diff --git a/BoardConfig.mk b/BoardConfig.mk index 469aa90..3960128 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -27,6 +27,10 @@ TARGET_FLATTEN_APEX := true # Platform TARGET_BOARD_PLATFORM := waydroid +# Init +TARGET_INIT_VENDOR_LIB ?= //$(COMMON_PATH):init_waydroid_waydroid +TARGET_RECOVERY_DEVICE_MODULES ?= init_waydroid_waydroid + # Kernel TARGET_NO_KERNEL := true diff --git a/device.mk b/device.mk index 5cda3fa..d945c6a 100644 --- a/device.mk +++ b/device.mk @@ -210,6 +210,11 @@ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.vulkan.compute-0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.compute.xml \ frameworks/native/data/etc/android.software.freeform_window_management.xml:system/etc/permissions/android.software.freeform_window_management.xml +# Preopt critical applications +PRODUCT_DEXPREOPT_SPEED_APPS += \ + Settings \ + SystemUI + # Power PRODUCT_PACKAGES += \ android.hardware.power@1.0-service.waydroid @@ -230,6 +235,10 @@ PRODUCT_PACKAGES += \ PRODUCT_SOONG_NAMESPACES += \ $(LOCAL_PATH) +# Speed profile services and wifi-service to reduce RAM and storage.Add commentMore actions +PRODUCT_SYSTEM_SERVER_COMPILER_FILTER := speed-profile +PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK := true + # Binder IPC PRODUCT_PACKAGES += \ vndservicemanager diff --git a/libinit/Android.bp b/libinit/Android.bp new file mode 100644 index 0000000..9a2a396 --- /dev/null +++ b/libinit/Android.bp @@ -0,0 +1,25 @@ +// +// Copyright (C) 2021 The LineageOS Project +// +// SPDX-License-Identifier: Apache-2.0 +// + +cc_library_static { + name: "libinit_waydroid_waydroid", + srcs: [ + "libinit_dalvik_heap.cpp", + "libinit_dalvik_vm.cpp", + "libinit_utils.cpp", + ], + whole_static_libs: ["libbase"], + export_include_dirs: ["include"], + recovery_available: true, +} + +cc_library_static { + name: "init_waydroid_waydroid", + srcs: ["init_waydroid_waydroid.cpp"], + whole_static_libs: ["libinit_waydroid_waydroid"], + include_dirs: ["system/core/init"], + recovery_available: true, +} diff --git a/libinit/include/libinit_dalvik_heap.h b/libinit/include/libinit_dalvik_heap.h new file mode 100644 index 0000000..75144b2 --- /dev/null +++ b/libinit/include/libinit_dalvik_heap.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_DALVIK_HEAP_H +#define LIBINIT_DALVIK_HEAP_H + +#include + +typedef struct dalvik_heap_info { + std::string heapstartsize; + std::string heapgrowthlimit; + std::string heapsize; + std::string heapminfree; + std::string heapmaxfree; + std::string heaptargetutilization; +} dalvik_heap_info_t; + +void set_dalvik_heap(void); + +#endif // LIBINIT_DALVIK_HEAP_H diff --git a/libinit/include/libinit_dalvik_vm.h b/libinit/include/libinit_dalvik_vm.h new file mode 100644 index 0000000..f9e020f --- /dev/null +++ b/libinit/include/libinit_dalvik_vm.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_DALVIK_VM_H +#define LIBINIT_DALVIK_VM_H + +#include + +typedef struct dalvik_vm_info { + std::string backgroundcpuset; + std::string backgroundthreads; + std::string bootcpuset; + std::string bootcputhreads; + std::string dexcpuset; + std::string dexcputhreads; +} dalvik_heap_info_t; + +void set_dalvik_heap(void); + +#endif // LIBINIT_DALVIK_HEAP_H diff --git a/libinit/include/libinit_utils.h b/libinit/include/libinit_utils.h new file mode 100644 index 0000000..ac2d673 --- /dev/null +++ b/libinit/include/libinit_utils.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef LIBINIT_UTILS_H +#define LIBINIT_UTILS_H + +#include + +void property_override(std::string prop, std::string value, bool add = true); + +void set_ro_build_prop(const std::string &prop, const std::string &value, bool product = false); + +#endif // LIBINIT_UTILS_H diff --git a/libinit/init_waydroid_waydroid.cpp b/libinit/init_waydroid_waydroid.cpp new file mode 100644 index 0000000..623cd71 --- /dev/null +++ b/libinit/init_waydroid_waydroid.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "vendor_init.h" + +void vendor_load_properties() { + set_dalvik_heap(); +} diff --git a/libinit/libinit_dalvik_heap.cpp b/libinit/libinit_dalvik_heap.cpp new file mode 100644 index 0000000..eaeaacf --- /dev/null +++ b/libinit/libinit_dalvik_heap.cpp @@ -0,0 +1,107 @@ + /* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + + #include "include/libinit_utils.h" +#include + #include + + #include + + #define HEAPSTARTSIZE_PROP "dalvik.vm.heapstartsize" + #define HEAPGROWTHLIMIT_PROP "dalvik.vm.heapgrowthlimit" + #define HEAPSIZE_PROP "dalvik.vm.heapsize" + #define HEAPMINFREE_PROP "dalvik.vm.heapminfree" + #define HEAPMAXFREE_PROP "dalvik.vm.heapmaxfree" + #define HEAPTARGETUTILIZATION_PROP "dalvik.vm.heaptargetutilization" + #define LOWMEMORYRAM_PROP "ro.config.low_ram" + + #define GB(b) (b * 1024ull * 1024 * 1024) + + + static const dalvik_heap_info_t dalvik_heap_info_16384 = { + .heapstartsize = "32m", + .heapgrowthlimit = "448m", + .heapsize = "640m", + .heapminfree = "16m", + .heapmaxfree = "64m", + .heaptargetutilization = "0.4", + }; + + static const dalvik_heap_info_t dalvik_heap_info_12288 = { + .heapstartsize = "24m", + .heapgrowthlimit = "384m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "56m", + .heaptargetutilization = "0.42", + }; + + static const dalvik_heap_info_t dalvik_heap_info_8192 = { + .heapstartsize = "24m", + .heapgrowthlimit = "256m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "48m", + .heaptargetutilization = "0.46", + }; + + static const dalvik_heap_info_t dalvik_heap_info_6144 = { + .heapstartsize = "16m", + .heapgrowthlimit = "256m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "32m", + .heaptargetutilization = "0.5", + }; + + static const dalvik_heap_info_t dalvik_heap_info_4096 = { + .heapstartsize = "8m", + .heapgrowthlimit = "256m", + .heapsize = "512m", + .heapminfree = "8m", + .heapmaxfree = "16m", + .heaptargetutilization = "0.6", + }; + + static const dalvik_heap_info_t dalvik_heap_info_2048 = { + .heapstartsize = "8m", + .heapgrowthlimit = "192m", + .heapsize = "512m", + .heapminfree = "512k", + .heapmaxfree = "8m", + .heaptargetutilization = "0.75", + }; + + void set_dalvik_heap() { + struct sysinfo sys; + const dalvik_heap_info_t *dhi; + + sysinfo(&sys); + + if (sys.totalram > GB(15)) + dhi = &dalvik_heap_info_16384; + else if (sys.totalram > GB(11)) + dhi = &dalvik_heap_info_12288; + else if (sys.totalram > GB(7)) + dhi = &dalvik_heap_info_8192; + else if (sys.totalram > GB(5)) + dhi = &dalvik_heap_info_6144; + else if (sys.totalram > GB(3)) + dhi = &dalvik_heap_info_4096; + else + dhi = &dalvik_heap_info_2048; + + property_override(HEAPSTARTSIZE_PROP, dhi->heapstartsize); + property_override(HEAPGROWTHLIMIT_PROP, dhi->heapgrowthlimit); + property_override(HEAPSIZE_PROP, dhi->heapsize); + property_override(HEAPTARGETUTILIZATION_PROP, dhi->heaptargetutilization); + property_override(HEAPMINFREE_PROP, dhi->heapminfree); + property_override(HEAPMAXFREE_PROP, dhi->heapmaxfree); + + if (sys.totalram >= GB(5) && sys.totalram <= GB(6)) { + property_override(LOWMEMORYRAM_PROP, "true"); + } + } diff --git a/libinit/libinit_dalvik_vm.cpp b/libinit/libinit_dalvik_vm.cpp new file mode 100644 index 0000000..325ea48 --- /dev/null +++ b/libinit/libinit_dalvik_vm.cpp @@ -0,0 +1,75 @@ + /* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + + #include + #include + + #include + + #define VMBACKGROUNDCPUSET_PROP "dalvik.vm.background-dex2oat-cpu-set" + #define VMBACKGROUNDTHREADS_PROP "dalvik.vm.background-dex2oat-threads" + #define VMBOOTCPUSET_PROP "dalvik.vm.boot-dex2oat-cpu-set" + #define VMBOOTCPUTHREADS_PROP "dalvik.vm.boot-dex2oat-threads" + #define VMDEXCPUSET_PROP "dalvik.vm.dex2oat-cpu-set" + #define VMDEXCPUTHREADS_PROP "dalvik.vm.dex2oat-threads" + + static const dalvik_vm_info_t dalvik_vm_info_8 = { + .backgroundcpuset = "0,1,2,3,4,5,6,7", + .backgroundthreads = "8", + .bootcpuset = "0,1,2,3,4,5,6,7", + .bootcputhreads = "8", + .dexcpuset = "0,1,2,3,4,5,6,7", + .dexcputhreads = "8", + }; + + static const dalvik_vm_info_t dalvik_vm_info_6 = { + .backgroundcpuset = "0,1,2,3,4,5", + .backgroundthreads = "6", + .bootcpuset = "0,1,2,3,4,5", + .bootcputhreads = "6", + .dexcpuset = "0,1,2,3,4,5", + .dexcputhreads = "6", + }; + + static const dalvik_vm_info_t dalvik_vm_info_4 = { + .backgroundcpuset = "0,1,2,3", + .backgroundthreads = "4", + .bootcpuset = "0,1,2,3", + .bootcputhreads = "4", + .dexcpuset = "0,1,2,3", + .dexcputhreads = "4", + }; + + static const dalvik_vm_info_t dalvik_vm_info_2 = { + .backgroundcpuset = "0,1", + .backgroundthreads = "2", + .bootcpuset = "0,1", + .bootcputhreads = "2", + .dexcpuset = "0,1", + .dexcputhreads = "2", + }; + + void set_dalvik_vm() { + const dalvik_vm_info_t *thi; + + int ncpus = get_nprocs_conf(); + + if (ncpus == 2) + thi = &dalvik_vm_info_2; + else if (ncpus == 4) + thi = &dalvik_vm_info_2; + else if (ncpus = 6) + thi = &dalvik_vm_info_6; + else (ncpus >= 8) + thi = &dalvik_vm_info_8; + + property_override(VMBACKGROUNDCPUSET_PROP, thi->backgroundcpuset); + property_override(VMBACKGROUNDTHREADS_PROP, thi->backgroundthreads); + property_override(VMBOOTCPUSET_PROP, thi->bootcpuset); + property_override(VMBOOTCPUTHREADS_PROP, thi->bootcputhreads); + property_override(VMDEXCPUSET_PROP, thi->dexcpuset); + property_override(VMDEXCPUTHREADS_PROP, thi->dexcputhreads); + } diff --git a/libinit/libinit_utils.cpp b/libinit/libinit_utils.cpp new file mode 100644 index 0000000..322d66a --- /dev/null +++ b/libinit/libinit_utils.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ +#include +#include + +#include + +void property_override(std::string prop, std::string value, bool add) { + auto pi = (prop_info *) __system_property_find(prop.c_str()); + if (pi != nullptr) { + __system_property_update(pi, value.c_str(), value.length()); + } else if (add) { + __system_property_add(prop.c_str(), prop.length(), value.c_str(), value.length()); + } +} + +std::vector ro_props_default_source_order = { + "system.", + "", +}; + +void set_ro_build_prop(const std::string &prop, const std::string &value, bool product) { + std::string prop_name; + + for (const auto &source : ro_props_default_source_order) { + if (product) + prop_name = "ro.product." + source + prop; + else + prop_name = "ro." + source + "build." + prop; + + property_override(prop_name, value, true); + } diff --git a/system.prop b/system.prop index de8cf1d..59fc812 100644 --- a/system.prop +++ b/system.prop @@ -5,14 +5,6 @@ import /vendor_extra/build.prop vendor.gralloc.disable_ubwc af.thread.throttle=false audio.deep_buffer.media=true -# Provides overrides to configure the Dalvik heap for a 4GB phone -dalvik.vm.heapstartsize=8m -dalvik.vm.heapgrowthlimit=192m -dalvik.vm.heapsize=512m -dalvik.vm.heaptargetutilization=0.6 -dalvik.vm.heapminfree=8m -dalvik.vm.heapmaxfree=16m - # SurfaceFlinger ro.surface_flinger.max_frame_buffer_acquired_buffers=3 ro.surface_flinger.running_without_sync_framework=true