From 663d1fb15b06572e677f9aa7bb59136d903f6e76 Mon Sep 17 00:00:00 2001 From: Davide Garberi Date: Thu, 7 Oct 2021 10:17:47 +0200 Subject: msm8996-common: Move oem unlock prop set to libinit * Since eleven the property wouldn't get its new context anymore, so work around that Change-Id: If2f987dd28e1423f53460c65aaa6c03568d94eba --- init/init_msm8996.cpp | 31 +++++++++++++++++++++++++++++++ rootdir/bin/init.qcom.sh | 6 ------ sepolicy/vendor/property.te | 1 - sepolicy/vendor/property_contexts | 3 --- sepolicy/vendor/qti_init_shell.te | 5 ----- sepolicy/vendor/system_app.te | 1 - 6 files changed, 31 insertions(+), 16 deletions(-) delete mode 100644 sepolicy/vendor/property.te diff --git a/init/init_msm8996.cpp b/init/init_msm8996.cpp index bdaaaa8..d9b087a 100644 --- a/init/init_msm8996.cpp +++ b/init/init_msm8996.cpp @@ -32,6 +32,8 @@ #include #include +#include +#include #include "property_service.h" #include "vendor_init.h" @@ -39,6 +41,9 @@ #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include +using android::base::ReadFileToString; +using android::base::Split; + char const *heapminfree; char const *heapmaxfree; @@ -70,9 +75,35 @@ void property_override(char const prop[], char const value[], bool add = true) } } +void import_kernel_cmdline(const std::function& fn) { + std::string cmdline; + android::base::ReadFileToString("/proc/cmdline", &cmdline); + + for (const auto& entry : android::base::Split(android::base::Trim(cmdline), " ")) { + std::vector pieces = android::base::Split(entry, "="); + if (pieces.size() == 2) { + fn(pieces[0], pieces[1]); + } + } +} + +static void init_setup_lock(const std::string& key, const std::string& value) +{ + if (key.empty()) return; + + if (key == "androidboot.lock") { + if (value.find("unlocked") != std::string::npos) { + property_override("ro.oem_unlock_supported", "0"); + } else { + property_override("ro.oem_unlock_supported", "1"); + } + } +} + void vendor_load_properties() { check_device(); + import_kernel_cmdline(init_setup_lock); property_override("dalvik.vm.heapstartsize", "8m"); property_override("dalvik.vm.heapgrowthlimit", "256m"); diff --git a/rootdir/bin/init.qcom.sh b/rootdir/bin/init.qcom.sh index 93439bb..12615aa 100755 --- a/rootdir/bin/init.qcom.sh +++ b/rootdir/bin/init.qcom.sh @@ -65,9 +65,3 @@ if [ ! -f /vendor/firmware_mnt/verinfo/ver_info.txt -o "$prev_version_info" != " fi chmod g-w /data/vendor/modem_config setprop ro.vendor.ril.mbn_copy_completed 1 - -if [[ -z $(grep "androidboot.lock=unlocked" /proc/cmdline) ]]; then - setprop ro.oem_unlock_supported 1 -else - setprop ro.oem_unlock_supported 0 -fi diff --git a/sepolicy/vendor/property.te b/sepolicy/vendor/property.te deleted file mode 100644 index 9520846..0000000 --- a/sepolicy/vendor/property.te +++ /dev/null @@ -1 +0,0 @@ -type oem_unlock_prop, property_type; diff --git a/sepolicy/vendor/property_contexts b/sepolicy/vendor/property_contexts index 1ae2e9b..c8eab1e 100644 --- a/sepolicy/vendor/property_contexts +++ b/sepolicy/vendor/property_contexts @@ -4,8 +4,5 @@ persist.camera. u:object_r:camera_prop:s0 # Netmgrd persist.net.doxlat u:object_r:vendor_xlat_prop:s0 -# OEM unlocking -ro.oem_unlock_supported u:object_r:oem_unlock_prop:s0 - # Qseecomd sys.listeners.registered u:object_r:vendor_tee_listener_prop:s0 diff --git a/sepolicy/vendor/qti_init_shell.te b/sepolicy/vendor/qti_init_shell.te index 56c35ba..f154182 100644 --- a/sepolicy/vendor/qti_init_shell.te +++ b/sepolicy/vendor/qti_init_shell.te @@ -8,8 +8,3 @@ allow qti_init_shell mnt_vendor_file:file create_file_perms; # Allow qti_init_shell to write and read /mnt/vendor/persist/bluetooth/bt_mac allow qti_init_shell persist_bluetooth_file:dir { add_name create search write }; allow qti_init_shell persist_bluetooth_file:file { create getattr open read write }; - -# Allow qti_init_shell to read cmdline -allow qti_init_shell proc_cmdline:file { getattr open read }; - -set_prop(qti_init_shell, oem_unlock_prop) diff --git a/sepolicy/vendor/system_app.te b/sepolicy/vendor/system_app.te index d0e4915..54a86c9 100644 --- a/sepolicy/vendor/system_app.te +++ b/sepolicy/vendor/system_app.te @@ -4,4 +4,3 @@ allow system_app shell_prop:property_service set; allow system_app hal_imsrcsd_hwservice:hwservice_manager find; binder_call(system_app, wificond); -get_prop(system_app, oem_unlock_prop); -- cgit v1.2.3