Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
libra: Set initial value for persist properties
Browse files Browse the repository at this point in the history
The following 3 persist properties should have a default value "false" after a factory reset or ROM update.
- persist.sys.cpu_overclock
- persist.sys.root_access
- persist.vendor.edge_touch_mode

Otherwise, some unexpectd behavior may happen because init cannot handle the property tigger with an empty value.
For example, if "persist.sys.cpu_overclock" has no default value (NULL or ""), overclock will be enabled by default and cause random reboot on some devices.

Also added dalvik heap properties to build.prop with the default values for 3GB devices, in order to avoid unnecessary property_find operation.
Devices with 2GB memory will still use libinit_libra to set dalvik heap parameters.
  • Loading branch information
BYZYB committed Feb 4, 2021
1 parent 4658a50 commit f45cc57
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 48 deletions.
76 changes: 30 additions & 46 deletions init/init_libra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,29 @@
*/

#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#define AQUA_BOARD_ID 30
#define BOARD_ID_PATH "/proc/device-tree/qcom,board-id"
#define LIBRA_BOARD_ID 12

#include "property_service.h"
#include <fstream>
#include <sys/_system_properties.h>
#include <sys/sysinfo.h>

#define AQUA_BOARD_ID 30
#define LIBRA_BOARD_ID 12
#define BOARD_ID_PATH "/proc/device-tree/qcom,board-id"
uint8_t get_board_id(const char *path)
{
uint8_t board_id;

/*
qcom,board-id contains two 4-byte numbers,
For libra, 00 00 00 0c and 00 00 00 00.
For aqua, 00 00 00 1e and 00 00 00 00.
*/
std::ifstream board_id_file(path, std::ifstream::binary);
board_id_file.seekg(3); // Shift past the first 3 bytes and only read the 4th one
board_id_file.read(reinterpret_cast<char *>(&board_id), 1);

using std::ifstream;
return board_id;
}

void property_override(const char *prop, const char *value)
{
Expand All @@ -52,46 +64,22 @@ void property_override(const char *prop, const char *value)
}
}

inline void property_override(const char *system_prop, const char *vendor_prop, const char *value)
{
property_override(system_prop, value);
property_override(vendor_prop, value);
}

uint8_t get_board_id()
{
uint8_t board_id;

/*
qcom,board-id contains two 4-byte numbers,
For libra, 00 00 00 0c and 00 00 00 00.
For aqua, 00 00 00 1e and 00 00 00 00.
*/
ifstream board_id_file(BOARD_ID_PATH, ifstream::binary);
board_id_file.seekg(3); // Shift past the first 3 bytes and only read the 4th one
board_id_file.read(reinterpret_cast<char *>(&board_id), 1);

return board_id;
}

void vendor_load_properties()
{
switch (get_board_id())
// Set initial value for persist properties
property_override("persist.sys.cpu_overclock", "false");
property_override("persist.sys.root_access", "false");
property_override("persist.vendor.edge_touch_mode", "false");

switch (get_board_id(BOARD_ID_PATH))
{
case LIBRA_BOARD_ID:
{
struct sysinfo sys;
sysinfo(&sys);

// Set memory parameters
if (sys.totalram > 2048ull * 1024 * 1024) // Mi-4c with 3GB RAM
{
property_override("dalvik.vm.heapgrowthlimit", "288m");
property_override("dalvik.vm.heapminfree", "512k");
property_override("dalvik.vm.heapsize", "768m");
property_override("dalvik.vm.heapstartsize", "8m");
}
else // Mi-4c with 2GB RAM
// Set memory properties for Mi-4c with 2GB RAM
if (sys.totalram <= 2048ull * 1024 * 1024)
{
property_override("dalvik.vm.heapgrowthlimit", "192m");
property_override("dalvik.vm.heapminfree", "2m");
Expand All @@ -107,16 +95,12 @@ void vendor_load_properties()
{
// Set device info for Mi-4s
property_override("ro.build.product", "aqua");
property_override("ro.product.device", "ro.vendor.product.device", "aqua");
property_override("ro.product.model", "ro.vendor.product.model", "Mi-4s");

// Set memory parameters
property_override("dalvik.vm.heapgrowthlimit", "288m");
property_override("dalvik.vm.heapminfree", "512k");
property_override("dalvik.vm.heapsize", "768m");
property_override("dalvik.vm.heapstartsize", "8m");
property_override("ro.product.device", "aqua");
property_override("ro.product.model", "Mi-4s");
property_override("ro.vendor.product.device", "aqua");
property_override("ro.vendor.product.model", "Mi-4s");

// Set fingerprint parameters
// Set fingerprint properties
property_override("ro.frp.pst", "/dev/block/bootdevice/by-name/config");
property_override("ro.hardware.fingerprint", "fpc");
property_override("sys.fpc.tu.disabled", "0");
Expand Down
4 changes: 2 additions & 2 deletions patch/packages/apps/LineageParts/overclock-control.patch
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ index 949562f..de3868a 100644
Global.putInt(getContentResolver(), Global.LOW_POWER_MODE_TRIGGER_LEVEL, level);
updateAutoPowerSaveSummary(level);
+ } else if (preference == mCPUOverclockPref) {
+ SystemProperties.set("persist.sys.cpu_overclock", SystemProperties.getBoolean("persist.sys.cpu_overclock", true) ? "false" : "true");
+ SystemProperties.set("persist.sys.cpu_overclock", mCPUOverclockPref.isChecked() ? "false" : "true");
}
return true;
}
Expand All @@ -130,7 +130,7 @@ index 949562f..de3868a 100644
}

+ private void updateCPUOverclockValue() {
+ mCPUOverclockPref.setChecked(SystemProperties.getBoolean("persist.sys.cpu_overclock", true));
+ mCPUOverclockPref.setChecked(SystemProperties.getBoolean("persist.sys.cpu_overclock", false));
+ }
+
private void updateAutoPowerSaveValue() {
Expand Down
9 changes: 9 additions & 0 deletions system_prop.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ PRODUCT_PROPERTY_OVERRIDES += \
persist.sys.button_jack_profile=volume \
persist.sys.button_jack_switch=0

# Dalvik heap
PRODUCT_PROPERTY_OVERRIDES += \
dalvik.vm.heapgrowthlimit=288m \
dalvik.vm.heapmaxfree=8m \
dalvik.vm.heapminfree=512k \
dalvik.vm.heapsize=768m \
dalvik.vm.heapstartsize=8m \
dalvik.vm.heaptargetutilization=0.75

# Dexpreopt
PRODUCT_PROPERTY_OVERRIDES += \
dalvik.vm.dex2oat-filter=speed \
Expand Down

0 comments on commit f45cc57

Please sign in to comment.