Commit afaf937a authored by Omkar Chandorkar's avatar Omkar Chandorkar Committed by Adam Lawson
Browse files

nicky: libinit: handle dalvik props based on sysram

* Adapted to Realme XT.
* We have 3 variants(4gb, 6gb & 8gb RAM)
* Values are taken from frameworks/native
parent 68571909
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
#include <sys/sysinfo.h>

using android::base::GetProperty;

@@ -27,6 +28,42 @@ void OverrideProperty(const char* name, const char* value) {
    }
}

void property_override(char const prop[], char const value[], bool add = true) {
    prop_info *pi;

    pi = (prop_info *)__system_property_find(prop);
    if (pi)
        __system_property_update(pi, value, strlen(value));
    else if (add)
        __system_property_add(prop, strlen(prop), value, strlen(value));
}

void load_dalvikvm_properties() {
  struct sysinfo sys;
  sysinfo(&sys);
  if (sys.totalram > 6144ull * 1024 * 1024) {
    // from - phone-xhdpi-8192-dalvik-heap.mk
    property_override("dalvik.vm.heapstartsize", "24m");
    property_override("dalvik.vm.heaptargetutilization", "0.46");
    property_override("dalvik.vm.heapmaxfree", "48m");
    }
  else if (sys.totalram > 4096ull * 1024 * 1024) {
    // from - phone-xhdpi-6144-dalvik-heap.mk
    property_override("dalvik.vm.heapstartsize", "16m");
    property_override("dalvik.vm.heaptargetutilization", "0.5");
    property_override("dalvik.vm.heapmaxfree", "32m");
    }
  else {
    // from - phone-xhdpi-4096-dalvik-heap.mk
    property_override("dalvik.vm.heaptargetutilization", "0.7");
    property_override("dalvik.vm.heapstartsize", "8m");
    property_override("dalvik.vm.heapmaxfree", "16m");
  }
  property_override("dalvik.vm.heapgrowthlimit", "256m");
  property_override("dalvik.vm.heapsize", "512m");
  property_override("dalvik.vm.heapminfree", "8m");
}

/*
 * Only for read-only properties. Properties that can be wrote to more
 * than once should be set in a typical init script (e.g. init.oplus.hw.rc)
@@ -49,4 +86,7 @@ void vendor_load_properties() {
        default:
            LOG(ERROR) << "Unidentied oplus project: " << prjName;
    }

    // dalvikvm props
    load_dalvikvm_properties();
}