From 1705545d22e8bee252fbe722aecccfa9b5a44332 Mon Sep 17 00:00:00 2001 From: Tad Date: Mon, 4 Apr 2022 21:48:14 -0400 Subject: [PATCH] 19.1: Initial bringup TODO: - manifest - devices - a few small patches to rebase Signed-off-by: Tad --- .../0001-constify_JNINativeMethod.patch | 414 ++++++++++++++++++ .../android_bionic/0001-HM-Use_HM.patch | 168 +++++++ .../0002-Graphene_Bionic_Hardening-1.patch | 89 ++++ .../0002-Graphene_Bionic_Hardening-10.patch | 84 ++++ .../0002-Graphene_Bionic_Hardening-11.patch | 95 ++++ .../0002-Graphene_Bionic_Hardening-12.patch | 85 ++++ .../0002-Graphene_Bionic_Hardening-13.patch | 25 ++ .../0002-Graphene_Bionic_Hardening-14.patch | 76 ++++ .../0002-Graphene_Bionic_Hardening-15.patch | 58 +++ .../0002-Graphene_Bionic_Hardening-16.patch | 98 +++++ .../0002-Graphene_Bionic_Hardening-2.patch | 76 ++++ .../0002-Graphene_Bionic_Hardening-3.patch | 57 +++ .../0002-Graphene_Bionic_Hardening-4.patch | 26 ++ .../0002-Graphene_Bionic_Hardening-5.patch | 47 ++ .../0002-Graphene_Bionic_Hardening-6.patch | 40 ++ .../0002-Graphene_Bionic_Hardening-7.patch | 26 ++ .../0002-Graphene_Bionic_Hardening-8.patch | 59 +++ .../0002-Graphene_Bionic_Hardening-9.patch | 41 ++ .../0001-No_SerialNum_Restrictions.patch | 38 ++ .../android_build/0001-Enable_fwrapv.patch | 24 + .../android_build/0002-OTA_Keys.patch | 69 +++ .../0003-Exec_Based_Spawning.patch | 28 ++ .../0001-Enable_fwrapv.patch | 50 +++ .../android_build_soong/0002-hm_apex.patch | 21 + .../0001-constify_JNINativeMethod.patch | 22 + .../0003-SUPL_No_IMSI.patch | 35 ++ .../0004-Fingerprint_Lockout.patch | 23 + .../0005-User_Logout.patch | 42 ++ .../0007-Always_Restict_Serial.patch | 29 ++ .../0008-Browser_No_Location.patch | 33 ++ .../0009-SystemUI_No_Permission_Review.patch | 22 + .../0013-Network_Permission-1.patch | 37 ++ .../0013-Network_Permission-2.patch | 69 +++ .../0013-Network_Permission-3.patch | 49 +++ .../0013-Sensors_Permission.patch | 113 +++++ .../0013-Special_Permissions.patch | 99 +++++ .../0014-Automatic_Reboot.patch | 153 +++++++ .../0015-Bluetooth_Timeout.patch | 121 +++++ .../0016-WiFi_Timeout.patch | 123 ++++++ .../0017-constify_JNINativeMethod.patch | 213 +++++++++ .../0018-Exec_Based_Spawning-1.patch | 181 ++++++++ .../0018-Exec_Based_Spawning-10.patch | 28 ++ .../0018-Exec_Based_Spawning-11.patch | 28 ++ .../0018-Exec_Based_Spawning-12.patch | 253 +++++++++++ .../0018-Exec_Based_Spawning-2.patch | 25 ++ .../0018-Exec_Based_Spawning-3.patch | 47 ++ .../0018-Exec_Based_Spawning-4.patch | 50 +++ .../0018-Exec_Based_Spawning-5.patch | 28 ++ .../0018-Exec_Based_Spawning-6.patch | 28 ++ .../0018-Exec_Based_Spawning-7.patch | 28 ++ .../0018-Exec_Based_Spawning-8.patch | 28 ++ .../0018-Exec_Based_Spawning-9.patch | 57 +++ .../0020-Location_Indicators.patch | 48 ++ .../0001-constify_JNINativeMethod.patch | 22 + .../0001-Sensors_Permission.patch | 22 + .../0001-Fix_Calling.patch | 55 +++ .../0001-Random_MAC.patch | 88 ++++ .../0001-Unused-8996.patch | 58 +++ .../0001-Unused-8998.patch | 60 +++ .../0001-Unused-sdm845.patch | 60 +++ .../0001-Unused-sm8150.patch | 58 +++ .../0001-Network_Permission.patch | 32 ++ .../0002-constify_JNINativeMethod.patch | 199 +++++++++ .../0003-Exec_Based_Spawning-1.patch | 112 +++++ .../0003-Exec_Based_Spawning-2.patch | 38 ++ .../0001-constify_JNINativeMethod.patch | 259 +++++++++++ .../0001-Not_Private_Banner.patch | 185 ++++++++ .../0001-Remove_Analytics.patch | 140 ++++++ .../0001-constify_JNINativeMethod.patch | 92 ++++ .../0001-Captive_Portal_Toggle.patch | 341 +++++++++++++++ .../0004-Private_DNS.patch | 318 ++++++++++++++ .../0005-Automatic_Reboot.patch | 196 +++++++++ .../0006-Bluetooth_Timeout.patch | 238 ++++++++++ .../0007-WiFi_Timeout.patch | 238 ++++++++++ .../0008-ptrace_scope.patch | 168 +++++++ .../0009-Install_Restrictions.patch | 140 ++++++ .../0010-exec_spawning_toggle.patch | 168 +++++++ .../0011-Random_MAC.patch | 145 ++++++ .../0001-Remove_Analytics.patch | 178 ++++++++ .../0001-Server.patch | 33 ++ .../0002-Tor_Support.patch | 397 +++++++++++++++++ .../0001-Random_MAC.patch | 70 +++ .../0002-Network_Permission-1.patch | 62 +++ .../0002-Network_Permission-2.patch | 31 ++ .../0003-Sensors_Permission-1.patch | 46 ++ .../0003-Sensors_Permission-2.patch | 30 ++ .../0004-Special_Permission-1.patch | 110 +++++ .../0004-Special_Permission-2.patch | 73 +++ .../0004-Special_Permission-3.patch | 30 ++ .../0004-Special_Permission-4.patch | 41 ++ .../0005-Browser_No_Location.patch | 44 ++ .../0006-Location_Indicators.patch | 25 ++ .../0001-Random_MAC.patch | 103 +++++ .../0001-Network_Permission.patch | 21 + .../android_system_bt/0001-alloc_size.patch | 25 ++ .../android_system_core/0001-Harden.patch | 60 +++ .../0002-ptrace_scope.patch | 27 ++ .../0003-HM-Increase_vm_mmc.patch | 23 + .../0001-ext4_pad_filenames.patch | 38 ++ .../0001-Network_Permission.patch | 31 ++ .../0002-protected_files.patch | 41 ++ .../0003-ptrace_scope-1.patch | 90 ++++ .../0003-ptrace_scope-2.patch | 34 ++ Scripts/Common/Functions.sh | 2 +- Scripts/LineageOS-18.1/Patch.sh | 7 +- Scripts/LineageOS-19.1/Defaults.sh | 60 +++ Scripts/LineageOS-19.1/Functions.sh | 112 +++++ Scripts/LineageOS-19.1/Patch.sh | 405 +++++++++++++++++ Scripts/LineageOS-19.1/Rebrand.sh | 99 +++++ 109 files changed, 9579 insertions(+), 7 deletions(-) create mode 100644 Patches/LineageOS-19.1/android_art/0001-constify_JNINativeMethod.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0001-HM-Use_HM.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-1.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-10.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-11.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-12.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-13.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-14.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-15.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-16.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-2.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-3.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-4.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-5.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-6.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-7.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-8.patch create mode 100644 Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-9.patch create mode 100644 Patches/LineageOS-19.1/android_bootable_recovery/0001-No_SerialNum_Restrictions.patch create mode 100644 Patches/LineageOS-19.1/android_build/0001-Enable_fwrapv.patch create mode 100644 Patches/LineageOS-19.1/android_build/0002-OTA_Keys.patch create mode 100644 Patches/LineageOS-19.1/android_build/0003-Exec_Based_Spawning.patch create mode 100644 Patches/LineageOS-19.1/android_build_soong/0001-Enable_fwrapv.patch create mode 100644 Patches/LineageOS-19.1/android_build_soong/0002-hm_apex.patch create mode 100644 Patches/LineageOS-19.1/android_external_conscrypt/0001-constify_JNINativeMethod.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0003-SUPL_No_IMSI.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0004-Fingerprint_Lockout.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0005-User_Logout.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0007-Always_Restict_Serial.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0008-Browser_No_Location.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0009-SystemUI_No_Permission_Review.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0013-Network_Permission-1.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0013-Network_Permission-2.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0013-Network_Permission-3.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0013-Sensors_Permission.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0013-Special_Permissions.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0014-Automatic_Reboot.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0015-Bluetooth_Timeout.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0016-WiFi_Timeout.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0017-constify_JNINativeMethod.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-1.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-10.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-11.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-12.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-2.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-3.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-4.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-5.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-6.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-7.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-8.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-9.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_base/0020-Location_Indicators.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_ex/0001-constify_JNINativeMethod.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_native/0001-Sensors_Permission.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_opt_net_ims/0001-Fix_Calling.patch create mode 100644 Patches/LineageOS-19.1/android_frameworks_opt_net_wifi/0001-Random_MAC.patch create mode 100644 Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-8996.patch create mode 100644 Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-8998.patch create mode 100644 Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-sdm845.patch create mode 100644 Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-sm8150.patch create mode 100644 Patches/LineageOS-19.1/android_libcore/0001-Network_Permission.patch create mode 100644 Patches/LineageOS-19.1/android_libcore/0002-constify_JNINativeMethod.patch create mode 100644 Patches/LineageOS-19.1/android_libcore/0003-Exec_Based_Spawning-1.patch create mode 100644 Patches/LineageOS-19.1/android_libcore/0003-Exec_Based_Spawning-2.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Bluetooth/0001-constify_JNINativeMethod.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Dialer/0001-Not_Private_Banner.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_LineageParts/0001-Remove_Analytics.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Nfc/0001-constify_JNINativeMethod.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Settings/0001-Captive_Portal_Toggle.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Settings/0004-Private_DNS.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Settings/0005-Automatic_Reboot.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Settings/0006-Bluetooth_Timeout.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Settings/0007-WiFi_Timeout.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Settings/0008-ptrace_scope.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Settings/0009-Install_Restrictions.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Settings/0010-exec_spawning_toggle.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Settings/0011-Random_MAC.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_SetupWizard/0001-Remove_Analytics.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Updater/0001-Server.patch create mode 100644 Patches/LineageOS-19.1/android_packages_apps_Updater/0002-Tor_Support.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_NetworkStack/0001-Random_MAC.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Permission/0002-Network_Permission-1.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Permission/0002-Network_Permission-2.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Permission/0003-Sensors_Permission-1.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Permission/0003-Sensors_Permission-2.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Permission/0004-Special_Permission-1.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Permission/0004-Special_Permission-2.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Permission/0004-Special_Permission-3.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Permission/0004-Special_Permission-4.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Permission/0005-Browser_No_Location.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Permission/0006-Location_Indicators.patch create mode 100644 Patches/LineageOS-19.1/android_packages_modules_Wifi/0001-Random_MAC.patch create mode 100644 Patches/LineageOS-19.1/android_packages_providers_DownloadProvider/0001-Network_Permission.patch create mode 100644 Patches/LineageOS-19.1/android_system_bt/0001-alloc_size.patch create mode 100644 Patches/LineageOS-19.1/android_system_core/0001-Harden.patch create mode 100644 Patches/LineageOS-19.1/android_system_core/0002-ptrace_scope.patch create mode 100644 Patches/LineageOS-19.1/android_system_core/0003-HM-Increase_vm_mmc.patch create mode 100644 Patches/LineageOS-19.1/android_system_extras/0001-ext4_pad_filenames.patch create mode 100644 Patches/LineageOS-19.1/android_system_netd/0001-Network_Permission.patch create mode 100644 Patches/LineageOS-19.1/android_system_sepolicy/0002-protected_files.patch create mode 100644 Patches/LineageOS-19.1/android_system_sepolicy/0003-ptrace_scope-1.patch create mode 100644 Patches/LineageOS-19.1/android_system_sepolicy/0003-ptrace_scope-2.patch create mode 100644 Scripts/LineageOS-19.1/Defaults.sh create mode 100644 Scripts/LineageOS-19.1/Functions.sh create mode 100644 Scripts/LineageOS-19.1/Patch.sh create mode 100644 Scripts/LineageOS-19.1/Rebrand.sh diff --git a/Patches/LineageOS-19.1/android_art/0001-constify_JNINativeMethod.patch b/Patches/LineageOS-19.1/android_art/0001-constify_JNINativeMethod.patch new file mode 100644 index 00000000..755bdcbe --- /dev/null +++ b/Patches/LineageOS-19.1/android_art/0001-constify_JNINativeMethod.patch @@ -0,0 +1,414 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sun, 10 Oct 2021 16:45:59 -0400 +Subject: [PATCH] constify JNINativeMethod tables + +--- + runtime/native/dalvik_system_BaseDexClassLoader.cc | 2 +- + runtime/native/dalvik_system_DexFile.cc | 2 +- + runtime/native/dalvik_system_VMDebug.cc | 2 +- + runtime/native/dalvik_system_VMRuntime.cc | 2 +- + runtime/native/dalvik_system_VMStack.cc | 2 +- + runtime/native/dalvik_system_ZygoteHooks.cc | 2 +- + runtime/native/java_lang_Class.cc | 2 +- + runtime/native/java_lang_Object.cc | 2 +- + runtime/native/java_lang_String.cc | 2 +- + runtime/native/java_lang_StringFactory.cc | 2 +- + runtime/native/java_lang_System.cc | 2 +- + runtime/native/java_lang_Thread.cc | 2 +- + runtime/native/java_lang_Throwable.cc | 2 +- + runtime/native/java_lang_VMClassLoader.cc | 2 +- + runtime/native/java_lang_invoke_MethodHandleImpl.cc | 2 +- + runtime/native/java_lang_ref_FinalizerReference.cc | 2 +- + runtime/native/java_lang_ref_Reference.cc | 2 +- + runtime/native/java_lang_reflect_Array.cc | 2 +- + runtime/native/java_lang_reflect_Constructor.cc | 2 +- + runtime/native/java_lang_reflect_Executable.cc | 2 +- + runtime/native/java_lang_reflect_Field.cc | 2 +- + runtime/native/java_lang_reflect_Method.cc | 2 +- + runtime/native/java_lang_reflect_Parameter.cc | 2 +- + runtime/native/java_lang_reflect_Proxy.cc | 2 +- + runtime/native/java_util_concurrent_atomic_AtomicLong.cc | 2 +- + runtime/native/libcore_util_CharsetUtils.cc | 2 +- + runtime/native/org_apache_harmony_dalvik_ddmc_DdmServer.cc | 2 +- + runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc | 2 +- + runtime/native/sun_misc_Unsafe.cc | 2 +- + 29 files changed, 29 insertions(+), 29 deletions(-) + +diff --git a/runtime/native/dalvik_system_BaseDexClassLoader.cc b/runtime/native/dalvik_system_BaseDexClassLoader.cc +index 607395d308..f3d84e57a8 100644 +--- a/runtime/native/dalvik_system_BaseDexClassLoader.cc ++++ b/runtime/native/dalvik_system_BaseDexClassLoader.cc +@@ -58,7 +58,7 @@ static jobjectArray BaseDexClassLoader_computeClassLoaderContextsNative(JNIEnv* + return result; + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(BaseDexClassLoader, computeClassLoaderContextsNative, + "()[Ljava/lang/String;"), + }; +diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc +index f8ad7f1b7a..b0f7cd8f17 100644 +--- a/runtime/native/dalvik_system_DexFile.cc ++++ b/runtime/native/dalvik_system_DexFile.cc +@@ -913,7 +913,7 @@ static void DexFile_setTrusted(JNIEnv* env, jclass, jobject j_cookie) { + } + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(DexFile, closeDexFile, "(Ljava/lang/Object;)Z"), + NATIVE_METHOD(DexFile, + defineClassNative, +diff --git a/runtime/native/dalvik_system_VMDebug.cc b/runtime/native/dalvik_system_VMDebug.cc +index 5c8bd8431a..fdd0ad079d 100644 +--- a/runtime/native/dalvik_system_VMDebug.cc ++++ b/runtime/native/dalvik_system_VMDebug.cc +@@ -489,7 +489,7 @@ static void VMDebug_setAllocTrackerStackDepth(JNIEnv* env, jclass, jint stack_de + } + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(VMDebug, countInstancesOfClass, "(Ljava/lang/Class;Z)J"), + NATIVE_METHOD(VMDebug, countInstancesOfClasses, "([Ljava/lang/Class;Z)[J"), + NATIVE_METHOD(VMDebug, dumpHprofData, "(Ljava/lang/String;I)V"), +diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc +index 842590408d..8283f30995 100644 +--- a/runtime/native/dalvik_system_VMRuntime.cc ++++ b/runtime/native/dalvik_system_VMRuntime.cc +@@ -506,7 +506,7 @@ static jboolean VMRuntime_isValidClassLoaderContext(JNIEnv* env, + return ClassLoaderContext::IsValidEncoding(encoded_class_loader_context.c_str()); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(VMRuntime, addressOf, "(Ljava/lang/Object;)J"), + NATIVE_METHOD(VMRuntime, bootClassPath, "()Ljava/lang/String;"), + NATIVE_METHOD(VMRuntime, clampGrowthLimit, "()V"), +diff --git a/runtime/native/dalvik_system_VMStack.cc b/runtime/native/dalvik_system_VMStack.cc +index e88516e248..58e40f6e8a 100644 +--- a/runtime/native/dalvik_system_VMStack.cc ++++ b/runtime/native/dalvik_system_VMStack.cc +@@ -168,7 +168,7 @@ static jobjectArray VMStack_getAnnotatedThreadStackTrace(JNIEnv* env, jclass, jo + return GetThreadStack(soa, javaThread, fn); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(VMStack, fillStackTraceElements, "(Ljava/lang/Thread;[Ljava/lang/StackTraceElement;)I"), + FAST_NATIVE_METHOD(VMStack, getCallingClassLoader, "()Ljava/lang/ClassLoader;"), + FAST_NATIVE_METHOD(VMStack, getClosestUserClassLoader, "()Ljava/lang/ClassLoader;"), +diff --git a/runtime/native/dalvik_system_ZygoteHooks.cc b/runtime/native/dalvik_system_ZygoteHooks.cc +index 050233dac5..37551d049b 100644 +--- a/runtime/native/dalvik_system_ZygoteHooks.cc ++++ b/runtime/native/dalvik_system_ZygoteHooks.cc +@@ -456,7 +456,7 @@ static jboolean ZygoteHooks_nativeZygoteLongSuspendOk(JNIEnv* env ATTRIBUTE_UNUS + } + + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(ZygoteHooks, nativePreFork, "()J"), + NATIVE_METHOD(ZygoteHooks, nativePostZygoteFork, "()V"), + NATIVE_METHOD(ZygoteHooks, nativePostForkSystemServer, "(I)V"), +diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc +index 776b14f735..bdf3ea92ec 100644 +--- a/runtime/native/java_lang_Class.cc ++++ b/runtime/native/java_lang_Class.cc +@@ -981,7 +981,7 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) { + return soa.AddLocalReference(receiver.Get()); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Class, classForName, + "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"), + FAST_NATIVE_METHOD(Class, getDeclaredAnnotation, +diff --git a/runtime/native/java_lang_Object.cc b/runtime/native/java_lang_Object.cc +index 8fc10d1114..8740755199 100644 +--- a/runtime/native/java_lang_Object.cc ++++ b/runtime/native/java_lang_Object.cc +@@ -54,7 +54,7 @@ static jint Object_identityHashCodeNative(JNIEnv* env, jclass, jobject javaObjec + return static_cast(o->IdentityHashCode()); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Object, internalClone, "()Ljava/lang/Object;"), + FAST_NATIVE_METHOD(Object, notify, "()V"), + FAST_NATIVE_METHOD(Object, notifyAll, "()V"), +diff --git a/runtime/native/java_lang_String.cc b/runtime/native/java_lang_String.cc +index 86f93299d9..ec4b8a9025 100644 +--- a/runtime/native/java_lang_String.cc ++++ b/runtime/native/java_lang_String.cc +@@ -109,7 +109,7 @@ static jcharArray String_toCharArray(JNIEnv* env, jobject java_this) { + return soa.AddLocalReference(mirror::String::ToCharArray(s, soa.Self())); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(String, charAt, "(I)C"), + FAST_NATIVE_METHOD(String, compareTo, "(Ljava/lang/String;)I"), + FAST_NATIVE_METHOD(String, concat, "(Ljava/lang/String;)Ljava/lang/String;"), +diff --git a/runtime/native/java_lang_StringFactory.cc b/runtime/native/java_lang_StringFactory.cc +index 9086ee932d..de0a81e9a5 100644 +--- a/runtime/native/java_lang_StringFactory.cc ++++ b/runtime/native/java_lang_StringFactory.cc +@@ -264,7 +264,7 @@ static jstring StringFactory_newStringFromUtf8Bytes(JNIEnv* env, jclass, jbyteAr + return soa.AddLocalReference(result); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(StringFactory, newStringFromBytes, "([BIII)Ljava/lang/String;"), + FAST_NATIVE_METHOD(StringFactory, newStringFromChars, "(II[C)Ljava/lang/String;"), + FAST_NATIVE_METHOD(StringFactory, newStringFromString, "(Ljava/lang/String;)Ljava/lang/String;"), +diff --git a/runtime/native/java_lang_System.cc b/runtime/native/java_lang_System.cc +index 63cbd2c815..e7b3894aad 100644 +--- a/runtime/native/java_lang_System.cc ++++ b/runtime/native/java_lang_System.cc +@@ -239,7 +239,7 @@ static void System_arraycopyBooleanUnchecked(JNIEnv* env, + javaDst, dstPos, count); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(System, arraycopy, "(Ljava/lang/Object;ILjava/lang/Object;II)V"), + FAST_NATIVE_METHOD(System, arraycopyCharUnchecked, "([CI[CII)V"), + FAST_NATIVE_METHOD(System, arraycopyByteUnchecked, "([BI[BII)V"), +diff --git a/runtime/native/java_lang_Thread.cc b/runtime/native/java_lang_Thread.cc +index c3b4fe09de..8ff4e02605 100644 +--- a/runtime/native/java_lang_Thread.cc ++++ b/runtime/native/java_lang_Thread.cc +@@ -193,7 +193,7 @@ static void Thread_yield(JNIEnv*, jobject) { + sched_yield(); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Thread, currentThread, "()Ljava/lang/Thread;"), + FAST_NATIVE_METHOD(Thread, interrupted, "()Z"), + FAST_NATIVE_METHOD(Thread, isInterrupted, "()Z"), +diff --git a/runtime/native/java_lang_Throwable.cc b/runtime/native/java_lang_Throwable.cc +index b89e287481..5cdd70c513 100644 +--- a/runtime/native/java_lang_Throwable.cc ++++ b/runtime/native/java_lang_Throwable.cc +@@ -38,7 +38,7 @@ static jobjectArray Throwable_nativeGetStackTrace(JNIEnv* env, jclass, jobject j + return Thread::InternalStackTraceToStackTraceElementArray(soa, javaStackState); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Throwable, nativeFillInStackTrace, "()Ljava/lang/Object;"), + FAST_NATIVE_METHOD(Throwable, nativeGetStackTrace, "(Ljava/lang/Object;)[Ljava/lang/StackTraceElement;"), + }; +diff --git a/runtime/native/java_lang_VMClassLoader.cc b/runtime/native/java_lang_VMClassLoader.cc +index 11e02a2ce4..ce37a33086 100644 +--- a/runtime/native/java_lang_VMClassLoader.cc ++++ b/runtime/native/java_lang_VMClassLoader.cc +@@ -155,7 +155,7 @@ static jobjectArray VMClassLoader_getBootClassPathEntries(JNIEnv* env, jclass) { + return array; + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(VMClassLoader, findLoadedClass, "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;"), + NATIVE_METHOD(VMClassLoader, getBootClassPathEntries, "()[Ljava/lang/String;"), + }; +diff --git a/runtime/native/java_lang_invoke_MethodHandleImpl.cc b/runtime/native/java_lang_invoke_MethodHandleImpl.cc +index 45d9a8abef..afeaa94ec5 100644 +--- a/runtime/native/java_lang_invoke_MethodHandleImpl.cc ++++ b/runtime/native/java_lang_invoke_MethodHandleImpl.cc +@@ -63,7 +63,7 @@ static jobject MethodHandleImpl_getMemberInternal(JNIEnv* env, jobject thiz) { + return soa.AddLocalReference(h_object.Get()); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(MethodHandleImpl, getMemberInternal, "()Ljava/lang/reflect/Member;"), + }; + +diff --git a/runtime/native/java_lang_ref_FinalizerReference.cc b/runtime/native/java_lang_ref_FinalizerReference.cc +index 535b243411..0a8dfb6c09 100644 +--- a/runtime/native/java_lang_ref_FinalizerReference.cc ++++ b/runtime/native/java_lang_ref_FinalizerReference.cc +@@ -42,7 +42,7 @@ static jobject FinalizerReference_getReferent(JNIEnv* env, jobject javaThis) { + return soa.AddLocalReference(referent); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(FinalizerReference, makeCircularListIfUnenqueued, "()Z"), + FAST_NATIVE_METHOD(FinalizerReference, getReferent, "()Ljava/lang/Object;"), + }; +diff --git a/runtime/native/java_lang_ref_Reference.cc b/runtime/native/java_lang_ref_Reference.cc +index f23010bf48..e36287154f 100644 +--- a/runtime/native/java_lang_ref_Reference.cc ++++ b/runtime/native/java_lang_ref_Reference.cc +@@ -73,7 +73,7 @@ static void Reference_clearReferent(JNIEnv* env, jobject javaThis) { + Runtime::Current()->GetHeap()->GetReferenceProcessor()->ClearReferent(ref); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Reference, getReferent, "()Ljava/lang/Object;"), + FAST_NATIVE_METHOD(Reference, clearReferent, "()V"), + FAST_NATIVE_METHOD(Reference, refersTo0, "(Ljava/lang/Object;)Z"), +diff --git a/runtime/native/java_lang_reflect_Array.cc b/runtime/native/java_lang_reflect_Array.cc +index ff94593cdf..e359e7d8a8 100644 +--- a/runtime/native/java_lang_reflect_Array.cc ++++ b/runtime/native/java_lang_reflect_Array.cc +@@ -74,7 +74,7 @@ static jobject Array_createObjectArray(JNIEnv* env, jclass, jclass javaElementCl + return soa.AddLocalReference(new_array); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Array, createMultiArray, "(Ljava/lang/Class;[I)Ljava/lang/Object;"), + FAST_NATIVE_METHOD(Array, createObjectArray, "(Ljava/lang/Class;I)Ljava/lang/Object;"), + }; +diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc +index 1d362c0302..16f5dedb44 100644 +--- a/runtime/native/java_lang_reflect_Constructor.cc ++++ b/runtime/native/java_lang_reflect_Constructor.cc +@@ -128,7 +128,7 @@ static jobject Constructor_newInstanceFromSerialization(JNIEnv* env, jclass unus + return env->NewObject(allocClass, ctor); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Constructor, getExceptionTypes, "()[Ljava/lang/Class;"), + FAST_NATIVE_METHOD(Constructor, newInstance0, "([Ljava/lang/Object;)Ljava/lang/Object;"), + FAST_NATIVE_METHOD(Constructor, newInstanceFromSerialization, "(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;"), +diff --git a/runtime/native/java_lang_reflect_Executable.cc b/runtime/native/java_lang_reflect_Executable.cc +index fef16b9099..1acce4e5d3 100644 +--- a/runtime/native/java_lang_reflect_Executable.cc ++++ b/runtime/native/java_lang_reflect_Executable.cc +@@ -383,7 +383,7 @@ static jint Executable_getParameterCountInternal(JNIEnv* env, jobject javaMethod + } + + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Executable, compareMethodParametersInternal, + "(Ljava/lang/reflect/Method;)I"), + FAST_NATIVE_METHOD(Executable, getAnnotationNative, +diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc +index cfc4a292ba..7bbff9ba36 100644 +--- a/runtime/native/java_lang_reflect_Field.cc ++++ b/runtime/native/java_lang_reflect_Field.cc +@@ -521,7 +521,7 @@ static jboolean Field_isAnnotationPresentNative(JNIEnv* env, + return annotations::IsFieldAnnotationPresent(field, klass); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Field, get, "(Ljava/lang/Object;)Ljava/lang/Object;"), + FAST_NATIVE_METHOD(Field, getBoolean, "(Ljava/lang/Object;)Z"), + FAST_NATIVE_METHOD(Field, getByte, "(Ljava/lang/Object;)B"), +diff --git a/runtime/native/java_lang_reflect_Method.cc b/runtime/native/java_lang_reflect_Method.cc +index 2c0dd806e1..e052ba9b2c 100644 +--- a/runtime/native/java_lang_reflect_Method.cc ++++ b/runtime/native/java_lang_reflect_Method.cc +@@ -86,7 +86,7 @@ static jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiv + return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Method, getDefaultValue, "()Ljava/lang/Object;"), + FAST_NATIVE_METHOD(Method, getExceptionTypes, "()[Ljava/lang/Class;"), + FAST_NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"), +diff --git a/runtime/native/java_lang_reflect_Parameter.cc b/runtime/native/java_lang_reflect_Parameter.cc +index 263a56796f..92bf9078a4 100644 +--- a/runtime/native/java_lang_reflect_Parameter.cc ++++ b/runtime/native/java_lang_reflect_Parameter.cc +@@ -98,7 +98,7 @@ static jobject Parameter_getAnnotationNative(JNIEnv* env, + annotations::GetAnnotationForMethodParameter(method, parameterIndex, klass)); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD( + Parameter, + getAnnotationNative, +diff --git a/runtime/native/java_lang_reflect_Proxy.cc b/runtime/native/java_lang_reflect_Proxy.cc +index f723ed223d..c2b533de5d 100644 +--- a/runtime/native/java_lang_reflect_Proxy.cc ++++ b/runtime/native/java_lang_reflect_Proxy.cc +@@ -37,7 +37,7 @@ static jclass Proxy_generateProxy(JNIEnv* env, jclass, jstring name, jobjectArra + soa, name, interfaces, loader, methods, throws)); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Proxy, generateProxy, "(Ljava/lang/String;[Ljava/lang/Class;Ljava/lang/ClassLoader;[Ljava/lang/reflect/Method;[[Ljava/lang/Class;)Ljava/lang/Class;"), + }; + +diff --git a/runtime/native/java_util_concurrent_atomic_AtomicLong.cc b/runtime/native/java_util_concurrent_atomic_AtomicLong.cc +index fa288edcb8..299ac5a61d 100644 +--- a/runtime/native/java_util_concurrent_atomic_AtomicLong.cc ++++ b/runtime/native/java_util_concurrent_atomic_AtomicLong.cc +@@ -30,7 +30,7 @@ static jboolean AtomicLong_VMSupportsCS8(JNIEnv*, jclass) { + return QuasiAtomic::LongAtomicsUseMutexes(kRuntimeISA) ? JNI_FALSE : JNI_TRUE; + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(AtomicLong, VMSupportsCS8, "()Z"), + }; + +diff --git a/runtime/native/libcore_util_CharsetUtils.cc b/runtime/native/libcore_util_CharsetUtils.cc +index f0764f1d74..d9303a9b93 100644 +--- a/runtime/native/libcore_util_CharsetUtils.cc ++++ b/runtime/native/libcore_util_CharsetUtils.cc +@@ -183,7 +183,7 @@ static jbyteArray CharsetUtils_toUtf8Bytes(JNIEnv* env, jclass, jstring java_str + return soa.AddLocalReference(result); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(CharsetUtils, asciiBytesToChars, "([BII[C)V"), + FAST_NATIVE_METHOD(CharsetUtils, isoLatin1BytesToChars, "([BII[C)V"), + FAST_NATIVE_METHOD(CharsetUtils, toAsciiBytes, "(Ljava/lang/String;II)[B"), +diff --git a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmServer.cc b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmServer.cc +index 419aed8578..ccbef4f3f4 100644 +--- a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmServer.cc ++++ b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmServer.cc +@@ -38,7 +38,7 @@ static void DdmServer_nativeSendChunk(JNIEnv* env, jclass, jint type, + Runtime::Current()->GetRuntimeCallbacks()->DdmPublishChunk(static_cast(type), chunk); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(DdmServer, nativeSendChunk, "(I[BII)V"), + }; + +diff --git a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc +index f74e1206f5..044364cc45 100644 +--- a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc ++++ b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc +@@ -209,7 +209,7 @@ static jbyteArray DdmVmInternal_getThreadStats(JNIEnv* env, jclass) { + return result; + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(DdmVmInternal, setRecentAllocationsTrackingEnabled, "(Z)V"), + NATIVE_METHOD(DdmVmInternal, setThreadNotifyEnabled, "(Z)V"), + NATIVE_METHOD(DdmVmInternal, getStackTraceById, "(I)[Ljava/lang/StackTraceElement;"), +diff --git a/runtime/native/sun_misc_Unsafe.cc b/runtime/native/sun_misc_Unsafe.cc +index 5014f340cd..bb9226d1fa 100644 +--- a/runtime/native/sun_misc_Unsafe.cc ++++ b/runtime/native/sun_misc_Unsafe.cc +@@ -541,7 +541,7 @@ static void Unsafe_unpark(JNIEnv* env, jobject, jobject jthread) { + } + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Unsafe, compareAndSwapInt, "(Ljava/lang/Object;JII)Z"), + FAST_NATIVE_METHOD(Unsafe, compareAndSwapLong, "(Ljava/lang/Object;JJJ)Z"), + FAST_NATIVE_METHOD(Unsafe, compareAndSwapObject, "(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z"), diff --git a/Patches/LineageOS-19.1/android_bionic/0001-HM-Use_HM.patch b/Patches/LineageOS-19.1/android_bionic/0001-HM-Use_HM.patch new file mode 100644 index 00000000..8ff0e913 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0001-HM-Use_HM.patch @@ -0,0 +1,168 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 5 Dec 2018 01:51:56 -0500 +Subject: [PATCH] use Scudo on 32-bit and hardened_malloc on 64-bit + +Co-authored-by: anupritaisno1 +Signed-off-by: anupritaisno1 +--- + libc/Android.bp | 39 +++++++++++------------- + libc/bionic/h_malloc_wrapper.cpp | 51 ++++++++++++++++++++++++++++++++ + libc/bionic/malloc_common.h | 8 +++++ + 3 files changed, 77 insertions(+), 21 deletions(-) + create mode 100644 libc/bionic/h_malloc_wrapper.cpp + +diff --git a/libc/Android.bp b/libc/Android.bp +index 98b878151..75b06f58c 100644 +--- a/libc/Android.bp ++++ b/libc/Android.bp +@@ -68,6 +68,8 @@ libc_common_flags = [ + + // GWP-ASan requires platform TLS. + "-fno-emulated-tls", ++ ++ "-DH_MALLOC_PREFIX", + ] + + // Define some common cflags +@@ -113,33 +115,20 @@ cc_defaults { + ldflags: ["-Wl,-z,muldefs"], + + multilib: { +- lib64: { +- product_variables: { +- malloc_zero_contents: { +- cflags: ["-DSCUDO_ZERO_CONTENTS"], +- }, +- malloc_pattern_fill_contents: { +- cflags: ["-DSCUDO_PATTERN_FILL_CONTENTS"], +- }, +- malloc_not_svelte: { +- cflags: ["-DUSE_SCUDO"], +- }, +- }, +- }, + lib32: { + product_variables: { + malloc_zero_contents: { + cflags: ["-DSCUDO_ZERO_CONTENTS"], + }, + malloc_pattern_fill_contents: { +- cflags: ["-DSCUDO_PATTERN_FILL_CONTENTS"], ++ cflags: ["-DSCUDO_PATTERN_FILL_CONTENTS"], + }, + malloc_not_svelte_libc32: { +- cflags: ["-DUSE_SCUDO"], ++ cflags: ["-DUSE_SCUDO"], + }, + }, +- }, +- }, ++ } ++ } + } + + libc_scudo_product_variables = { +@@ -194,12 +183,20 @@ cc_defaults { + cc_library_static { + name: "libc_jemalloc_wrapper", + defaults: ["libc_defaults"], +- srcs: ["bionic/jemalloc_wrapper.cpp"], ++ multilib: { ++ lib32: { ++ // Used to pull in the jemalloc/hardened_malloc include directory so that if the ++ // library is removed, the include directory is also removed. ++ srcs: ["bionic/jemalloc_wrapper.cpp"], ++ static_libs: ["libjemalloc5"], ++ }, ++ lib64: { ++ srcs: ["bionic/h_malloc_wrapper.cpp"], ++ static_libs: ["libhardened_malloc"], ++ }, ++ }, + cflags: ["-fvisibility=hidden"], + +- // Used to pull in the jemalloc include directory so that if the +- // library is removed, the include directory is also removed. +- static_libs: ["libjemalloc5"], + } + + // ======================================================== +diff --git a/libc/bionic/h_malloc_wrapper.cpp b/libc/bionic/h_malloc_wrapper.cpp +new file mode 100644 +index 000000000..5fb0968c2 +--- /dev/null ++++ b/libc/bionic/h_malloc_wrapper.cpp +@@ -0,0 +1,51 @@ ++#include ++#include ++#include ++#include ++ ++#include ++ ++#include "h_malloc.h" ++ ++__BEGIN_DECLS ++int h_malloc_info(int options, FILE* fp); ++__END_DECLS ++ ++int h_malloc_info(int options, FILE* fp) { ++ if (options != 0) { ++ errno = EINVAL; ++ return -1; ++ } ++ ++ fflush(fp); ++ int fd = fileno(fp); ++ MallocXmlElem root(fd, "malloc", "version=\"jemalloc-1\""); ++ ++ // Dump all of the large allocations in the arenas. ++ for (size_t i = 0; i < h_mallinfo_narenas(); i++) { ++ struct mallinfo mi = h_mallinfo_arena_info(i); ++ if (mi.hblkhd != 0) { ++ MallocXmlElem arena_elem(fd, "heap", "nr=\"%d\"", i); ++ { ++ MallocXmlElem(fd, "allocated-large").Contents("%zu", mi.ordblks); ++ MallocXmlElem(fd, "allocated-huge").Contents("%zu", mi.uordblks); ++ MallocXmlElem(fd, "allocated-bins").Contents("%zu", mi.fsmblks); ++ ++ size_t total = 0; ++ for (size_t j = 0; j < h_mallinfo_nbins(); j++) { ++ struct mallinfo mi = h_mallinfo_bin_info(i, j); ++ if (mi.ordblks != 0) { ++ MallocXmlElem bin_elem(fd, "bin", "nr=\"%d\"", j); ++ MallocXmlElem(fd, "allocated").Contents("%zu", mi.ordblks); ++ MallocXmlElem(fd, "nmalloc").Contents("%zu", mi.uordblks); ++ MallocXmlElem(fd, "ndalloc").Contents("%zu", mi.fordblks); ++ total += mi.ordblks; ++ } ++ } ++ MallocXmlElem(fd, "bins-total").Contents("%zu", total); ++ } ++ } ++ } ++ ++ return 0; ++} +diff --git a/libc/bionic/malloc_common.h b/libc/bionic/malloc_common.h +index 4afcc4a8d..cca9e5202 100644 +--- a/libc/bionic/malloc_common.h ++++ b/libc/bionic/malloc_common.h +@@ -67,8 +67,16 @@ __END_DECLS + + #else + ++#ifdef __LP64__ ++#include "h_malloc.h" ++#define Malloc(function) h_ ## function ++__BEGIN_DECLS ++int h_malloc_info(int options, FILE* fp); ++__END_DECLS ++#else + #include "jemalloc.h" + #define Malloc(function) je_ ## function ++#endif + + #endif + diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-1.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-1.patch new file mode 100644 index 00000000..22fd3d73 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-1.patch @@ -0,0 +1,89 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: anupritaisno1 +Date: Wed, 13 Oct 2021 15:00:25 +0530 +Subject: [PATCH] add a real explicit_bzero implementation + +Clang, GCC and other compilers special-case standard C functions like +memset. Calls to memset will be optimized out. + +OpenBSD provides explicit_bzero to work around this but Android simply +defines it as memset so nothing prevents it from being optimized away. + +This implementation uses a memory read constraint via empty inline +assembly rather than something that may be broken via link-time +optimization in the future. + +Signed-off-by: anupritaisno1 +Change-Id: Ia021e30f86ee4b998d541fbf7262110f9d1d6fbf +Signed-off-by: anupritaisno1 +--- + libc/Android.bp | 1 + + libc/bionic/explicit_bzero.cpp | 7 +++++++ + libc/include/string.h | 1 + + libc/libc.map.txt | 1 + + libc/upstream-openbsd/android/include/openbsd-compat.h | 2 -- + 5 files changed, 10 insertions(+), 2 deletions(-) + create mode 100644 libc/bionic/explicit_bzero.cpp + +diff --git a/libc/Android.bp b/libc/Android.bp +index 75b06f58c..cae5d8776 100644 +--- a/libc/Android.bp ++++ b/libc/Android.bp +@@ -1084,6 +1084,7 @@ cc_library_static { + "bionic/error.cpp", + "bionic/eventfd.cpp", + "bionic/exec.cpp", ++ "bionic/explicit_bzero.cpp", + "bionic/faccessat.cpp", + "bionic/fchmod.cpp", + "bionic/fchmodat.cpp", +diff --git a/libc/bionic/explicit_bzero.cpp b/libc/bionic/explicit_bzero.cpp +new file mode 100644 +index 000000000..b06daa138 +--- /dev/null ++++ b/libc/bionic/explicit_bzero.cpp +@@ -0,0 +1,7 @@ ++#include ++ ++void* explicit_bzero(void* s, size_t n) { ++ void *ptr = memset(s, 0, n); ++ __asm__ __volatile__("" : : "r"(ptr) : "memory"); ++ return ptr; ++} +diff --git a/libc/include/string.h b/libc/include/string.h +index 0cc5611aa..befffd082 100644 +--- a/libc/include/string.h ++++ b/libc/include/string.h +@@ -56,6 +56,7 @@ void* mempcpy(void* __dst, const void* __src, size_t __n) __INTRODUCED_IN(23); + #endif + void* memmove(void* __dst, const void* __src, size_t __n); + void* memset(void* __dst, int __ch, size_t __n); ++void* explicit_bzero(void *s, size_t n); + void* memmem(const void* __haystack, size_t __haystack_size, const void* __needle, size_t __needle_size) __attribute_pure__; + + char* strchr(const char* __s, int __ch) __attribute_pure__; +diff --git a/libc/libc.map.txt b/libc/libc.map.txt +index c31e30681..cab7c1363 100644 +--- a/libc/libc.map.txt ++++ b/libc/libc.map.txt +@@ -332,6 +332,7 @@ LIBC { + execvp; + execvpe; # introduced=21 + exit; ++ explicit_bzero; # introduced=31 + faccessat; + fallocate; # introduced=21 + fallocate64; # introduced=21 +diff --git a/libc/upstream-openbsd/android/include/openbsd-compat.h b/libc/upstream-openbsd/android/include/openbsd-compat.h +index 6c21c5b49..49d98c3d2 100644 +--- a/libc/upstream-openbsd/android/include/openbsd-compat.h ++++ b/libc/upstream-openbsd/android/include/openbsd-compat.h +@@ -57,8 +57,6 @@ extern const char* __progname; + /* OpenBSD has this, but we can't really implement it correctly on Linux. */ + #define issetugid() 0 + +-#define explicit_bzero(p, s) memset(p, 0, s) +- + /* OpenBSD has this in paths.h. But this directory doesn't normally exist. + * Even when it does exist, only the 'shell' user has permissions. + */ diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-10.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-10.patch new file mode 100644 index 00000000..999f642f --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-10.patch @@ -0,0 +1,84 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 2 Dec 2015 23:37:28 -0500 +Subject: [PATCH] switch pthread_atfork handler allocation to mmap + +Signed-off-by: anupritaisno1 +--- + libc/bionic/pthread_atfork.cpp | 35 ++++++++++++++++++++++++++++------ + 1 file changed, 29 insertions(+), 6 deletions(-) + +diff --git a/libc/bionic/pthread_atfork.cpp b/libc/bionic/pthread_atfork.cpp +index 0dcabdfb2..6306052ee 100644 +--- a/libc/bionic/pthread_atfork.cpp ++++ b/libc/bionic/pthread_atfork.cpp +@@ -29,6 +29,9 @@ + #include + #include + #include ++#include ++#include ++#include + + #include "platform/bionic/macros.h" + +@@ -43,6 +46,8 @@ struct atfork_t { + void* dso_handle; + }; + ++static atfork_t* pool; ++ + class atfork_list_t { + public: + constexpr atfork_list_t() : first_(nullptr), last_(nullptr) {} +@@ -101,7 +106,8 @@ class atfork_list_t { + last_ = entry->prev; + } + +- free(entry); ++ entry->next = pool; ++ pool = entry; + } + + atfork_t* first_; +@@ -154,18 +160,35 @@ void __bionic_atfork_run_parent() { + // __register_atfork is the name used by glibc + extern "C" int __register_atfork(void (*prepare)(void), void (*parent)(void), + void(*child)(void), void* dso) { +- atfork_t* entry = reinterpret_cast(malloc(sizeof(atfork_t))); +- if (entry == nullptr) { +- return ENOMEM; ++ pthread_mutex_lock(&g_atfork_list_mutex); ++ ++ if (!pool) { ++ size_t page_size = getpagesize(); ++ char* page = static_cast(mmap(NULL, page_size, PROT_READ|PROT_WRITE, ++ MAP_ANONYMOUS|MAP_PRIVATE, -1, 0)); ++ if (page == MAP_FAILED) { ++ pthread_mutex_unlock(&g_atfork_list_mutex); ++ return ENOMEM; ++ } ++ ++ prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, page, page_size, ++ "atfork handlers"); ++ ++ for (char* it = page; it < page + page_size - sizeof(atfork_t); it += sizeof(atfork_t)) { ++ atfork_t* node = reinterpret_cast(it); ++ node->next = pool; ++ pool = node; ++ } + } + ++ atfork_t* entry = pool; ++ pool = entry->next; ++ + entry->prepare = prepare; + entry->parent = parent; + entry->child = child; + entry->dso_handle = dso; + +- pthread_mutex_lock(&g_atfork_list_mutex); +- + g_atfork_list.push_back(entry); + + pthread_mutex_unlock(&g_atfork_list_mutex); diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-11.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-11.patch new file mode 100644 index 00000000..b8635e8d --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-11.patch @@ -0,0 +1,95 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Thu, 3 Dec 2015 12:58:31 -0500 +Subject: [PATCH] add memory protection for pthread_atfork handlers + +Signed-off-by: anupritaisno1 +--- + libc/bionic/pthread_atfork.cpp | 34 ++++++++++++++++++++++++++++++++-- + 1 file changed, 32 insertions(+), 2 deletions(-) + +diff --git a/libc/bionic/pthread_atfork.cpp b/libc/bionic/pthread_atfork.cpp +index 6306052ee..d59f3ae54 100644 +--- a/libc/bionic/pthread_atfork.cpp ++++ b/libc/bionic/pthread_atfork.cpp +@@ -47,6 +47,7 @@ struct atfork_t { + }; + + static atfork_t* pool; ++static atfork_t* page_list; + + class atfork_list_t { + public: +@@ -160,13 +161,22 @@ void __bionic_atfork_run_parent() { + // __register_atfork is the name used by glibc + extern "C" int __register_atfork(void (*prepare)(void), void (*parent)(void), + void(*child)(void), void* dso) { ++ size_t page_size = getpagesize(); ++ + pthread_mutex_lock(&g_atfork_list_mutex); + ++ for (atfork_t* page_it = page_list; page_it; page_it = page_it->next) { ++ mprotect(page_it, page_size, PROT_READ|PROT_WRITE); ++ } ++ + if (!pool) { +- size_t page_size = getpagesize(); + char* page = static_cast(mmap(NULL, page_size, PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0)); + if (page == MAP_FAILED) { ++ for (atfork_t* page_it = page_list; page_it; page_it = page_it->next) { ++ mprotect(page_it, page_size, PROT_READ); ++ } ++ + pthread_mutex_unlock(&g_atfork_list_mutex); + return ENOMEM; + } +@@ -174,11 +184,15 @@ extern "C" int __register_atfork(void (*prepare)(void), void (*parent)(void), + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, page, page_size, + "atfork handlers"); + +- for (char* it = page; it < page + page_size - sizeof(atfork_t); it += sizeof(atfork_t)) { ++ for (char* it = page + sizeof(atfork_t); it < page + page_size - sizeof(atfork_t); it += sizeof(atfork_t)) { + atfork_t* node = reinterpret_cast(it); + node->next = pool; + pool = node; + } ++ ++ atfork_t* page_node = reinterpret_cast(page); ++ page_node->next = page_list; ++ page_list = page_node; + } + + atfork_t* entry = pool; +@@ -191,6 +205,10 @@ extern "C" int __register_atfork(void (*prepare)(void), void (*parent)(void), + + g_atfork_list.push_back(entry); + ++ for (atfork_t* page_it = page_list; page_it; page_it = page_it->next) { ++ mprotect(page_it, page_size, PROT_READ); ++ } ++ + pthread_mutex_unlock(&g_atfork_list_mutex); + + return 0; +@@ -198,8 +216,20 @@ extern "C" int __register_atfork(void (*prepare)(void), void (*parent)(void), + + extern "C" __LIBC_HIDDEN__ void __unregister_atfork(void* dso) { + pthread_mutex_lock(&g_atfork_list_mutex); ++ ++ size_t page_size = getpagesize(); ++ ++ for (atfork_t* page_it = page_list; page_it; page_it = page_it->next) { ++ mprotect(page_it, page_size, PROT_READ|PROT_WRITE); ++ } ++ + g_atfork_list.remove_if([&](const atfork_t* entry) { + return entry->dso_handle == dso; + }); ++ ++ for (atfork_t* page_it = page_list; page_it; page_it = page_it->next) { ++ mprotect(page_it, page_size, PROT_READ); ++ } ++ + pthread_mutex_unlock(&g_atfork_list_mutex); + } diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-12.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-12.patch new file mode 100644 index 00000000..c104f701 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-12.patch @@ -0,0 +1,85 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 27 Jan 2016 18:02:15 -0500 +Subject: [PATCH] add XOR mangling mitigation for thread-local dtors + +Signed-off-by: anupritaisno1 +--- + libc/bionic/__cxa_thread_atexit_impl.cpp | 8 +++++--- + libc/bionic/libc_init_common.cpp | 2 ++ + libc/private/bionic_globals.h | 1 + + 3 files changed, 8 insertions(+), 3 deletions(-) + +diff --git a/libc/bionic/__cxa_thread_atexit_impl.cpp b/libc/bionic/__cxa_thread_atexit_impl.cpp +index 99077c101..74608513e 100644 +--- a/libc/bionic/__cxa_thread_atexit_impl.cpp ++++ b/libc/bionic/__cxa_thread_atexit_impl.cpp +@@ -13,15 +13,17 @@ + * See the License for the specific language governing permissions and + * limitations under the License. + */ ++#include + #include + + #include ++#include + + #include "pthread_internal.h" + + class thread_local_dtor { + public: +- void (*func) (void *); ++ uintptr_t func; + void *arg; + void *dso_handle; // unused... + thread_local_dtor* next; +@@ -35,7 +37,7 @@ __BIONIC_WEAK_FOR_NATIVE_BRIDGE + int __cxa_thread_atexit_impl(void (*func) (void *), void *arg, void *dso_handle) { + thread_local_dtor* dtor = new thread_local_dtor(); + +- dtor->func = func; ++ dtor->func = __libc_globals->dtor_cookie ^ reinterpret_cast(func); + dtor->arg = arg; + dtor->dso_handle = dso_handle; + +@@ -54,7 +56,7 @@ extern "C" __LIBC_HIDDEN__ void __cxa_thread_finalize() { + thread_local_dtor* current = thread->thread_local_dtors; + thread->thread_local_dtors = current->next; + +- current->func(current->arg); ++ (reinterpret_cast(__libc_globals->dtor_cookie ^ current->func))(current->arg); + if (__loader_remove_thread_local_dtor != nullptr) { + __loader_remove_thread_local_dtor(current->dso_handle); + } +diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp +index dd623a529..ddad1b8ad 100644 +--- a/libc/bionic/libc_init_common.cpp ++++ b/libc/bionic/libc_init_common.cpp +@@ -45,6 +45,7 @@ + #include + + #include "private/WriteProtected.h" ++#include "private/bionic_arc4random.h" + #include "private/bionic_defs.h" + #include "private/bionic_globals.h" + #include "private/bionic_tls.h" +@@ -69,6 +70,7 @@ void __libc_init_globals() { + __libc_globals.mutate([](libc_globals* globals) { + __libc_init_vdso(globals); + __libc_init_setjmp_cookie(globals); ++ arc4random_buf(&globals->dtor_cookie, sizeof(globals->dtor_cookie)); + }); + } + +diff --git a/libc/private/bionic_globals.h b/libc/private/bionic_globals.h +index e105c18d9..ce05936b0 100644 +--- a/libc/private/bionic_globals.h ++++ b/libc/private/bionic_globals.h +@@ -45,6 +45,7 @@ + + struct libc_globals { + vdso_entry vdso[VDSO_END]; ++ long dtor_cookie; + long setjmp_cookie; + uintptr_t heap_pointer_tag; + diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-13.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-13.patch new file mode 100644 index 00000000..7cafd591 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-13.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Fri, 29 Jan 2016 20:20:09 -0500 +Subject: [PATCH] use a better pthread_attr junk filling pattern + +Guarantee that junk filled pointers will fault, at least on pure 64-bit. + +Signed-off-by: anupritaisno1 +--- + libc/bionic/pthread_attr.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libc/bionic/pthread_attr.cpp b/libc/bionic/pthread_attr.cpp +index 89aa28966..08e237f9f 100644 +--- a/libc/bionic/pthread_attr.cpp ++++ b/libc/bionic/pthread_attr.cpp +@@ -53,7 +53,7 @@ int pthread_attr_init(pthread_attr_t* attr) { + + __BIONIC_WEAK_FOR_NATIVE_BRIDGE + int pthread_attr_destroy(pthread_attr_t* attr) { +- memset(attr, 0x42, sizeof(pthread_attr_t)); ++ memset(attr, 0xdf, sizeof(pthread_attr_t)); + return 0; + } + diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-14.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-14.patch new file mode 100644 index 00000000..64f93dfc --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-14.patch @@ -0,0 +1,76 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Renlord +Date: Thu, 12 Sep 2019 14:51:51 +1000 +Subject: [PATCH] add guard page(s) between static_tls and stack + +Signed-off-by: anupritaisno1 +--- + libc/bionic/pthread_create.cpp | 29 +++++++++++++++++++---------- + 1 file changed, 19 insertions(+), 10 deletions(-) + +diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp +index 121b26f82..31c553e25 100644 +--- a/libc/bionic/pthread_create.cpp ++++ b/libc/bionic/pthread_create.cpp +@@ -201,9 +201,10 @@ int __init_thread(pthread_internal_t* thread) { + ThreadMapping __allocate_thread_mapping(size_t stack_size, size_t stack_guard_size) { + const StaticTlsLayout& layout = __libc_shared_globals()->static_tls_layout; + +- // Allocate in order: stack guard, stack, static TLS, guard page. ++ // Allocate in order: stack guard, stack, guard page, static TLS, guard page. + size_t mmap_size; + if (__builtin_add_overflow(stack_size, stack_guard_size, &mmap_size)) return {}; ++ if (__builtin_add_overflow(mmap_size, PTHREAD_GUARD_SIZE, &mmap_size)) return {}; + if (__builtin_add_overflow(mmap_size, layout.size(), &mmap_size)) return {}; + if (__builtin_add_overflow(mmap_size, PTHREAD_GUARD_SIZE, &mmap_size)) return {}; + +@@ -212,8 +213,8 @@ ThreadMapping __allocate_thread_mapping(size_t stack_size, size_t stack_guard_si + mmap_size = __BIONIC_ALIGN(mmap_size, PAGE_SIZE); + if (mmap_size < unaligned_size) return {}; + +- // Create a new private anonymous map. Make the entire mapping PROT_NONE, then carve out a +- // read+write area in the middle. ++ // Create a new private anonymous map. Make the entire mapping PROT_NONE, then carve out ++ // read+write areas for the stack and static TLS + const int flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; + char* const space = static_cast(mmap(nullptr, mmap_size, PROT_NONE, flags, -1, 0)); + if (space == MAP_FAILED) { +@@ -223,13 +224,21 @@ ThreadMapping __allocate_thread_mapping(size_t stack_size, size_t stack_guard_si + mmap_size, strerror(errno)); + return {}; + } +- const size_t writable_size = mmap_size - stack_guard_size - PTHREAD_GUARD_SIZE; +- if (mprotect(space + stack_guard_size, +- writable_size, +- PROT_READ | PROT_WRITE) != 0) { ++ ++ if (mprotect(space + stack_guard_size, stack_size, PROT_READ | PROT_WRITE) != 0) { + async_safe_format_log(ANDROID_LOG_WARN, "libc", + "pthread_create failed: couldn't mprotect R+W %zu-byte thread mapping region: %s", +- writable_size, strerror(errno)); ++ stack_size, strerror(errno)); ++ munmap(space, mmap_size); ++ return {}; ++ } ++ ++ char* const static_tls_space = space + stack_guard_size + stack_size + PTHREAD_GUARD_SIZE; ++ ++ if (mprotect(static_tls_space, layout.size(), PROT_READ | PROT_WRITE) != 0) { ++ async_safe_format_log(ANDROID_LOG_WARN, "libc", ++ "pthread_create failed: couldn't mprotect R+W %zu-byte static TLS mapping region: %s", ++ layout.size(), strerror(errno)); + munmap(space, mmap_size); + return {}; + } +@@ -239,9 +248,9 @@ ThreadMapping __allocate_thread_mapping(size_t stack_size, size_t stack_guard_si + result.mmap_size = mmap_size; + result.mmap_base_unguarded = space + stack_guard_size; + result.mmap_size_unguarded = mmap_size - stack_guard_size - PTHREAD_GUARD_SIZE; +- result.static_tls = space + mmap_size - PTHREAD_GUARD_SIZE - layout.size(); ++ result.static_tls = static_tls_space; + result.stack_base = space; +- result.stack_top = result.static_tls; ++ result.stack_top = space + stack_guard_size + stack_size; + return result; + } + diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-15.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-15.patch new file mode 100644 index 00000000..58fbf942 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-15.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Thu, 10 Oct 2019 22:52:49 -0400 +Subject: [PATCH] move pthread_internal_t behind guard page + +Signed-off-by: anupritaisno1 +--- + libc/bionic/pthread_create.cpp | 19 +++++++++---------- + 1 file changed, 9 insertions(+), 10 deletions(-) + +diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp +index 31c553e25..627fbb25b 100644 +--- a/libc/bionic/pthread_create.cpp ++++ b/libc/bionic/pthread_create.cpp +@@ -201,10 +201,13 @@ int __init_thread(pthread_internal_t* thread) { + ThreadMapping __allocate_thread_mapping(size_t stack_size, size_t stack_guard_size) { + const StaticTlsLayout& layout = __libc_shared_globals()->static_tls_layout; + +- // Allocate in order: stack guard, stack, guard page, static TLS, guard page. ++ size_t thread_page_size = __BIONIC_ALIGN(sizeof(pthread_internal_t), PAGE_SIZE); ++ ++ // Allocate in order: stack guard, stack, guard page, pthread_internal_t, static TLS, guard page. + size_t mmap_size; + if (__builtin_add_overflow(stack_size, stack_guard_size, &mmap_size)) return {}; + if (__builtin_add_overflow(mmap_size, PTHREAD_GUARD_SIZE, &mmap_size)) return {}; ++ if (__builtin_add_overflow(mmap_size, thread_page_size, &mmap_size)) return {}; + if (__builtin_add_overflow(mmap_size, layout.size(), &mmap_size)) return {}; + if (__builtin_add_overflow(mmap_size, PTHREAD_GUARD_SIZE, &mmap_size)) return {}; + +@@ -233,9 +236,10 @@ ThreadMapping __allocate_thread_mapping(size_t stack_size, size_t stack_guard_si + return {}; + } + +- char* const static_tls_space = space + stack_guard_size + stack_size + PTHREAD_GUARD_SIZE; ++ char* const thread = space + stack_guard_size + stack_size + PTHREAD_GUARD_SIZE; ++ char* const static_tls_space = thread + thread_page_size; + +- if (mprotect(static_tls_space, layout.size(), PROT_READ | PROT_WRITE) != 0) { ++ if (mprotect(thread, thread_page_size + layout.size(), PROT_READ | PROT_WRITE) != 0) { + async_safe_format_log(ANDROID_LOG_WARN, "libc", + "pthread_create failed: couldn't mprotect R+W %zu-byte static TLS mapping region: %s", + layout.size(), strerror(errno)); +@@ -280,13 +284,8 @@ static int __allocate_thread(pthread_attr_t* attr, bionic_tcb** tcbp, void** chi + stack_top = static_cast(attr->stack_base) + attr->stack_size; + } + +- // Carve out space from the stack for the thread's pthread_internal_t. This +- // memory isn't counted in pthread_attr_getstacksize. +- +- // To safely access the pthread_internal_t and thread stack, we need to find a 16-byte aligned boundary. +- stack_top = align_down(stack_top - sizeof(pthread_internal_t), 16); +- +- pthread_internal_t* thread = reinterpret_cast(stack_top); ++ pthread_internal_t* thread = reinterpret_cast( ++ mapping.static_tls - __BIONIC_ALIGN(sizeof(pthread_internal_t), PAGE_SIZE)); + if (!stack_clean) { + // If thread was not allocated by mmap(), it may not have been cleared to zero. + // So assume the worst and zero it. diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-16.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-16.patch new file mode 100644 index 00000000..37e10f56 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-16.patch @@ -0,0 +1,98 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Renlord +Date: Sun, 20 Oct 2019 08:17:11 +1100 +Subject: [PATCH] add secondary stack randomization + +Signed-off-by: anupritaisno1 +--- + libc/bionic/pthread_create.cpp | 32 +++++++++++++++++++++++++++----- + libc/include/sys/cdefs.h | 1 + + 2 files changed, 28 insertions(+), 5 deletions(-) + +diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp +index 627fbb25b..1dc32be32 100644 +--- a/libc/bionic/pthread_create.cpp ++++ b/libc/bionic/pthread_create.cpp +@@ -29,6 +29,7 @@ + #include + + #include ++#include + #include + #include + #include +@@ -201,12 +202,24 @@ int __init_thread(pthread_internal_t* thread) { + ThreadMapping __allocate_thread_mapping(size_t stack_size, size_t stack_guard_size) { + const StaticTlsLayout& layout = __libc_shared_globals()->static_tls_layout; + ++ // round up if the given stack size is not in multiples of PAGE_SIZE ++ stack_size = __BIONIC_ALIGN(stack_size, PAGE_SIZE); + size_t thread_page_size = __BIONIC_ALIGN(sizeof(pthread_internal_t), PAGE_SIZE); + +- // Allocate in order: stack guard, stack, guard page, pthread_internal_t, static TLS, guard page. ++ // Place a randomly sized gap above the stack, up to 10% as large as the stack ++ // on 32-bit and 50% on 64-bit where virtual memory is plentiful. ++#if __LP64__ ++ size_t max_gap_size = stack_size / 2; ++#else ++ size_t max_gap_size = stack_size / 10; ++#endif ++ // Make sure random stack top guard size are multiples of PAGE_SIZE. ++ size_t gap_size = __BIONIC_ALIGN(arc4random_uniform(max_gap_size), PAGE_SIZE); ++ ++ // Allocate in order: stack guard, stack, (random) guard page(s), pthread_internal_t, static TLS, guard page. + size_t mmap_size; + if (__builtin_add_overflow(stack_size, stack_guard_size, &mmap_size)) return {}; +- if (__builtin_add_overflow(mmap_size, PTHREAD_GUARD_SIZE, &mmap_size)) return {}; ++ if (__builtin_add_overflow(mmap_size, gap_size, &mmap_size)) return {}; + if (__builtin_add_overflow(mmap_size, thread_page_size, &mmap_size)) return {}; + if (__builtin_add_overflow(mmap_size, layout.size(), &mmap_size)) return {}; + if (__builtin_add_overflow(mmap_size, PTHREAD_GUARD_SIZE, &mmap_size)) return {}; +@@ -228,15 +241,21 @@ ThreadMapping __allocate_thread_mapping(size_t stack_size, size_t stack_guard_si + return {}; + } + +- if (mprotect(space + stack_guard_size, stack_size, PROT_READ | PROT_WRITE) != 0) { ++ // Stack is at the lower end of mapped space, stack guard region is at the lower end of stack. ++ // Make the usable portion of the stack between the guard region and random gap readable and ++ // writable. ++ if (mprotect((space + stack_guard_size), stack_size, PROT_READ | PROT_WRITE) == -1) { + async_safe_format_log(ANDROID_LOG_WARN, "libc", + "pthread_create failed: couldn't mprotect R+W %zu-byte thread mapping region: %s", + stack_size, strerror(errno)); + munmap(space, mmap_size); + return {}; + } ++ prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, space, stack_guard_size, "stack guard"); ++ char* const stack_top_guard = space + stack_guard_size + stack_size; ++ prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, stack_top_guard, gap_size, "stack top guard"); + +- char* const thread = space + stack_guard_size + stack_size + PTHREAD_GUARD_SIZE; ++ char* const thread = space + stack_guard_size + stack_size + gap_size; + char* const static_tls_space = thread + thread_page_size; + + if (mprotect(thread, thread_page_size + layout.size(), PROT_READ | PROT_WRITE) != 0) { +@@ -254,7 +273,10 @@ ThreadMapping __allocate_thread_mapping(size_t stack_size, size_t stack_guard_si + result.mmap_size_unguarded = mmap_size - stack_guard_size - PTHREAD_GUARD_SIZE; + result.static_tls = static_tls_space; + result.stack_base = space; +- result.stack_top = space + stack_guard_size + stack_size; ++ // Choose a random base within the first page of the stack. Waste no more ++ // than the space originally wasted by pthread_internal_t for compatibility. ++ result.stack_top = space + stack_guard_size + stack_size - arc4random_uniform(sizeof(pthread_internal_t)); ++ result.stack_top = reinterpret_cast(__BIONIC_ALIGN_DOWN(reinterpret_cast(result.stack_top), 16)); + return result; + } + +diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h +index 2556d1183..1863bb70f 100644 +--- a/libc/include/sys/cdefs.h ++++ b/libc/include/sys/cdefs.h +@@ -61,6 +61,7 @@ + #endif + + #define __BIONIC_ALIGN(__value, __alignment) (((__value) + (__alignment)-1) & ~((__alignment)-1)) ++#define __BIONIC_ALIGN_DOWN(value, alignment) ((value) & ~((alignment) - 1)) + + /* + * The __CONCAT macro is used to concatenate parts of symbol names, e.g. diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-2.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-2.patch new file mode 100644 index 00000000..5cb8b39d --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-2.patch @@ -0,0 +1,76 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sun, 8 Feb 2015 01:18:54 -0500 +Subject: [PATCH] replace brk and sbrk with stubs + +Pretend that there is never room to grow the heap in order to prevent +usage of these unsafe legacy functions. There are likely no users of +these in practice as it is inherently broken to use them outside of +malloc. + +Signed-off-by: anupritaisno1 +--- + libc/bionic/brk.cpp | 48 ++++++++------------------------------------- + 1 file changed, 8 insertions(+), 40 deletions(-) + +diff --git a/libc/bionic/brk.cpp b/libc/bionic/brk.cpp +index 566c33a7a..ef9305513 100644 +--- a/libc/bionic/brk.cpp ++++ b/libc/bionic/brk.cpp +@@ -29,48 +29,16 @@ + #include + #include + +-#if defined(__LP64__) +-static void* __bionic_brk; +-#else +-void* __bionic_brk; // Accidentally exported by the NDK. ++#if !defined(__LP64__) ++void* __bionic_brk = reinterpret_cast(-1); // Accidentally exported by the NDK. + #endif + +-extern "C" void* __brk(void* __addr); +- +-int brk(void* end_data) { +- __bionic_brk = __brk(end_data); +- if (__bionic_brk < end_data) { +- errno = ENOMEM; +- return -1; +- } +- return 0; ++int brk(void*) { ++ errno = ENOMEM; ++ return -1; + } + +-void* sbrk(ptrdiff_t increment) { +- // Initialize __bionic_brk if necessary. +- if (__bionic_brk == nullptr) { +- __bionic_brk = __brk(nullptr); +- } +- +- // Don't ask the kernel if we already know the answer. +- if (increment == 0) { +- return __bionic_brk; +- } +- +- // Avoid overflow. +- uintptr_t old_brk = reinterpret_cast(__bionic_brk); +- if ((increment > 0 && static_cast(increment) > (UINTPTR_MAX - old_brk)) || +- (increment < 0 && static_cast(-increment) > old_brk)) { +- errno = ENOMEM; +- return reinterpret_cast(-1); +- } +- +- void* desired_brk = reinterpret_cast(old_brk + increment); +- __bionic_brk = __brk(desired_brk); +- if (__bionic_brk < desired_brk) { +- errno = ENOMEM; +- return reinterpret_cast(-1); +- } +- +- return reinterpret_cast(old_brk); ++void* sbrk(ptrdiff_t) { ++ errno = ENOMEM; ++ return reinterpret_cast(-1); + } diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-3.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-3.patch new file mode 100644 index 00000000..303c4566 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-3.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Mon, 4 Mar 2019 04:26:04 -0500 +Subject: [PATCH] use blocking getrandom and avoid urandom fallback + +Signed-off-by: anupritaisno1 +--- + libc/bionic/getentropy.cpp | 28 +++------------------------- + 1 file changed, 3 insertions(+), 25 deletions(-) + +diff --git a/libc/bionic/getentropy.cpp b/libc/bionic/getentropy.cpp +index 9c93e713b..c9438ad2b 100644 +--- a/libc/bionic/getentropy.cpp ++++ b/libc/bionic/getentropy.cpp +@@ -33,22 +33,6 @@ + + #include "private/ScopedFd.h" + +-static int getentropy_urandom(void* buffer, size_t buffer_size, int saved_errno) { +- ScopedFd fd(TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY | O_NOFOLLOW | O_CLOEXEC, 0))); +- if (fd.get() == -1) return -1; +- +- size_t collected = 0; +- while (collected < buffer_size) { +- ssize_t count = TEMP_FAILURE_RETRY(read(fd.get(), static_cast(buffer) + collected, +- buffer_size - collected)); +- if (count == -1) return -1; +- collected += count; +- } +- +- errno = saved_errno; +- return 0; +-} +- + int getentropy(void* buffer, size_t buffer_size) { + if (buffer_size > 256) { + errno = EIO; +@@ -59,16 +43,10 @@ int getentropy(void* buffer, size_t buffer_size) { + + size_t collected = 0; + while (collected < buffer_size) { +- long count = TEMP_FAILURE_RETRY(getrandom(static_cast(buffer) + collected, +- buffer_size - collected, GRND_NONBLOCK)); ++ long count = TEMP_FAILURE_RETRY( ++ getrandom(static_cast(buffer) + collected, buffer_size - collected, 0)); + if (count == -1) { +- // EAGAIN: there isn't enough entropy right now. +- // ENOSYS/EINVAL: getrandom(2) or GRND_NONBLOCK isn't supported. +- // EFAULT: `buffer` is invalid. +- // Try /dev/urandom regardless because it can't hurt, +- // and we don't need to optimize the EFAULT case. +- // See http://b/33059407 and http://b/67015565. +- return getentropy_urandom(buffer, buffer_size, saved_errno); ++ return -1; + } + collected += count; + } diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-4.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-4.patch new file mode 100644 index 00000000..85560f79 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-4.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Mon, 19 Sep 2016 07:57:43 -0400 +Subject: [PATCH] fix undefined out-of-bounds accesses in sched.h + +Signed-off-by: anupritaisno1 +--- + libc/include/sched.h | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/libc/include/sched.h b/libc/include/sched.h +index 3260231cf..00c2a4a45 100644 +--- a/libc/include/sched.h ++++ b/libc/include/sched.h +@@ -70,7 +70,10 @@ int setns(int __fd, int __ns_type) __INTRODUCED_IN(21); + #define __CPU_MASK(x) ((__CPU_BITTYPE)1 << ((x) & (__CPU_BITS - 1))) + + typedef struct { +- __CPU_BITTYPE __bits[ CPU_SETSIZE / __CPU_BITS ]; ++ union { ++ __CPU_BITTYPE __bits_minimum[ CPU_SETSIZE / __CPU_BITS ]; ++ __CPU_BITTYPE __bits[0]; ++ }; + } cpu_set_t; + + int sched_setaffinity(pid_t __pid, size_t __set_size, const cpu_set_t* __set); diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-5.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-5.patch new file mode 100644 index 00000000..42308ae1 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-5.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sat, 19 Nov 2016 09:56:14 -0500 +Subject: [PATCH] stop implicitly marking mappings as mergeable + +Signed-off-by: anupritaisno1 +--- + libc/bionic/mmap.cpp | 19 +------------------ + 1 file changed, 1 insertion(+), 18 deletions(-) + +diff --git a/libc/bionic/mmap.cpp b/libc/bionic/mmap.cpp +index 9aad0b315..6bf0ecfd1 100644 +--- a/libc/bionic/mmap.cpp ++++ b/libc/bionic/mmap.cpp +@@ -39,8 +39,6 @@ extern "C" void* __mmap2(void*, size_t, int, int, int, size_t); + + #define MMAP2_SHIFT 12 // 2**12 == 4096 + +-static bool kernel_has_MADV_MERGEABLE = true; +- + void* mmap64(void* addr, size_t size, int prot, int flags, int fd, off64_t offset) { + if (offset < 0 || (offset & ((1UL << MMAP2_SHIFT)-1)) != 0) { + errno = EINVAL; +@@ -54,22 +52,7 @@ void* mmap64(void* addr, size_t size, int prot, int flags, int fd, off64_t offse + return MAP_FAILED; + } + +- bool is_private_anonymous = +- (flags & (MAP_PRIVATE | MAP_ANONYMOUS)) == (MAP_PRIVATE | MAP_ANONYMOUS); +- bool is_stack_or_grows_down = (flags & (MAP_STACK | MAP_GROWSDOWN)) != 0; +- +- void* result = __mmap2(addr, size, prot, flags, fd, offset >> MMAP2_SHIFT); +- +- if (result != MAP_FAILED && kernel_has_MADV_MERGEABLE && +- is_private_anonymous && !is_stack_or_grows_down) { +- ErrnoRestorer errno_restorer; +- int rc = madvise(result, size, MADV_MERGEABLE); +- if (rc == -1 && errno == EINVAL) { +- kernel_has_MADV_MERGEABLE = false; +- } +- } +- +- return result; ++ return __mmap2(addr, size, prot, flags, fd, offset >> MMAP2_SHIFT); + } + + void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset) { diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-6.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-6.patch new file mode 100644 index 00000000..32c6781e --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-6.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sat, 16 Jul 2016 23:55:16 -0400 +Subject: [PATCH] replace VLA formatting with dprintf-like function + +Signed-off-by: anupritaisno1 +--- + libc/bionic/bionic_systrace.cpp | 10 +--------- + 1 file changed, 1 insertion(+), 9 deletions(-) + +diff --git a/libc/bionic/bionic_systrace.cpp b/libc/bionic/bionic_systrace.cpp +index fd9771298..acd9b7681 100644 +--- a/libc/bionic/bionic_systrace.cpp ++++ b/libc/bionic/bionic_systrace.cpp +@@ -27,8 +27,6 @@ + #include + #include // For ATRACE_TAG_BIONIC. + +-#define WRITE_OFFSET 32 +- + static Lock g_lock; + static CachedProperty g_debug_atrace_tags_enableflags("debug.atrace.tags.enableflags"); + static uint64_t g_tags; +@@ -65,15 +63,9 @@ void bionic_trace_begin(const char* message) { + return; + } + +- // If bionic tracing has been enabled, then write the message to the +- // kernel trace_marker. +- int length = strlen(message); +- char buf[length + WRITE_OFFSET]; +- size_t len = async_safe_format_buffer(buf, length + WRITE_OFFSET, "B|%d|%s", getpid(), message); +- + // Tracing may stop just after checking property and before writing the message. + // So the write is acceptable to fail. See b/20666100. +- TEMP_FAILURE_RETRY(write(trace_marker_fd, buf, len)); ++ async_safe_format_fd(trace_marker_fd, "B|%d|%s", getpid(), message); + } + + void bionic_trace_end() { diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-7.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-7.patch new file mode 100644 index 00000000..79db2741 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-7.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Fri, 17 Jul 2015 21:32:05 -0400 +Subject: [PATCH] increase default pthread stack to 8MiB on 64-bit + +Signed-off-by: anupritaisno1 +--- + libc/bionic/pthread_internal.h | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h +index 071a5bcb3..ab71e2a17 100644 +--- a/libc/bionic/pthread_internal.h ++++ b/libc/bionic/pthread_internal.h +@@ -238,7 +238,11 @@ __LIBC_HIDDEN__ void pthread_key_clean_all(void); + // stack overflows, we subtracted the same amount we were using there + // from the default thread stack size. This should keep memory usage + // roughly constant. ++#ifdef __LP64__ ++#define PTHREAD_STACK_SIZE_DEFAULT ((8 * 1024 * 1024) - SIGNAL_STACK_SIZE_WITHOUT_GUARD) ++#else + #define PTHREAD_STACK_SIZE_DEFAULT ((1 * 1024 * 1024) - SIGNAL_STACK_SIZE_WITHOUT_GUARD) ++#endif + + // Leave room for a guard page in the internally created signal stacks. + #define SIGNAL_STACK_SIZE (SIGNAL_STACK_SIZE_WITHOUT_GUARD + PTHREAD_GUARD_SIZE) diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-8.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-8.patch new file mode 100644 index 00000000..8f53f0f5 --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-8.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sat, 1 Oct 2016 05:11:44 -0400 +Subject: [PATCH] make __stack_chk_guard read-only at runtime + +Signed-off-by: anupritaisno1 +--- + libc/bionic/__libc_init_main_thread.cpp | 15 ++++++++++++--- + 1 file changed, 12 insertions(+), 3 deletions(-) + +diff --git a/libc/bionic/__libc_init_main_thread.cpp b/libc/bionic/__libc_init_main_thread.cpp +index 95f46e9fa..7e1e7cbcb 100644 +--- a/libc/bionic/__libc_init_main_thread.cpp ++++ b/libc/bionic/__libc_init_main_thread.cpp +@@ -28,6 +28,9 @@ + + #include "libc_init_common.h" + ++#include ++#include ++ + #include + + #include "private/KernelArgumentBlock.h" +@@ -35,14 +38,14 @@ + #include "private/bionic_defs.h" + #include "private/bionic_elf_tls.h" + #include "private/bionic_globals.h" +-#include "private/bionic_ssp.h" + #include "pthread_internal.h" + + extern "C" pid_t __getpid(); + extern "C" int __set_tid_address(int* tid_address); + + // Declared in "private/bionic_ssp.h". +-uintptr_t __stack_chk_guard = 0; ++__attribute__((aligned(PAGE_SIZE))) ++uintptr_t __stack_chk_guard[PAGE_SIZE / sizeof(uintptr_t)] = {0}; + + static pthread_internal_t main_thread; + +@@ -107,10 +110,16 @@ void __init_tcb_dtv(bionic_tcb* tcb) { + // Note in particular that it is not possible to return from any existing + // stack frame with stack protector enabled after this function is called. + extern "C" void android_reset_stack_guards() { ++ if (mprotect(__stack_chk_guard, sizeof(__stack_chk_guard), PROT_READ|PROT_WRITE) == -1) { ++ async_safe_fatal("mprotect __stack_chk_guard: %s", strerror(errno)); ++ } + // The TLS stack guard is set from the global, so ensure that we've initialized the global + // before we initialize the TLS. Dynamic executables will initialize their copy of the global + // stack protector from the one in the main thread's TLS. +- __libc_safe_arc4random_buf(&__stack_chk_guard, sizeof(__stack_chk_guard)); ++ __libc_safe_arc4random_buf(&__stack_chk_guard[0], sizeof(__stack_chk_guard[0])); ++ if (mprotect(__stack_chk_guard, sizeof(__stack_chk_guard), PROT_READ) == -1) { ++ async_safe_fatal("mprotect __stack_chk_guard: %s", strerror(errno)); ++ } + __init_tcb_stack_guard(__get_bionic_tcb()); + } + diff --git a/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-9.patch b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-9.patch new file mode 100644 index 00000000..df49e4bd --- /dev/null +++ b/Patches/LineageOS-19.1/android_bionic/0002-Graphene_Bionic_Hardening-9.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sun, 12 Mar 2017 17:49:13 -0400 +Subject: [PATCH] on 64-bit, zero the leading stack canary byte + +This reduces entropy of the canary from 64-bit to 56-bit in exchange for +mitigating non-terminated C string overflows. + +Signed-off-by: anupritaisno1 +--- + libc/bionic/__libc_init_main_thread.cpp | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/libc/bionic/__libc_init_main_thread.cpp b/libc/bionic/__libc_init_main_thread.cpp +index 7e1e7cbcb..5bdf61d2c 100644 +--- a/libc/bionic/__libc_init_main_thread.cpp ++++ b/libc/bionic/__libc_init_main_thread.cpp +@@ -49,6 +49,12 @@ uintptr_t __stack_chk_guard[PAGE_SIZE / sizeof(uintptr_t)] = {0}; + + static pthread_internal_t main_thread; + ++#if __LP64__ ++static const uintptr_t canary_mask = __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ? ++ 0xffffffffffffff00UL : ++ 0x00ffffffffffffffUL; ++#endif ++ + // Setup for the main thread. For dynamic executables, this is called by the + // linker _before_ libc is mapped in memory. This means that all writes to + // globals from this function will apply to linker-private copies and will not +@@ -117,6 +123,10 @@ extern "C" void android_reset_stack_guards() { + // before we initialize the TLS. Dynamic executables will initialize their copy of the global + // stack protector from the one in the main thread's TLS. + __libc_safe_arc4random_buf(&__stack_chk_guard[0], sizeof(__stack_chk_guard[0])); ++#if __LP64__ ++ // Sacrifice 8 bits of entropy on 64-bit to mitigate non-terminated C string overflows ++ __stack_chk_guard[0] &= canary_mask; ++#endif + if (mprotect(__stack_chk_guard, sizeof(__stack_chk_guard), PROT_READ) == -1) { + async_safe_fatal("mprotect __stack_chk_guard: %s", strerror(errno)); + } diff --git a/Patches/LineageOS-19.1/android_bootable_recovery/0001-No_SerialNum_Restrictions.patch b/Patches/LineageOS-19.1/android_bootable_recovery/0001-No_SerialNum_Restrictions.patch new file mode 100644 index 00000000..c2e7b71a --- /dev/null +++ b/Patches/LineageOS-19.1/android_bootable_recovery/0001-No_SerialNum_Restrictions.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 19 Aug 2020 09:31:04 -0400 +Subject: [PATCH] reject updates with serialno constraints + +--- + install/install.cpp | 16 ++-------------- + 1 file changed, 2 insertions(+), 14 deletions(-) + +diff --git a/install/install.cpp b/install/install.cpp +index d4f069d8..374f0cdc 100644 +--- a/install/install.cpp ++++ b/install/install.cpp +@@ -221,22 +221,10 @@ bool CheckPackageMetadata(const std::map& metadata, Ot + return false; + } + +- // We allow the package to not have any serialno; and we also allow it to carry multiple serial +- // numbers split by "|"; e.g. serialno=serialno1|serialno2|serialno3 ... We will fail the +- // verification if the device's serialno doesn't match any of these carried numbers. + auto pkg_serial_no = get_value(metadata, "serialno"); + if (!pkg_serial_no.empty()) { +- auto device_serial_no = android::base::GetProperty("ro.serialno", ""); +- bool serial_number_match = false; +- for (const auto& number : android::base::Split(pkg_serial_no, "|")) { +- if (device_serial_no == android::base::Trim(number)) { +- serial_number_match = true; +- } +- } +- if (!serial_number_match) { +- LOG(ERROR) << "Package is for serial " << pkg_serial_no; +- return false; +- } ++ LOG(ERROR) << "Serial number constraint not permitted: " << pkg_serial_no; ++ return INSTALL_ERROR; + } + + if (ota_type == OtaType::AB) { diff --git a/Patches/LineageOS-19.1/android_build/0001-Enable_fwrapv.patch b/Patches/LineageOS-19.1/android_build/0001-Enable_fwrapv.patch new file mode 100644 index 00000000..20417c01 --- /dev/null +++ b/Patches/LineageOS-19.1/android_build/0001-Enable_fwrapv.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Tue, 13 Sep 2016 22:05:56 -0400 +Subject: [PATCH] use -fwrapv when signed overflow checking is off + +Signed-off-by: anupritaisno1 +--- + core/config_sanitizers.mk | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk +index 46f7f2477b..017aa23822 100644 +--- a/core/config_sanitizers.mk ++++ b/core/config_sanitizers.mk +@@ -508,3 +508,9 @@ ifneq ($(findstring fsanitize,$(my_cflags)),) + endif + endif + endif ++ ++ifeq ($(filter signed-integer-overflow integer undefined,$(my_sanitize)),) ++ ifeq ($(filter -ftrapv,$(my_cflags)),) ++ my_cflags += -fwrapv ++ endif ++endif diff --git a/Patches/LineageOS-19.1/android_build/0002-OTA_Keys.patch b/Patches/LineageOS-19.1/android_build/0002-OTA_Keys.patch new file mode 100644 index 00000000..c09d7f7e --- /dev/null +++ b/Patches/LineageOS-19.1/android_build/0002-OTA_Keys.patch @@ -0,0 +1,69 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tad +Date: Tue, 6 Apr 2021 05:04:32 -0400 +Subject: [PATCH] Allow setting OTA public keys from environment variable + +Change-Id: Ib2a00de63b0c7a8790640462d13a84daf2076fa7 +--- + core/product_config.mk | 5 +++++ + target/product/security/Android.mk | 21 +++++++++++++++++---- + 2 files changed, 22 insertions(+), 4 deletions(-) + +diff --git a/core/product_config.mk b/core/product_config.mk +index 4b4ba3ccb8..dac79d1ff7 100644 +--- a/core/product_config.mk ++++ b/core/product_config.mk +@@ -314,6 +314,11 @@ ENFORCE_SYSTEM_CERTIFICATE_ALLOW_LIST := $(PRODUCT_ARTIFACT_SYSTEM_CERTIFICATE_R + PRODUCT_OTA_PUBLIC_KEYS := $(sort $(PRODUCT_OTA_PUBLIC_KEYS)) + PRODUCT_EXTRA_RECOVERY_KEYS := $(sort $(PRODUCT_EXTRA_RECOVERY_KEYS)) + ++ifneq ($(OTA_KEY_OVERRIDE_DIR),) ++ PRODUCT_OTA_PUBLIC_KEYS := $(OTA_KEY_OVERRIDE_DIR)/releasekey.x509.pem ++ PRODUCT_EXTRA_RECOVERY_KEYS := $(OTA_KEY_OVERRIDE_DIR)/extra ++endif ++ + # Resolve and setup per-module dex-preopt configs. + DEXPREOPT_DISABLED_MODULES := + # If a module has multiple setups, the first takes precedence. +diff --git a/target/product/security/Android.mk b/target/product/security/Android.mk +index cedad5b490..7eea027506 100644 +--- a/target/product/security/Android.mk ++++ b/target/product/security/Android.mk +@@ -63,8 +63,15 @@ LOCAL_MODULE_CLASS := ETC + LOCAL_MODULE_STEM := otacerts.zip + LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/security + include $(BUILD_SYSTEM)/base_rules.mk +-$(LOCAL_BUILT_MODULE): PRIVATE_CERT := $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem +-$(LOCAL_BUILT_MODULE): $(SOONG_ZIP) $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem ++ ++OTA_PUBLIC_KEYS := $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem ++ ++ifneq ($(OTA_KEY_OVERRIDE_DIR),) ++ OTA_PUBLIC_KEYS := $(OTA_KEY_OVERRIDE_DIR)/releasekey.x509.pem ++endif ++ ++$(LOCAL_BUILT_MODULE): PRIVATE_CERT := $(OTA_PUBLIC_KEYS) ++$(LOCAL_BUILT_MODULE): $(SOONG_ZIP) $(OTA_PUBLIC_KEYS) + $(SOONG_ZIP) -o $@ -j -symlinks=false -f $(PRIVATE_CERT) + + +@@ -82,11 +89,17 @@ include $(BUILD_SYSTEM)/base_rules.mk + + extra_recovery_keys := $(patsubst %,%.x509.pem,$(PRODUCT_EXTRA_RECOVERY_KEYS)) + +-$(LOCAL_BUILT_MODULE): PRIVATE_CERT := $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem +++OTA_PUBLIC_KEYS := $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem +++ ++ifneq ($(OTA_KEY_OVERRIDE_DIR),) ++ OTA_PUBLIC_KEYS := $(OTA_KEY_OVERRIDE_DIR)/releasekey.x509.pem ++endif ++ ++$(LOCAL_BUILT_MODULE): PRIVATE_CERT := $(OTA_PUBLIC_KEYS) + $(LOCAL_BUILT_MODULE): PRIVATE_EXTRA_RECOVERY_KEYS := $(extra_recovery_keys) + $(LOCAL_BUILT_MODULE): \ + $(SOONG_ZIP) \ +- $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem \ ++ $(OTA_PUBLIC_KEYS) \ + $(extra_recovery_keys) + $(SOONG_ZIP) -o $@ -j -symlinks=false \ + $(foreach key_file, $(PRIVATE_CERT) $(PRIVATE_EXTRA_RECOVERY_KEYS), -f $(key_file)) diff --git a/Patches/LineageOS-19.1/android_build/0003-Exec_Based_Spawning.patch b/Patches/LineageOS-19.1/android_build/0003-Exec_Based_Spawning.patch new file mode 100644 index 00000000..d69dc1c8 --- /dev/null +++ b/Patches/LineageOS-19.1/android_build/0003-Exec_Based_Spawning.patch @@ -0,0 +1,28 @@ +From 8e01dd93f29aba79e15a211084582afd9681e8ab Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Thu, 17 Sep 2020 10:53:00 -0400 +Subject: [PATCH] disable enforce RRO for mainline devices + +This is currently incompatible with exec-based spawning. This also +impacts the wrapper spawning model for the stock OS which is available +by default, making it an upstream bug rather than a missing feature for +exec-based spawning in GrapheneOS. + +Signed-off-by: anupritaisno1 +--- + target/product/generic_system.mk | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/target/product/generic_system.mk b/target/product/generic_system.mk +index d930957dfb..f0a9400b86 100644 +--- a/target/product/generic_system.mk ++++ b/target/product/generic_system.mk +@@ -113,7 +113,7 @@ PRODUCT_COPY_FILES += \ + # Enable dynamic partition size + PRODUCT_USE_DYNAMIC_PARTITION_SIZE := true + +-PRODUCT_ENFORCE_RRO_TARGETS := * ++#PRODUCT_ENFORCE_RRO_TARGETS := * + + PRODUCT_NAME := generic_system + PRODUCT_BRAND := generic diff --git a/Patches/LineageOS-19.1/android_build_soong/0001-Enable_fwrapv.patch b/Patches/LineageOS-19.1/android_build_soong/0001-Enable_fwrapv.patch new file mode 100644 index 00000000..1820db5f --- /dev/null +++ b/Patches/LineageOS-19.1/android_build_soong/0001-Enable_fwrapv.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 23 Aug 2017 20:28:03 -0400 +Subject: [PATCH] use -fwrapv when signed overflow checking is off + +Signed-off-by: anupritaisno1 +--- + cc/cc.go | 2 ++ + cc/sanitize.go | 12 ++++++++++++ + 2 files changed, 14 insertions(+) + +diff --git a/cc/cc.go b/cc/cc.go +index 619acf96b..02ec906a0 100644 +--- a/cc/cc.go ++++ b/cc/cc.go +@@ -1710,6 +1710,8 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { + } + if c.sanitize != nil { + flags = c.sanitize.flags(ctx, flags) ++ } else { ++ flags.Local.CFlags = append(flags.Local.CFlags, "-fwrapv") + } + if c.coverage != nil { + flags, deps = c.coverage.flags(ctx, flags, deps) +diff --git a/cc/sanitize.go b/cc/sanitize.go +index 941a955e5..694a3659f 100644 +--- a/cc/sanitize.go ++++ b/cc/sanitize.go +@@ -556,9 +556,21 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { + } + + if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep { ++ flags.Local.CFlags = append(flags.Local.CFlags, "-fwrapv") + return flags + } + ++ wrapv := true ++ for _, element := range sanitize.Properties.Sanitizers { ++ if (element == "signed-integer-overflow" || element == "integer" || element == "undefined") { ++ wrapv = false ++ break ++ } ++ } ++ if wrapv { ++ flags.Local.CFlags = append(flags.Local.CFlags, "-fwrapv") ++ } ++ + if Bool(sanitize.Properties.Sanitize.Address) { + if ctx.Arch().ArchType == android.Arm { + // Frame pointer based unwinder in ASan requires ARM frame setup. diff --git a/Patches/LineageOS-19.1/android_build_soong/0002-hm_apex.patch b/Patches/LineageOS-19.1/android_build_soong/0002-hm_apex.patch new file mode 100644 index 00000000..59606924 --- /dev/null +++ b/Patches/LineageOS-19.1/android_build_soong/0002-hm_apex.patch @@ -0,0 +1,21 @@ +From cc973e807d440a2cfe7bed420fbf7ae25985ddc1 Mon Sep 17 00:00:00 2001 +From: anupritaisno1 +Date: Sun, 13 Sep 2020 09:35:41 +0000 +Subject: [PATCH] make hardened malloc available to apexes + +--- + apex/apex.go | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/apex/apex.go b/apex/apex.go +index 77854074b..d7ae35c3d 100644 +--- a/apex/apex.go ++++ b/apex/apex.go +@@ -2899,6 +2899,7 @@ func makeApexAvailableBaseline() map[string][]string { + "libdebuggerd_handler_fallback", + "libdl_static", + "libjemalloc5", ++ "libhardened_malloc", + "liblinker_main", + "liblinker_malloc", + "liblz4", diff --git a/Patches/LineageOS-19.1/android_external_conscrypt/0001-constify_JNINativeMethod.patch b/Patches/LineageOS-19.1/android_external_conscrypt/0001-constify_JNINativeMethod.patch new file mode 100644 index 00000000..ccb02e9e --- /dev/null +++ b/Patches/LineageOS-19.1/android_external_conscrypt/0001-constify_JNINativeMethod.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 18 Nov 2020 14:28:24 -0500 +Subject: [PATCH] constify JNINativeMethod table + +--- + common/src/jni/main/cpp/conscrypt/native_crypto.cc | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/common/src/jni/main/cpp/conscrypt/native_crypto.cc b/common/src/jni/main/cpp/conscrypt/native_crypto.cc +index 5b0acf0d..f8142151 100644 +--- a/common/src/jni/main/cpp/conscrypt/native_crypto.cc ++++ b/common/src/jni/main/cpp/conscrypt/native_crypto.cc +@@ -10354,7 +10354,7 @@ static jlong NativeCrypto_SSL_get1_session(JNIEnv* env, jclass, jlong ssl_addres + #define REF_X509_CRL "L" TO_STRING(JNI_JARJAR_PREFIX) "org/conscrypt/OpenSSLX509CRL;" + #define REF_SSL "L" TO_STRING(JNI_JARJAR_PREFIX) "org/conscrypt/NativeSsl;" + #define REF_SSL_CTX "L" TO_STRING(JNI_JARJAR_PREFIX) "org/conscrypt/AbstractSessionContext;" +-static JNINativeMethod sNativeCryptoMethods[] = { ++static const JNINativeMethod sNativeCryptoMethods[] = { + CONSCRYPT_NATIVE_METHOD(clinit, "()V"), + CONSCRYPT_NATIVE_METHOD(CMAC_CTX_new, "()J"), + CONSCRYPT_NATIVE_METHOD(CMAC_CTX_free, "(J)V"), diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0003-SUPL_No_IMSI.patch b/Patches/LineageOS-19.1/android_frameworks_base/0003-SUPL_No_IMSI.patch new file mode 100644 index 00000000..bf4b3de1 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0003-SUPL_No_IMSI.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MSe1969 +Date: Mon, 29 Oct 2018 12:14:17 +0100 +Subject: [PATCH] SUPL: Don't send IMSI / Phone number to SUPL server + +Change-Id: I5ccc4d61e52ac11ef33f44618d0e610089885b87 +--- + .../android/server/location/gnss/GnssLocationProvider.java | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java b/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java +index 9956da274263..65f5b836bfcf 100644 +--- a/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java ++++ b/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java +@@ -1601,6 +1601,11 @@ public class GnssLocationProvider extends AbstractLocationProvider implements + int type = AGPS_SETID_TYPE_NONE; + String setId = null; + ++ /* ++ * We don't want to tell Google our IMSI or phone number to spy on us! ++ * As devices w/o SIM card also have working GPS, providing this data does ++ * not seem to add a lot of value, at least not for the device holder ++ * + int ddSubId = SubscriptionManager.getDefaultDataSubscriptionId(); + if (SubscriptionManager.isValidSubscriptionId(ddSubId)) { + phone = phone.createForSubscriptionId(ddSubId); +@@ -1617,7 +1622,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements + // This means the framework has the SIM card. + type = AGPS_SETID_TYPE_MSISDN; + } +- } ++ } */ + + mGnssNative.setAgpsSetId(type, (setId == null) ? "" : setId); + } diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0004-Fingerprint_Lockout.patch b/Patches/LineageOS-19.1/android_frameworks_base/0004-Fingerprint_Lockout.patch new file mode 100644 index 00000000..6062f6ce --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0004-Fingerprint_Lockout.patch @@ -0,0 +1,23 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Tue, 12 Sep 2017 01:52:11 -0400 +Subject: [PATCH] use permanent fingerprint lockout immediately + +Signed-off-by: anupritaisno1 +--- + .../sensors/fingerprint/hidl/LockoutFrameworkImpl.java | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/services/core/java/com/android/server/biometrics/sensors/fingerprint/hidl/LockoutFrameworkImpl.java b/services/core/java/com/android/server/biometrics/sensors/fingerprint/hidl/LockoutFrameworkImpl.java +index dc5dace98825..efee4843aa99 100644 +--- a/services/core/java/com/android/server/biometrics/sensors/fingerprint/hidl/LockoutFrameworkImpl.java ++++ b/services/core/java/com/android/server/biometrics/sensors/fingerprint/hidl/LockoutFrameworkImpl.java +@@ -41,7 +41,7 @@ public class LockoutFrameworkImpl implements LockoutTracker { + private static final String ACTION_LOCKOUT_RESET = + "com.android.server.biometrics.sensors.fingerprint.ACTION_LOCKOUT_RESET"; + private static final int MAX_FAILED_ATTEMPTS_LOCKOUT_TIMED = 5; +- private static final int MAX_FAILED_ATTEMPTS_LOCKOUT_PERMANENT = 20; ++ private static final int MAX_FAILED_ATTEMPTS_LOCKOUT_PERMANENT = 3; + private static final long FAIL_LOCKOUT_TIMEOUT_MS = 30 * 1000; + private static final String KEY_LOCKOUT_RESET_USER = "lockout_reset_user"; + diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0005-User_Logout.patch b/Patches/LineageOS-19.1/android_frameworks_base/0005-User_Logout.patch new file mode 100644 index 00000000..adad8f0e --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0005-User_Logout.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: flawedworld +Date: Fri, 15 Oct 2021 17:07:13 +0100 +Subject: [PATCH] enable secondary user logout support by default + +Ported from 11, 12 moved the isLogoutEnabled boolean to ActiveAdmin.java +--- + .../java/com/android/server/devicepolicy/ActiveAdmin.java | 2 +- + .../server/devicepolicy/DevicePolicyManagerService.java | 4 ++-- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java b/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java +index 37a84f3698c1..0ae88276ebda 100644 +--- a/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java ++++ b/services/devicepolicy/java/com/android/server/devicepolicy/ActiveAdmin.java +@@ -197,7 +197,7 @@ class ActiveAdmin { + boolean requireAutoTime = false; + boolean forceEphemeralUsers = false; + boolean isNetworkLoggingEnabled = false; +- boolean isLogoutEnabled = false; ++ boolean isLogoutEnabled = true; + + // one notification after enabling + one more after reboots + static final int DEF_MAXIMUM_NETWORK_LOGGING_NOTIFICATIONS_SHOWN = 2; +diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +index dbbbd41ceeb3..5f66da8d8431 100644 +--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java ++++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +@@ -15796,11 +15796,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { + @Override + public boolean isLogoutEnabled() { + if (!mHasFeature) { +- return false; ++ return true; + } + synchronized (getLockObject()) { + ActiveAdmin deviceOwner = getDeviceOwnerAdminLocked(); +- return (deviceOwner != null) && deviceOwner.isLogoutEnabled; ++ return (deviceOwner == null) || deviceOwner.isLogoutEnabled; + } + } + diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0007-Always_Restict_Serial.patch b/Patches/LineageOS-19.1/android_frameworks_base/0007-Always_Restict_Serial.patch new file mode 100644 index 00000000..f858d90f --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0007-Always_Restict_Serial.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 6 Sep 2017 21:40:48 -0400 +Subject: [PATCH] always set deprecated Build.SERIAL to UNKNOWN + +Only support fetching the serial number via the new Build.getSerial() +requiring the READ_PHONE_STATE permission. +--- + .../java/com/android/server/am/ActivityManagerService.java | 7 +------ + 1 file changed, 1 insertion(+), 6 deletions(-) + +diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java +index 330d2ddc0a94..77521e64d603 100644 +--- a/services/core/java/com/android/server/am/ActivityManagerService.java ++++ b/services/core/java/com/android/server/am/ActivityManagerService.java +@@ -4478,12 +4478,7 @@ public class ActivityManagerService extends IActivityManager.Stub + + ProfilerInfo profilerInfo = mAppProfiler.setupProfilerInfoLocked(thread, app, instr); + +- // We deprecated Build.SERIAL and it is not accessible to +- // Instant Apps and target APIs higher than O MR1. Since access to the serial +- // is now behind a permission we push down the value. +- final String buildSerial = (!appInfo.isInstantApp() +- && appInfo.targetSdkVersion < Build.VERSION_CODES.P) +- ? sTheRealBuildSerial : Build.UNKNOWN; ++ final String buildSerial = Build.UNKNOWN; + + // Figure out whether the app needs to run in autofill compat mode. + AutofillOptions autofillOptions = null; diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0008-Browser_No_Location.patch b/Patches/LineageOS-19.1/android_frameworks_base/0008-Browser_No_Location.patch new file mode 100644 index 00000000..0fc03836 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0008-Browser_No_Location.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sun, 17 Mar 2019 19:54:30 -0400 +Subject: [PATCH] stop auto-granting location to system browsers + +--- + .../pm/permission/DefaultPermissionGrantPolicy.java | 13 ------------- + 1 file changed, 13 deletions(-) + +diff --git a/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java b/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java +index cb28637e8c10..77ae50533f42 100644 +--- a/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java ++++ b/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java +@@ -706,19 +706,6 @@ final class DefaultPermissionGrantPolicy { + Intent.CATEGORY_APP_EMAIL, userId), + userId, CONTACTS_PERMISSIONS, CALENDAR_PERMISSIONS); + +- // Browser +- String browserPackage = ArrayUtils.firstOrNull(getKnownPackages( +- PackageManagerInternal.PACKAGE_BROWSER, userId)); +- if (browserPackage == null) { +- browserPackage = getDefaultSystemHandlerActivityPackageForCategory(pm, +- Intent.CATEGORY_APP_BROWSER, userId); +- if (!pm.isSystemPackage(browserPackage)) { +- browserPackage = null; +- } +- } +- grantPermissionsToPackage(pm, browserPackage, userId, false /* ignoreSystemPackage */, +- true /*whitelistRestrictedPermissions*/, FOREGROUND_LOCATION_PERMISSIONS); +- + // Voice interaction + if (voiceInteractPackageNames != null) { + for (String voiceInteractPackageName : voiceInteractPackageNames) { diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0009-SystemUI_No_Permission_Review.patch b/Patches/LineageOS-19.1/android_frameworks_base/0009-SystemUI_No_Permission_Review.patch new file mode 100644 index 00000000..3d2ca5f7 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0009-SystemUI_No_Permission_Review.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Tue, 18 Dec 2018 08:48:14 -0500 +Subject: [PATCH] allow SystemUI to directly manage Bluetooth/WiFi + +--- + packages/SystemUI/AndroidManifest.xml | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml +index 6cf77882019c..5797aa01bfc0 100644 +--- a/packages/SystemUI/AndroidManifest.xml ++++ b/packages/SystemUI/AndroidManifest.xml +@@ -84,6 +84,8 @@ + + + ++ ++ + + + diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0013-Network_Permission-1.patch b/Patches/LineageOS-19.1/android_frameworks_base/0013-Network_Permission-1.patch new file mode 100644 index 00000000..47b9b463 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0013-Network_Permission-1.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sun, 17 Mar 2019 11:59:15 -0400 +Subject: [PATCH] make INTERNET into a special runtime permission + +Ported from 10: 5e2898e9d21dd6802bb0b0139e7e496c41e1cd80 +--- + core/res/AndroidManifest.xml | 2 +- + .../android/server/pm/permission/PermissionManagerService.java | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml +index 030310406949..7c4a046fda7b 100644 +--- a/core/res/AndroidManifest.xml ++++ b/core/res/AndroidManifest.xml +@@ -1735,7 +1735,7 @@ + ++ android:protectionLevel="dangerous|instant" /> + + + + ++ ++ ++ + + +diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml +index 166d6abd1809..27c9026c863a 100644 +--- a/core/res/res/values/strings.xml ++++ b/core/res/res/values/strings.xml +@@ -837,6 +837,11 @@ + + access sensor data about your vital signs + ++ ++ Network ++ ++ access the network ++ + + Retrieve window content + diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0013-Network_Permission-3.patch b/Patches/LineageOS-19.1/android_frameworks_base/0013-Network_Permission-3.patch new file mode 100644 index 00000000..b5b77bb5 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0013-Network_Permission-3.patch @@ -0,0 +1,49 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Danny Lin +Date: Tue, 5 Oct 2021 16:27:43 -0700 +Subject: [PATCH] net: Notify ConnectivityService of runtime permission changes + +ConnectivityService needs permission change events in order to enforce +INTERNET permission updates correctly at runtime. + +Change-Id: I74b0b8a5aa70f0794b4f3d72c70167dbe2aae88d +--- + .../server/net/NetworkPolicyManagerService.java | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java +index 0a85854b2af8..236dd19e0982 100644 +--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java ++++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java +@@ -182,6 +182,7 @@ import android.content.pm.IPackageManager; + import android.content.pm.PackageInfo; + import android.content.pm.PackageManager; + import android.content.pm.PackageManager.NameNotFoundException; ++import android.content.pm.PackageManagerInternal; + import android.content.pm.UserInfo; + import android.content.res.Resources; + import android.database.ContentObserver; +@@ -282,6 +283,7 @@ import com.android.server.LocalServices; + import com.android.server.ServiceThread; + import com.android.server.SystemConfig; + import com.android.server.connectivity.MultipathPolicyTracker; ++import com.android.server.pm.permission.PermissionManagerServiceInternal; + import com.android.server.usage.AppStandbyInternal; + import com.android.server.usage.AppStandbyInternal.AppIdleStateChangeListener; + +@@ -797,6 +799,15 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { + public void bindConnectivityManager() { + mConnManager = Objects.requireNonNull(mContext.getSystemService(ConnectivityManager.class), + "missing ConnectivityManager"); ++ ++ // Listen for permission changes and forward to ConnectivityService ++ PermissionManagerServiceInternal pm = LocalServices.getService( ++ PermissionManagerServiceInternal.class); ++ PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class); ++ pm.addOnRuntimePermissionStateChangedListener((packageName, userId) -> { ++ int uid = pmi.getPackageUid(packageName, PackageManager.GET_PERMISSIONS, userId); ++ mConnManager.onPackagePermissionChanged(uid); ++ }); + } + + @GuardedBy("mUidRulesFirstLock") diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0013-Sensors_Permission.patch b/Patches/LineageOS-19.1/android_frameworks_base/0013-Sensors_Permission.patch new file mode 100644 index 00000000..c6f58c2d --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0013-Sensors_Permission.patch @@ -0,0 +1,113 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sat, 7 Oct 2017 15:54:42 -0400 +Subject: [PATCH] add special runtime permission for other sensors + +This covers sensors not included in the existing runtime permission for +body sensors. + +Ported from 10: 9ec9f7f521323552fa658b46862c8408f1a7b41b + +Changes from 10: +- Needed to run `m api-stubs-docs-non-updatable-update-current-api` +to fix the "You have tried to change the API from what has been +previously approved" errors. +--- + core/api/current.txt | 1 + + core/java/android/content/pm/PackageParser.java | 2 ++ + core/res/AndroidManifest.xml | 12 ++++++++++++ + core/res/res/values/strings.xml | 12 ++++++++++++ + .../pm/permission/PermissionManagerService.java | 2 +- + 5 files changed, 28 insertions(+), 1 deletion(-) + +diff --git a/core/api/current.txt b/core/api/current.txt +index 8d0391a80193..57f4821bb631 100644 +--- a/core/api/current.txt ++++ b/core/api/current.txt +@@ -116,6 +116,7 @@ package android { + field public static final String NFC = "android.permission.NFC"; + field public static final String NFC_PREFERRED_PAYMENT_INFO = "android.permission.NFC_PREFERRED_PAYMENT_INFO"; + field public static final String NFC_TRANSACTION_EVENT = "android.permission.NFC_TRANSACTION_EVENT"; ++ field public static final String OTHER_SENSORS = "android.permission.OTHER_SENSORS"; + field public static final String PACKAGE_USAGE_STATS = "android.permission.PACKAGE_USAGE_STATS"; + field @Deprecated public static final String PERSISTENT_ACTIVITY = "android.permission.PERSISTENT_ACTIVITY"; + field @Deprecated public static final String PROCESS_OUTGOING_CALLS = "android.permission.PROCESS_OUTGOING_CALLS"; +diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java +index 86fef5d9df19..5edc8d35082e 100644 +--- a/core/java/android/content/pm/PackageParser.java ++++ b/core/java/android/content/pm/PackageParser.java +@@ -283,6 +283,8 @@ public class PackageParser { + @UnsupportedAppUsage + public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] = + new PackageParser.NewPermissionInfo[] { ++ new PackageParser.NewPermissionInfo(android.Manifest.permission.OTHER_SENSORS, ++ android.os.Build.VERSION_CODES.CUR_DEVELOPMENT + 1, 0), + new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, + android.os.Build.VERSION_CODES.DONUT, 0), + new PackageParser.NewPermissionInfo(android.Manifest.permission.READ_PHONE_STATE, +diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml +index 76811630410d..3053eb4e1e16 100644 +--- a/core/res/AndroidManifest.xml ++++ b/core/res/AndroidManifest.xml +@@ -1498,6 +1498,18 @@ + android:description="@string/permdesc_useBiometric" + android:protectionLevel="normal" /> + ++ ++ ++ ++ + + + +diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml +index 27c9026c863a..4a8624222ae8 100644 +--- a/core/res/res/values/strings.xml ++++ b/core/res/res/values/strings.xml +@@ -837,6 +837,11 @@ + + access sensor data about your vital signs + ++ ++ Sensors ++ ++ access sensor data about orientation, movement, etc. ++ + + Network + +@@ -1165,6 +1170,13 @@ + Allows the app to access data from sensors + that monitor your physical condition, such as your heart rate. + ++ ++ access sensors (like the compass) ++ ++ ++ Allows the app to access data from sensors ++ monitoring orientation, movement, vibration (including low frequency sound) and environmental data ++ + + Read calendar events and details + +diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java +index 22d3fd41ea64..60dc0a027725 100644 +--- a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java ++++ b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java +@@ -2592,7 +2592,7 @@ public class PermissionManagerService extends IPermissionManager.Stub { + } + + public static boolean isSpecialRuntimePermission(final String permission) { +- return Manifest.permission.INTERNET.equals(permission); ++ return Manifest.permission.INTERNET.equals(permission) || Manifest.permission.OTHER_SENSORS.equals(permission); + } + + /** diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0013-Special_Permissions.patch b/Patches/LineageOS-19.1/android_frameworks_base/0013-Special_Permissions.patch new file mode 100644 index 00000000..04aa00a1 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0013-Special_Permissions.patch @@ -0,0 +1,99 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: inthewaves +Date: Sat, 12 Sep 2020 12:28:34 -0700 +Subject: [PATCH] support new special runtime permissions + +These are treated as a runtime permission even for legacy apps. They +need to be granted by default for all apps to maintain compatibility. + +Ported from 10: 4d5d82f4e2fb9ff68158bf30f3944591bb74dd04 + +Changes from 10: +- It seems like parts of PackageManagerService#resetUserChangesToRuntimePermissionsAndFlagsLPw +were refactored into PermissionManagerService#resetRuntimePermissionsInternal. +As a result, PackageManagerService is no longer modified. + +[kdrag0n: Ported to Android 12] +Signed-off-by: Danny Lin +--- + .../permission/PermissionManagerService.java | 25 +++++++++++++++---- + 1 file changed, 20 insertions(+), 5 deletions(-) + +diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java +index 54a6c678e0da..41b43e3c38bd 100644 +--- a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java ++++ b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java +@@ -1525,7 +1525,8 @@ public class PermissionManagerService extends IPermissionManager.Stub { + // their permissions as always granted runtime ones since we need + // to keep the review required permission flag per user while an + // install permission's state is shared across all users. +- if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M && bp.isRuntime()) { ++ if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M && bp.isRuntime() && ++ !isSpecialRuntimePermission(permName)) { + return; + } + +@@ -1568,7 +1569,8 @@ public class PermissionManagerService extends IPermissionManager.Stub { + + " for package " + packageName); + } + +- if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M) { ++ if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M && ++ !isSpecialRuntimePermission(permName)) { + Slog.w(TAG, "Cannot grant runtime permission to a legacy app"); + return; + } +@@ -1693,7 +1695,8 @@ public class PermissionManagerService extends IPermissionManager.Stub { + // their permissions as always granted runtime ones since we need + // to keep the review required permission flag per user while an + // install permission's state is shared across all users. +- if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M && bp.isRuntime()) { ++ if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M && bp.isRuntime() && ++ !isSpecialRuntimePermission(permName)) { + return; + } + +@@ -1898,7 +1901,8 @@ public class PermissionManagerService extends IPermissionManager.Stub { + + // If this permission was granted by default or role, make sure it is. + if ((oldFlags & FLAG_PERMISSION_GRANTED_BY_DEFAULT) != 0 +- || (oldFlags & FLAG_PERMISSION_GRANTED_BY_ROLE) != 0) { ++ || (oldFlags & FLAG_PERMISSION_GRANTED_BY_ROLE) != 0 ++ || isSpecialRuntimePermission(permName)) { + // PermissionPolicyService will handle the app op for runtime permissions later. + grantRuntimePermissionInternal(packageName, permName, false, + Process.SYSTEM_UID, userId, delayingPermCallback); +@@ -2587,6 +2591,10 @@ public class PermissionManagerService extends IPermissionManager.Stub { + } + } + ++ public static boolean isSpecialRuntimePermission(final String permission) { ++ return false; ++ } ++ + /** + * Restore the permission state for a package. + * +@@ -2966,6 +2974,13 @@ public class PermissionManagerService extends IPermissionManager.Stub { + } + } + } ++ ++ if (isSpecialRuntimePermission(permName) && ++ origPermState == null) { ++ if (uidState.grantPermission(bp)) { ++ wasChanged = true; ++ } ++ } + } else { + if (origPermState == null) { + // New permission +@@ -3803,7 +3818,7 @@ public class PermissionManagerService extends IPermissionManager.Stub { + if (shouldGrantPermission) { + final int flags = getPermissionFlagsInternal(pkg.getPackageName(), permission, + myUid, userId); +- if (supportsRuntimePermissions) { ++ if (supportsRuntimePermissions || isSpecialRuntimePermission(permission)) { + // Installer cannot change immutable permissions. + if ((flags & immutableFlags) == 0) { + grantRuntimePermissionInternal(pkg.getPackageName(), permission, false, diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0014-Automatic_Reboot.patch b/Patches/LineageOS-19.1/android_frameworks_base/0014-Automatic_Reboot.patch new file mode 100644 index 00000000..5b8c3e8e --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0014-Automatic_Reboot.patch @@ -0,0 +1,153 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: anupritaisno1 +Date: Mon, 18 Oct 2021 04:05:40 +0530 +Subject: [PATCH] automatically reboot device after timeout if set + +Signed-off-by: anupritaisno1 +Change-Id: If891bfbcc144c9336ba013260bad2b7c7a59c054 +--- + core/java/android/provider/Settings.java | 7 ++++ + data/etc/com.android.systemui.xml | 1 + + packages/SystemUI/AndroidManifest.xml | 3 ++ + .../keyguard/KeyguardViewMediator.java | 35 +++++++++++++++++++ + 4 files changed, 46 insertions(+) + +diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java +index 01e369779e1e..52103c3a3f99 100644 +--- a/core/java/android/provider/Settings.java ++++ b/core/java/android/provider/Settings.java +@@ -16378,6 +16378,13 @@ public final class Settings { + * @hide + */ + public static final String RESTRICTED_NETWORKING_MODE = "restricted_networking_mode"; ++ ++ /** ++ * Whether to automatically reboot the device after a user defined timeout ++ * ++ * @hide ++ */ ++ public static final String SETTINGS_REBOOT_AFTER_TIMEOUT = "settings_reboot_after_timeout"; + } + + /** +diff --git a/data/etc/com.android.systemui.xml b/data/etc/com.android.systemui.xml +index f2a33de008d6..354fd82f3a0d 100644 +--- a/data/etc/com.android.systemui.xml ++++ b/data/etc/com.android.systemui.xml +@@ -48,6 +48,7 @@ + + + ++ + + + +diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml +index 5797aa01bfc0..cd3e8b391982 100644 +--- a/packages/SystemUI/AndroidManifest.xml ++++ b/packages/SystemUI/AndroidManifest.xml +@@ -292,6 +292,9 @@ + + + ++ ++ ++ + + + +diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +index 532f071132fc..bb78b6cd6eee 100644 +--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java ++++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +@@ -186,6 +186,8 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, + + private final static String TAG = "KeyguardViewMediator"; + ++ private static final String DELAYED_REBOOT_ACTION = ++ "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_REBOOT"; + private static final String DELAYED_KEYGUARD_ACTION = + "com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KEYGUARD"; + private static final String DELAYED_LOCK_PROFILE_ACTION = +@@ -313,6 +315,11 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, + */ + private int mDelayedProfileShowingSequence; + ++ /** ++ * Same as {@link #mDelayedProfileShowingSequence}, but used for our reboot implementation ++ */ ++ private int mDelayedRebootSequence; ++ + /** + * If the user has disabled the keyguard, then requests to exit, this is + * how we'll ultimately let them know whether it was successful. We use this +@@ -905,6 +912,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, + final IntentFilter delayedActionFilter = new IntentFilter(); + delayedActionFilter.addAction(DELAYED_KEYGUARD_ACTION); + delayedActionFilter.addAction(DELAYED_LOCK_PROFILE_ACTION); ++ delayedActionFilter.addAction(DELAYED_REBOOT_ACTION); + mContext.registerReceiver(mDelayedLockBroadcastReceiver, delayedActionFilter, + SYSTEMUI_PERMISSION, null /* scheduler */); + +@@ -1206,6 +1214,18 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, + } + } + ++ private void doRebootForOwnerAfterTimeoutIfEnabled(long rebootAfterTimeout) { ++ long when = SystemClock.elapsedRealtime() + rebootAfterTimeout; ++ Intent rebootIntent = new Intent(DELAYED_REBOOT_ACTION); ++ rebootIntent.putExtra("seq", mDelayedRebootSequence); ++ rebootIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); ++ PendingIntent sender = PendingIntent.getBroadcast(mContext, ++ 0, rebootIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE); ++ mAlarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, when, sender); ++ if (DEBUG) Log.d(TAG, "setting alarm to reboot device, timeout = " ++ + String.valueOf(rebootAfterTimeout)); ++ } ++ + private void doKeyguardForChildProfilesLocked() { + UserManager um = UserManager.get(mContext); + for (int profileId : um.getEnabledProfileIds(UserHandle.myUserId())) { +@@ -1223,6 +1243,10 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, + mDelayedProfileShowingSequence++; + } + ++ private void cancelDoRebootForOwnerAfterTimeoutIfEnabled() { ++ mDelayedRebootSequence++; ++ } ++ + /** + * Let's us know when the device is waking up. + */ +@@ -1587,6 +1611,10 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, + + if (DEBUG) Log.d(TAG, "doKeyguard: showing the lock screen"); + showLocked(options); ++ final long rebootAfterTimeout = Settings.Global.getLong(mContext.getContentResolver(), Settings.Global.SETTINGS_REBOOT_AFTER_TIMEOUT, 0); ++ if (rebootAfterTimeout >= 1) { ++ doRebootForOwnerAfterTimeoutIfEnabled(rebootAfterTimeout); ++ } + } + + private void lockProfile(int userId) { +@@ -1786,6 +1814,12 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, + } + } + } ++ } else if (DELAYED_REBOOT_ACTION.equals(intent.getAction())) { ++ final int sequence = intent.getIntExtra("seq", 0); ++ if (sequence == mDelayedRebootSequence) { ++ PowerManager pm = mContext.getSystemService(PowerManager.class); ++ pm.reboot(null); ++ } + } + } + }; +@@ -2365,6 +2399,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable, + mHideAnimationRun = false; + adjustStatusBarLocked(); + sendUserPresentBroadcast(); ++ cancelDoRebootForOwnerAfterTimeoutIfEnabled(); + } + + private Configuration.Builder createInteractionJankMonitorConf(String tag) { diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0015-Bluetooth_Timeout.patch b/Patches/LineageOS-19.1/android_frameworks_base/0015-Bluetooth_Timeout.patch new file mode 100644 index 00000000..e89164e3 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0015-Bluetooth_Timeout.patch @@ -0,0 +1,121 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: pratyush +Date: Thu, 1 Jul 2021 12:26:49 +0530 +Subject: [PATCH] Bluetooth auto turn off + +--- + core/java/android/provider/Settings.java | 6 ++ + .../server/BluetoothManagerService.java | 76 +++++++++++++++++++ + 2 files changed, 82 insertions(+) + +diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java +index 52103c3a3f99..580f9745eea7 100644 +--- a/core/java/android/provider/Settings.java ++++ b/core/java/android/provider/Settings.java +@@ -16385,6 +16385,12 @@ public final class Settings { + * @hide + */ + public static final String SETTINGS_REBOOT_AFTER_TIMEOUT = "settings_reboot_after_timeout"; ++ ++ /** ++ * The amount of time in milliseconds before bluetooth is turned off ++ * @hide ++ */ ++ public static final String BLUETOOTH_OFF_TIMEOUT = "bluetooth_off_timeout"; + } + + /** +diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java +index f5ff7a3d71a4..8123494599b6 100644 +--- a/services/core/java/com/android/server/BluetoothManagerService.java ++++ b/services/core/java/com/android/server/BluetoothManagerService.java +@@ -29,6 +29,7 @@ import android.annotation.NonNull; + import android.annotation.RequiresPermission; + import android.annotation.SuppressLint; + import android.app.ActivityManager; ++import android.app.AlarmManager; + import android.app.AppGlobals; + import android.app.AppOpsManager; + import android.app.BroadcastOptions; +@@ -549,6 +550,81 @@ class BluetoothManagerService extends IBluetoothManager.Stub { + Slog.w(TAG, "Unable to resolve SystemUI's UID."); + } + mSystemUiUid = systemUiUid; ++ ++ /* ++ * System sends ACTION_STATE_CHANGED broadcast soon as any state ++ * changes. what it means in action is we don't have to take care if ++ * device reboot while BT has not been turned off automatically. ++ * ++ * A word of warning though it does not check if device as been ++ * unlocked or not what it means in real life is if you have sometime ++ * like tile ble tracker configured it will turn off BT. As result tile ++ * tracking will fail because of auto timeout. this behaviour can be ++ * changed with UserManager.isUnlocked() ++ * */ ++ IntentFilter btFilter = new IntentFilter(); ++ btFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); ++ btFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); ++ btFilter.addAction(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED); ++ context.registerReceiver(new BroadcastReceiver() { ++ @Override ++ public void onReceive(Context broadcastContext, Intent intent) { ++ reconfigureBtTimeoutListener(); ++ } ++ }, btFilter); ++ ++ context.getContentResolver().registerContentObserver( ++ Settings.Global.getUriFor(Settings.Global.BLUETOOTH_OFF_TIMEOUT), ++ false, ++ new ContentObserver(new Handler(context.getMainLooper())) { ++ @Override ++ public void onChange(boolean selfChange) { ++ super.onChange(selfChange); ++ reconfigureBtTimeoutListener(); ++ } ++ }); ++ } ++ ++ private static final AlarmManager.OnAlarmListener listener = () -> { ++ BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); ++ if (isBtOnAndDisconnected() && bluetoothAdapter != null) { ++ bluetoothAdapter.disable(); ++ } ++ }; ++ ++ // If device is still connected cancel timeout for now and wait for disconnected signal ++ private void reconfigureBtTimeoutListener() { ++ AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); ++ if (isTimeoutEnabled(mContext) && isBtOnAndDisconnected()) { ++ final long timeout = SystemClock.elapsedRealtime() + btTimeoutDurationInMilli(mContext); ++ alarmManager.cancel(listener); ++ alarmManager.setExact( ++ AlarmManager.ELAPSED_REALTIME_WAKEUP, ++ timeout, ++ "BT Idle Timeout", ++ listener, ++ new Handler(mContext.getMainLooper()) ++ ); ++ } else { ++ alarmManager.cancel(listener); ++ } ++ } ++ ++ private static boolean isBtOnAndDisconnected() { ++ BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); ++ return bluetoothAdapter != null && bluetoothAdapter.getState() == BluetoothAdapter.STATE_ON ++ && bluetoothAdapter.getState() == BluetoothAdapter.STATE_ON && ++ bluetoothAdapter.getConnectionState() == BluetoothAdapter.STATE_DISCONNECTED; ++ } ++ ++ private static long btTimeoutDurationInMilli(Context context) { ++ return Settings.Global.getLong(context.getContentResolver(), ++ Settings.Global.BLUETOOTH_OFF_TIMEOUT, 0); ++ } ++ ++ /** Zero is default and means disabled */ ++ private static boolean isTimeoutEnabled(Context context) { ++ return 0 != btTimeoutDurationInMilli(context); + } + + /** diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0016-WiFi_Timeout.patch b/Patches/LineageOS-19.1/android_frameworks_base/0016-WiFi_Timeout.patch new file mode 100644 index 00000000..5ec3541c --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0016-WiFi_Timeout.patch @@ -0,0 +1,123 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Pratyush +Date: Tue, 6 Jul 2021 18:18:06 +0530 +Subject: [PATCH] Wi-Fi auto turn off + +--- + core/java/android/provider/Settings.java | 6 ++ + .../server/net/NetworkStatsService.java | 69 +++++++++++++++++++ + 2 files changed, 75 insertions(+) + +diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java +index 580f9745eea7..1d8745501553 100644 +--- a/core/java/android/provider/Settings.java ++++ b/core/java/android/provider/Settings.java +@@ -16379,6 +16379,12 @@ public final class Settings { + */ + public static final String RESTRICTED_NETWORKING_MODE = "restricted_networking_mode"; + ++ /** ++ * The amount of time in milliseconds before Wi-Fi is turned off ++ * @hide ++ */ ++ public static final String WIFI_OFF_TIMEOUT = "wifi_off_timeout"; ++ + /** + * Whether to automatically reboot the device after a user defined timeout + * +diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java +index 097b0711eff7..0a4fca3ec09d 100644 +--- a/services/core/java/com/android/server/net/NetworkStatsService.java ++++ b/services/core/java/com/android/server/net/NetworkStatsService.java +@@ -96,6 +96,7 @@ import android.net.INetworkStatsSession; + import android.net.Network; + import android.net.NetworkCapabilities; + import android.net.NetworkIdentity; ++import android.net.NetworkInfo; + import android.net.NetworkSpecifier; + import android.net.NetworkStack; + import android.net.NetworkStateSnapshot; +@@ -110,8 +111,10 @@ import android.net.Uri; + import android.net.netstats.provider.INetworkStatsProvider; + import android.net.netstats.provider.INetworkStatsProviderCallback; + import android.net.netstats.provider.NetworkStatsProvider; ++import android.net.wifi.WifiManager; + import android.os.BestClock; + import android.os.Binder; ++import android.os.Bundle; + import android.os.DropBoxManager; + import android.os.Environment; + import android.os.Handler; +@@ -449,6 +452,72 @@ public class NetworkStatsService extends INetworkStatsService.Stub { + mContentResolver = mContext.getContentResolver(); + mContentObserver = mDeps.makeContentObserver(mHandler, mSettings, + mNetworkStatsSubscriptionsMonitor); ++ IntentFilter wifiFilter = new IntentFilter(); ++ wifiFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); ++ wifiFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); ++ ++ context.registerReceiver( ++ new BroadcastReceiver() { ++ @Override ++ public void onReceive(Context context, Intent intent) { ++ if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) { ++ Bundle bundle = intent.getExtras(); ++ NetworkInfo networkInfo = bundle.getParcelable(WifiManager.EXTRA_NETWORK_INFO); ++ isWifiConnected = networkInfo != null && networkInfo.isConnected(); ++ } ++ reconfigureWiFiTimeoutListener(); ++ } ++ }, wifiFilter ++ ); ++ ++ context.getContentResolver().registerContentObserver( ++ Global.getUriFor(Global.WIFI_OFF_TIMEOUT), ++ false, ++ new ContentObserver(new Handler(context.getMainLooper())) { ++ @Override ++ public void onChange(boolean selfChange) { ++ super.onChange(selfChange); ++ reconfigureWiFiTimeoutListener(); ++ } ++ }); ++ } ++ ++ private static boolean isWifiConnected = false; ++ private final AlarmManager.OnAlarmListener listener = this::turnOffWifi; ++ ++ private void turnOffWifi() { ++ WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); ++ if (isWifiTimeoutEnabled(mContext) && wifiManager.isWifiEnabled()) { ++ // setWifiEnabled(enabled) is deprecated, though AOSP still uses ++ // it internally and system apps/services are exempted ++ wifiManager.setWifiEnabled(false); ++ } ++ } ++ ++ private void reconfigureWiFiTimeoutListener() { ++ if (isWifiTimeoutEnabled(mContext) && !isWifiConnected) { ++ final long timeout = SystemClock.elapsedRealtime() + wifiTimeoutDurationInMilli(mContext); ++ mAlarmManager.cancel(listener); ++ mAlarmManager.setExact( ++ AlarmManager.ELAPSED_REALTIME_WAKEUP, ++ timeout, ++ "Wi-Fi Idle Timeout", ++ listener, ++ new Handler(mContext.getMainLooper()) ++ ); ++ } else { ++ mAlarmManager.cancel(listener); ++ } ++ } ++ ++ private static long wifiTimeoutDurationInMilli(Context mContext) { ++ return Settings.Global.getLong(mContext.getContentResolver(), ++ Global.WIFI_OFF_TIMEOUT, 0); ++ } ++ ++ /** Zero is default and means disabled */ ++ private static boolean isWifiTimeoutEnabled(Context mContext) { ++ return 0 != wifiTimeoutDurationInMilli(mContext); + } + + /** diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0017-constify_JNINativeMethod.patch b/Patches/LineageOS-19.1/android_frameworks_base/0017-constify_JNINativeMethod.patch new file mode 100644 index 00000000..338e29e4 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0017-constify_JNINativeMethod.patch @@ -0,0 +1,213 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sat, 16 Oct 2021 19:44:59 -0400 +Subject: [PATCH] constify JNINativeMethod tables + +--- + cmds/hid/jni/com_android_commands_hid_Device.cpp | 2 +- + cmds/uinput/jni/com_android_commands_uinput_Device.cpp | 2 +- + core/jni/android_app_ActivityThread.cpp | 2 +- + core/jni/android_os_HidlMemory.cpp | 2 +- + core/jni/android_os_HwBinder.cpp | 2 +- + core/jni/android_os_HwBlob.cpp | 2 +- + core/jni/android_os_HwParcel.cpp | 2 +- + core/jni/android_os_HwRemoteBinder.cpp | 2 +- + libs/hwui/jni/android_graphics_DisplayListCanvas.cpp | 2 +- + media/jni/android_media_ImageWriter.cpp | 4 ++-- + media/jni/android_media_MediaSync.cpp | 2 +- + media/jni/soundpool/android_media_SoundPool.cpp | 2 +- + services/core/jni/com_android_server_UsbMidiDevice.cpp | 2 +- + services/core/jni/com_android_server_tv_TvUinputBridge.cpp | 2 +- + 14 files changed, 15 insertions(+), 15 deletions(-) + +diff --git a/cmds/hid/jni/com_android_commands_hid_Device.cpp b/cmds/hid/jni/com_android_commands_hid_Device.cpp +index 2cda57dd67e9..7613651e75c4 100644 +--- a/cmds/hid/jni/com_android_commands_hid_Device.cpp ++++ b/cmds/hid/jni/com_android_commands_hid_Device.cpp +@@ -354,7 +354,7 @@ static void closeDevice(JNIEnv* /* env */, jclass /* clazz */, jlong ptr) { + } + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"nativeOpenDevice", + "(Ljava/lang/String;IIII[B" + "Lcom/android/commands/hid/Device$DeviceCallback;)J", +diff --git a/cmds/uinput/jni/com_android_commands_uinput_Device.cpp b/cmds/uinput/jni/com_android_commands_uinput_Device.cpp +index 06fa2aac2c7e..4c20055020a4 100644 +--- a/cmds/uinput/jni/com_android_commands_uinput_Device.cpp ++++ b/cmds/uinput/jni/com_android_commands_uinput_Device.cpp +@@ -301,7 +301,7 @@ static void setAbsInfo(JNIEnv* env, jclass /* clazz */, jint handle, jint axisCo + ::ioctl(static_cast(handle), UI_ABS_SETUP, &absSetup); + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"nativeOpenUinputDevice", + "(Ljava/lang/String;IIIII" + "Lcom/android/commands/uinput/Device$DeviceCallback;)J", +diff --git a/core/jni/android_app_ActivityThread.cpp b/core/jni/android_app_ActivityThread.cpp +index e9d9a20c7538..cd285238d6e2 100644 +--- a/core/jni/android_app_ActivityThread.cpp ++++ b/core/jni/android_app_ActivityThread.cpp +@@ -40,7 +40,7 @@ static void android_app_ActivityThread_initZygoteChildHeapProfiling(JNIEnv* env, + android_mallopt(M_INIT_ZYGOTE_CHILD_PROFILING, nullptr, 0); + } + +-static JNINativeMethod gActivityThreadMethods[] = { ++static const JNINativeMethod gActivityThreadMethods[] = { + // ------------ Regular JNI ------------------ + { "nPurgePendingResources", "()V", + (void*) android_app_ActivityThread_purgePendingResources }, +diff --git a/core/jni/android_os_HidlMemory.cpp b/core/jni/android_os_HidlMemory.cpp +index 69e48184c0ad..612fc95776a5 100644 +--- a/core/jni/android_os_HidlMemory.cpp ++++ b/core/jni/android_os_HidlMemory.cpp +@@ -50,7 +50,7 @@ static void nativeFinalize(JNIEnv* env, jobject jobj) { + delete native; + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + {"nativeFinalize", "()V", (void*) nativeFinalize}, + }; + +diff --git a/core/jni/android_os_HwBinder.cpp b/core/jni/android_os_HwBinder.cpp +index 781895eeeaba..cbec79144826 100644 +--- a/core/jni/android_os_HwBinder.cpp ++++ b/core/jni/android_os_HwBinder.cpp +@@ -352,7 +352,7 @@ static void JHwBinder_report_sysprop_change(JNIEnv * /*env*/, jclass /*clazz*/) + report_sysprop_change(); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + { "native_init", "()J", (void *)JHwBinder_native_init }, + { "native_setup", "()V", (void *)JHwBinder_native_setup }, + +diff --git a/core/jni/android_os_HwBlob.cpp b/core/jni/android_os_HwBlob.cpp +index a9db91be1d5b..ba4cf6101449 100644 +--- a/core/jni/android_os_HwBlob.cpp ++++ b/core/jni/android_os_HwBlob.cpp +@@ -599,7 +599,7 @@ static jlong JHwBlob_native_handle(JNIEnv *env, jobject thiz) { + return handle; + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + { "native_init", "()J", (void *)JHwBlob_native_init }, + { "native_setup", "(I)V", (void *)JHwBlob_native_setup }, + +diff --git a/core/jni/android_os_HwParcel.cpp b/core/jni/android_os_HwParcel.cpp +index 4c4443fc29c3..78fd6d90691b 100644 +--- a/core/jni/android_os_HwParcel.cpp ++++ b/core/jni/android_os_HwParcel.cpp +@@ -1068,7 +1068,7 @@ static void JHwParcel_native_writeBuffer( + } + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + { "native_init", "()J", (void *)JHwParcel_native_init }, + { "native_setup", "(Z)V", (void *)JHwParcel_native_setup }, + +diff --git a/core/jni/android_os_HwRemoteBinder.cpp b/core/jni/android_os_HwRemoteBinder.cpp +index 3af55fe810fc..feabd6a60fbf 100644 +--- a/core/jni/android_os_HwRemoteBinder.cpp ++++ b/core/jni/android_os_HwRemoteBinder.cpp +@@ -442,7 +442,7 @@ static jint JHwRemoteBinder_hashCode(JNIEnv* env, jobject thiz) { + return static_cast(longHash ^ (longHash >> 32)); // See Long.hashCode() + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + { "native_init", "()J", (void *)JHwRemoteBinder_native_init }, + + { "native_setup_empty", "()V", +diff --git a/libs/hwui/jni/android_graphics_DisplayListCanvas.cpp b/libs/hwui/jni/android_graphics_DisplayListCanvas.cpp +index f060bb32031a..3ebb3553ce20 100644 +--- a/libs/hwui/jni/android_graphics_DisplayListCanvas.cpp ++++ b/libs/hwui/jni/android_graphics_DisplayListCanvas.cpp +@@ -174,7 +174,7 @@ static void android_view_DisplayListCanvas_drawWebViewFunctor(CRITICAL_JNI_PARAM + + const char* const kClassPathName = "android/graphics/RecordingCanvas"; + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + // ------------ @CriticalNative -------------- + {"nCreateDisplayListCanvas", "(JII)J", + (void*)android_view_DisplayListCanvas_createDisplayListCanvas}, +diff --git a/media/jni/android_media_ImageWriter.cpp b/media/jni/android_media_ImageWriter.cpp +index b291ac95bf4f..1ee25c4f6421 100644 +--- a/media/jni/android_media_ImageWriter.cpp ++++ b/media/jni/android_media_ImageWriter.cpp +@@ -1061,7 +1061,7 @@ static jobjectArray Image_createSurfacePlanes(JNIEnv* env, jobject thiz, + + // ---------------------------------------------------------------------------- + +-static JNINativeMethod gImageWriterMethods[] = { ++static const JNINativeMethod gImageWriterMethods[] = { + {"nativeClassInit", "()V", (void*)ImageWriter_classInit }, + {"nativeInit", "(Ljava/lang/Object;Landroid/view/Surface;IIII)J", + (void*)ImageWriter_init }, +@@ -1075,7 +1075,7 @@ static JNINativeMethod gImageWriterMethods[] = { + {"cancelImage", "(JLandroid/media/Image;)V", (void*)ImageWriter_cancelImage }, + }; + +-static JNINativeMethod gImageMethods[] = { ++static const JNINativeMethod gImageMethods[] = { + {"nativeCreatePlanes", "(II)[Landroid/media/ImageWriter$WriterSurfaceImage$SurfacePlane;", + (void*)Image_createSurfacePlanes }, + {"nativeGetWidth", "()I", (void*)Image_getWidth }, +diff --git a/media/jni/android_media_MediaSync.cpp b/media/jni/android_media_MediaSync.cpp +index d1ce30a3e827..d93bda166c44 100644 +--- a/media/jni/android_media_MediaSync.cpp ++++ b/media/jni/android_media_MediaSync.cpp +@@ -514,7 +514,7 @@ static void android_media_MediaSync_native_finalize(JNIEnv *env, jobject thiz) { + android_media_MediaSync_release(env, thiz); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + { "native_setSurface", + "(Landroid/view/Surface;)V", + (void *)android_media_MediaSync_native_setSurface }, +diff --git a/media/jni/soundpool/android_media_SoundPool.cpp b/media/jni/soundpool/android_media_SoundPool.cpp +index a66d99fbd9f4..1665421aacd4 100644 +--- a/media/jni/soundpool/android_media_SoundPool.cpp ++++ b/media/jni/soundpool/android_media_SoundPool.cpp +@@ -247,7 +247,7 @@ android_media_SoundPool_release(JNIEnv *env, jobject thiz) + // ---------------------------------------------------------------------------- + + // Dalvik VM type signatures +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + { "_load", + "(Ljava/io/FileDescriptor;JJI)I", + (void *)android_media_SoundPool_load_FD +diff --git a/services/core/jni/com_android_server_UsbMidiDevice.cpp b/services/core/jni/com_android_server_UsbMidiDevice.cpp +index d6b5bed173eb..564f71daedac 100644 +--- a/services/core/jni/com_android_server_UsbMidiDevice.cpp ++++ b/services/core/jni/com_android_server_UsbMidiDevice.cpp +@@ -157,7 +157,7 @@ android_server_UsbMidiDevice_close(JNIEnv *env, jobject thiz, jobjectArray fds) + } + } + +-static JNINativeMethod method_table[] = { ++static const JNINativeMethod method_table[] = { + { "nativeGetSubdeviceCount", "(II)I", (void*)android_server_UsbMidiDevice_get_subdevice_count }, + { "nativeOpen", "(III)[Ljava/io/FileDescriptor;", (void*)android_server_UsbMidiDevice_open }, + { "nativeClose", "([Ljava/io/FileDescriptor;)V", (void*)android_server_UsbMidiDevice_close }, +diff --git a/services/core/jni/com_android_server_tv_TvUinputBridge.cpp b/services/core/jni/com_android_server_tv_TvUinputBridge.cpp +index 99deab4fd652..2cb1aaef13fa 100644 +--- a/services/core/jni/com_android_server_tv_TvUinputBridge.cpp ++++ b/services/core/jni/com_android_server_tv_TvUinputBridge.cpp +@@ -534,7 +534,7 @@ static void nativeClear(JNIEnv* env, jclass clazz, jlong ptr) { + * JNI registration + */ + +-static JNINativeMethod gUinputBridgeMethods[] = { ++static const JNINativeMethod gUinputBridgeMethods[] = { + {"nativeOpen", "(Ljava/lang/String;Ljava/lang/String;III)J", (void*)nativeOpen}, + {"nativeGamepadOpen", "(Ljava/lang/String;Ljava/lang/String;)J", (void*)nativeGamepadOpen}, + {"nativeClose", "(J)V", (void*)nativeClose}, diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-1.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-1.patch new file mode 100644 index 00000000..9bb48185 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-1.patch @@ -0,0 +1,181 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sat, 14 Mar 2015 18:10:20 -0400 +Subject: [PATCH] add exec-based spawning support + +--- + .../com/android/internal/os/ExecInit.java | 115 ++++++++++++++++++ + .../com/android/internal/os/WrapperInit.java | 2 +- + .../android/internal/os/ZygoteConnection.java | 10 +- + 3 files changed, 125 insertions(+), 2 deletions(-) + create mode 100644 core/java/com/android/internal/os/ExecInit.java + +diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java +new file mode 100644 +index 000000000000..2adcab7fdbe6 +--- /dev/null ++++ b/core/java/com/android/internal/os/ExecInit.java +@@ -0,0 +1,115 @@ ++package com.android.internal.os; ++ ++import android.os.Trace; ++import android.system.ErrnoException; ++import android.system.Os; ++import android.util.Slog; ++import android.util.TimingsTraceLog; ++import dalvik.system.VMRuntime; ++ ++/** ++ * Startup class for the process. ++ * @hide ++ */ ++public class ExecInit { ++ /** ++ * Class not instantiable. ++ */ ++ private ExecInit() { ++ } ++ ++ /** ++ * The main function called when starting a runtime application. ++ * ++ * The first argument is the target SDK version for the app. ++ * ++ * The remaining arguments are passed to the runtime. ++ * ++ * @param args The command-line arguments. ++ */ ++ public static void main(String[] args) { ++ // Parse our mandatory argument. ++ int targetSdkVersion = Integer.parseInt(args[0], 10); ++ ++ // Mimic system Zygote preloading. ++ ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming", ++ Trace.TRACE_TAG_DALVIK)); ++ ++ // Launch the application. ++ String[] runtimeArgs = new String[args.length - 1]; ++ System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length); ++ Runnable r = execInit(targetSdkVersion, runtimeArgs); ++ ++ r.run(); ++ } ++ ++ /** ++ * Executes a runtime application with exec-based spawning. ++ * This method never returns. ++ * ++ * @param niceName The nice name for the application, or null if none. ++ * @param targetSdkVersion The target SDK version for the app. ++ * @param args Arguments for {@link RuntimeInit#main}. ++ */ ++ public static void execApplication(String niceName, int targetSdkVersion, ++ String instructionSet, String[] args) { ++ int niceArgs = niceName == null ? 0 : 1; ++ int baseArgs = 5 + niceArgs; ++ String[] argv = new String[baseArgs + args.length]; ++ if (VMRuntime.is64BitInstructionSet(instructionSet)) { ++ argv[0] = "/system/bin/app_process64"; ++ } else { ++ argv[0] = "/system/bin/app_process32"; ++ } ++ argv[1] = "/system/bin"; ++ argv[2] = "--application"; ++ if (niceName != null) { ++ argv[3] = "--nice-name=" + niceName; ++ } ++ argv[3 + niceArgs] = "com.android.internal.os.ExecInit"; ++ argv[4 + niceArgs] = Integer.toString(targetSdkVersion); ++ System.arraycopy(args, 0, argv, baseArgs, args.length); ++ ++ WrapperInit.preserveCapabilities(); ++ try { ++ Os.execv(argv[0], argv); ++ } catch (ErrnoException e) { ++ throw new RuntimeException(e); ++ } ++ } ++ ++ /** ++ * The main function called when an application is started with exec-based spawning. ++ * ++ * When the app starts, the runtime starts {@link RuntimeInit#main} ++ * which calls {@link main} which then calls this method. ++ * So we don't need to call commonInit() here. ++ * ++ * @param targetSdkVersion target SDK version ++ * @param argv arg strings ++ */ ++ private static Runnable execInit(int targetSdkVersion, String[] argv) { ++ if (RuntimeInit.DEBUG) { ++ Slog.d(RuntimeInit.TAG, "RuntimeInit: Starting application from exec"); ++ } ++ ++ // Check whether the first argument is a "-cp" in argv, and assume the next argument is the ++ // classpath. If found, create a PathClassLoader and use it for applicationInit. ++ ClassLoader classLoader = null; ++ if (argv != null && argv.length > 2 && argv[0].equals("-cp")) { ++ classLoader = ZygoteInit.createPathClassLoader(argv[1], targetSdkVersion); ++ ++ // Install this classloader as the context classloader, too. ++ Thread.currentThread().setContextClassLoader(classLoader); ++ ++ // Remove the classpath from the arguments. ++ String removedArgs[] = new String[argv.length - 2]; ++ System.arraycopy(argv, 2, removedArgs, 0, argv.length - 2); ++ argv = removedArgs; ++ } ++ ++ // Perform the same initialization that would happen after the Zygote forks. ++ Zygote.nativePreApplicationInit(); ++ return RuntimeInit.applicationInit(targetSdkVersion, /*disabledCompatChanges*/ null, argv, classLoader); ++ } ++} +diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java +index 6860759eea8a..a2eef62f80be 100644 +--- a/core/java/com/android/internal/os/WrapperInit.java ++++ b/core/java/com/android/internal/os/WrapperInit.java +@@ -186,7 +186,7 @@ public class WrapperInit { + * This is acceptable here as failure will leave the wrapped app with strictly less + * capabilities, which may make it crash, but not exceed its allowances. + */ +- private static void preserveCapabilities() { ++ public static void preserveCapabilities() { + StructCapUserHeader header = new StructCapUserHeader( + OsConstants._LINUX_CAPABILITY_VERSION_3, 0); + StructCapUserData[] data; +diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java +index 993e4e7b4b3d..756547706f60 100644 +--- a/core/java/com/android/internal/os/ZygoteConnection.java ++++ b/core/java/com/android/internal/os/ZygoteConnection.java +@@ -29,6 +29,7 @@ import android.net.Credentials; + import android.net.LocalSocket; + import android.os.Parcel; + import android.os.Process; ++import android.os.SystemProperties; + import android.os.Trace; + import android.system.ErrnoException; + import android.system.Os; +@@ -247,7 +248,7 @@ class ZygoteConnection { + fdsToClose[1] = zygoteFd.getInt$(); + } + +- if (parsedArgs.mInvokeWith != null || parsedArgs.mStartChildZygote ++ if (parsedArgs.mInvokeWith != null || SystemProperties.getBoolean("sys.spawn.exec", true) || parsedArgs.mStartChildZygote + || !multipleOK || peer.getUid() != Process.SYSTEM_UID) { + // Continue using old code for now. TODO: Handle these cases in the other path. + pid = Zygote.forkAndSpecialize(parsedArgs.mUid, parsedArgs.mGid, +@@ -535,6 +536,13 @@ class ZygoteConnection { + throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned"); + } else { + if (!isZygote) { ++ if (SystemProperties.getBoolean("sys.spawn.exec", true)) { ++ ExecInit.execApplication(parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion, ++ VMRuntime.getCurrentInstructionSet(), parsedArgs.mRemainingArgs); ++ ++ // Should not get here. ++ throw new IllegalStateException("ExecInit.execApplication unexpectedly returned"); ++ } + return ZygoteInit.zygoteInit(parsedArgs.mTargetSdkVersion, + parsedArgs.mDisabledCompatChanges, + parsedArgs.mRemainingArgs, null /* classLoader */); diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-10.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-10.patch new file mode 100644 index 00000000..49c8dd34 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-10.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 11 Sep 2019 06:57:24 -0400 +Subject: [PATCH] disable preloading classloaders for exec spawning + +--- + core/java/com/android/internal/os/ZygoteInit.java | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java +index 851e5e1fb5b1..231b42ba64b9 100644 +--- a/core/java/com/android/internal/os/ZygoteInit.java ++++ b/core/java/com/android/internal/os/ZygoteInit.java +@@ -143,9 +143,11 @@ public class ZygoteInit { + preloadClasses(); + bootTimingsTraceLog.traceEnd(); // PreloadClasses + } +- bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders"); +- cacheNonBootClasspathClassLoaders(); +- bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders ++ if (fullPreload) { ++ bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders"); ++ cacheNonBootClasspathClassLoaders(); ++ bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders ++ } + if (fullPreload) { + bootTimingsTraceLog.traceBegin("PreloadResources"); + preloadResources(); diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-11.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-11.patch new file mode 100644 index 00000000..1ce4eba3 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-11.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 11 Sep 2019 06:58:51 -0400 +Subject: [PATCH] disable preloading HALs for exec spawning + +--- + core/java/com/android/internal/os/ZygoteInit.java | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java +index 231b42ba64b9..1696d2135180 100644 +--- a/core/java/com/android/internal/os/ZygoteInit.java ++++ b/core/java/com/android/internal/os/ZygoteInit.java +@@ -153,9 +153,11 @@ public class ZygoteInit { + preloadResources(); + bootTimingsTraceLog.traceEnd(); // PreloadResources + } +- Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs"); +- nativePreloadAppProcessHALs(); +- Trace.traceEnd(Trace.TRACE_TAG_DALVIK); ++ if (fullPreload) { ++ Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs"); ++ nativePreloadAppProcessHALs(); ++ Trace.traceEnd(Trace.TRACE_TAG_DALVIK); ++ } + Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver"); + maybePreloadGraphicsDriver(); + Trace.traceEnd(Trace.TRACE_TAG_DALVIK); diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-12.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-12.patch new file mode 100644 index 00000000..f67220e5 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-12.patch @@ -0,0 +1,253 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: anupritaisno1 +Date: Fri, 30 Oct 2020 22:26:09 +0000 +Subject: [PATCH] pass through runtime flags for exec spawning and implement + them in the child + +Signed-off-by: anupritaisno1 +--- + .../com/android/internal/os/ExecInit.java | 14 +- + core/java/com/android/internal/os/Zygote.java | 9 ++ + .../android/internal/os/ZygoteConnection.java | 2 +- + core/jni/com_android_internal_os_Zygote.cpp | 129 ++++++++++-------- + 4 files changed, 89 insertions(+), 65 deletions(-) + +diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java +index 830e5b562a91..749c67abf389 100644 +--- a/core/java/com/android/internal/os/ExecInit.java ++++ b/core/java/com/android/internal/os/ExecInit.java +@@ -31,15 +31,20 @@ public class ExecInit { + // Parse our mandatory argument. + int targetSdkVersion = Integer.parseInt(args[0], 10); + ++ // Parse the runtime_flags. ++ int runtimeFlags = Integer.parseInt(args[1], 10); ++ + // Mimic system Zygote preloading. + ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming", + Trace.TRACE_TAG_DALVIK), false); + + // Launch the application. +- String[] runtimeArgs = new String[args.length - 1]; +- System.arraycopy(args, 1, runtimeArgs, 0, runtimeArgs.length); ++ String[] runtimeArgs = new String[args.length - 2]; ++ System.arraycopy(args, 2, runtimeArgs, 0, runtimeArgs.length); + Runnable r = execInit(targetSdkVersion, runtimeArgs); + ++ Zygote.nativeHandleRuntimeFlags(runtimeFlags); ++ + r.run(); + } + +@@ -52,9 +57,9 @@ public class ExecInit { + * @param args Arguments for {@link RuntimeInit#main}. + */ + public static void execApplication(String niceName, int targetSdkVersion, +- String instructionSet, String[] args) { ++ String instructionSet, int runtimeFlags, String[] args) { + int niceArgs = niceName == null ? 0 : 1; +- int baseArgs = 5 + niceArgs; ++ int baseArgs = 6 + niceArgs; + String[] argv = new String[baseArgs + args.length]; + if (VMRuntime.is64BitInstructionSet(instructionSet)) { + argv[0] = "/system/bin/app_process64"; +@@ -68,6 +73,7 @@ public class ExecInit { + } + argv[3 + niceArgs] = "com.android.internal.os.ExecInit"; + argv[4 + niceArgs] = Integer.toString(targetSdkVersion); ++ argv[5 + niceArgs] = Integer.toString(runtimeFlags); + System.arraycopy(args, 0, argv, baseArgs, args.length); + + WrapperInit.preserveCapabilities(); +diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java +index 6d4b8c5ea1ad..1f0ac0bd6520 100644 +--- a/core/java/com/android/internal/os/Zygote.java ++++ b/core/java/com/android/internal/os/Zygote.java +@@ -1170,4 +1170,13 @@ public final class Zygote { + * we failed to determine the level. + */ + public static native int nativeCurrentTaggingLevel(); ++ ++ /** ++ * Used on GrapheneOS to set up runtime flags ++ * ++ * @param runtimeFlags flags to be passed to the native method ++ * ++ * @hide ++ */ ++ public static native void nativeHandleRuntimeFlags(int runtimeFlags); + } +diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java +index 27518dd4cdce..a8d9400c7992 100644 +--- a/core/java/com/android/internal/os/ZygoteConnection.java ++++ b/core/java/com/android/internal/os/ZygoteConnection.java +@@ -539,7 +539,7 @@ class ZygoteConnection { + if (SystemProperties.getBoolean("sys.spawn.exec", true) && + (parsedArgs.mRuntimeFlags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) { + ExecInit.execApplication(parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion, +- VMRuntime.getCurrentInstructionSet(), parsedArgs.mRemainingArgs); ++ VMRuntime.getCurrentInstructionSet(), parsedArgs.mRuntimeFlags, parsedArgs.mRemainingArgs); + + // Should not get here. + throw new IllegalStateException("ExecInit.execApplication unexpectedly returned"); +diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp +index bed0aae074a4..69f615a8e0f4 100644 +--- a/core/jni/com_android_internal_os_Zygote.cpp ++++ b/core/jni/com_android_internal_os_Zygote.cpp +@@ -1552,6 +1552,69 @@ static void BindMountStorageDirs(JNIEnv* env, jobjectArray pkg_data_info_list, + } + } + ++static void HandleRuntimeFlags(JNIEnv* env, jint& runtime_flags) { ++ // Set process properties to enable debugging if required. ++ if ((runtime_flags & RuntimeFlags::DEBUG_ENABLE_JDWP) != 0) { ++ EnableDebugger(); ++ } ++ if ((runtime_flags & RuntimeFlags::PROFILE_FROM_SHELL) != 0) { ++ // simpleperf needs the process to be dumpable to profile it. ++ if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) { ++ ALOGE("prctl(PR_SET_DUMPABLE) failed: %s", strerror(errno)); ++ RuntimeAbort(env, __LINE__, "prctl(PR_SET_DUMPABLE, 1) failed"); ++ } ++ } ++ ++ HeapTaggingLevel heap_tagging_level; ++ switch (runtime_flags & RuntimeFlags::MEMORY_TAG_LEVEL_MASK) { ++ case RuntimeFlags::MEMORY_TAG_LEVEL_TBI: ++ heap_tagging_level = M_HEAP_TAGGING_LEVEL_TBI; ++ break; ++ case RuntimeFlags::MEMORY_TAG_LEVEL_ASYNC: ++ heap_tagging_level = M_HEAP_TAGGING_LEVEL_ASYNC; ++ break; ++ case RuntimeFlags::MEMORY_TAG_LEVEL_SYNC: ++ heap_tagging_level = M_HEAP_TAGGING_LEVEL_SYNC; ++ break; ++ default: ++ heap_tagging_level = M_HEAP_TAGGING_LEVEL_NONE; ++ break; ++ } ++ mallopt(M_BIONIC_SET_HEAP_TAGGING_LEVEL, heap_tagging_level); ++ ++ // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART ++ // runtime. ++ runtime_flags &= ~RuntimeFlags::MEMORY_TAG_LEVEL_MASK; ++ ++ // Avoid heap zero initialization for applications without MTE. Zero init may ++ // cause app compat problems, use more memory, or reduce performance. While it ++ // would be nice to have them for apps, we will have to wait until they are ++ // proven out, have more efficient hardware, and/or apply them only to new ++ // applications. ++ if (!(runtime_flags & RuntimeFlags::NATIVE_HEAP_ZERO_INIT)) { ++ mallopt(M_BIONIC_ZERO_INIT, 0); ++ } ++ ++ // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART ++ // runtime. ++ runtime_flags &= ~RuntimeFlags::NATIVE_HEAP_ZERO_INIT; ++ ++ bool forceEnableGwpAsan = false; ++ switch (runtime_flags & RuntimeFlags::GWP_ASAN_LEVEL_MASK) { ++ default: ++ case RuntimeFlags::GWP_ASAN_LEVEL_NEVER: ++ break; ++ case RuntimeFlags::GWP_ASAN_LEVEL_ALWAYS: ++ forceEnableGwpAsan = true; ++ [[fallthrough]]; ++ case RuntimeFlags::GWP_ASAN_LEVEL_LOTTERY: ++ android_mallopt(M_INITIALIZE_GWP_ASAN, &forceEnableGwpAsan, sizeof(forceEnableGwpAsan)); ++ } ++ // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART ++ // runtime. ++ runtime_flags &= ~RuntimeFlags::GWP_ASAN_LEVEL_MASK; ++} ++ + // Utility routine to specialize a zygote child process. + static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, jint runtime_flags, + jobjectArray rlimits, jlong permitted_capabilities, +@@ -1679,66 +1742,7 @@ static void SpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArray gids, + } + } + +- // Set process properties to enable debugging if required. +- if ((runtime_flags & RuntimeFlags::DEBUG_ENABLE_JDWP) != 0) { +- EnableDebugger(); +- } +- if ((runtime_flags & RuntimeFlags::PROFILE_FROM_SHELL) != 0) { +- // simpleperf needs the process to be dumpable to profile it. +- if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) { +- ALOGE("prctl(PR_SET_DUMPABLE) failed: %s", strerror(errno)); +- RuntimeAbort(env, __LINE__, "prctl(PR_SET_DUMPABLE, 1) failed"); +- } +- } +- +- HeapTaggingLevel heap_tagging_level; +- switch (runtime_flags & RuntimeFlags::MEMORY_TAG_LEVEL_MASK) { +- case RuntimeFlags::MEMORY_TAG_LEVEL_TBI: +- heap_tagging_level = M_HEAP_TAGGING_LEVEL_TBI; +- break; +- case RuntimeFlags::MEMORY_TAG_LEVEL_ASYNC: +- heap_tagging_level = M_HEAP_TAGGING_LEVEL_ASYNC; +- break; +- case RuntimeFlags::MEMORY_TAG_LEVEL_SYNC: +- heap_tagging_level = M_HEAP_TAGGING_LEVEL_SYNC; +- break; +- default: +- heap_tagging_level = M_HEAP_TAGGING_LEVEL_NONE; +- break; +- } +- mallopt(M_BIONIC_SET_HEAP_TAGGING_LEVEL, heap_tagging_level); +- +- // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART +- // runtime. +- runtime_flags &= ~RuntimeFlags::MEMORY_TAG_LEVEL_MASK; +- +- // Avoid heap zero initialization for applications without MTE. Zero init may +- // cause app compat problems, use more memory, or reduce performance. While it +- // would be nice to have them for apps, we will have to wait until they are +- // proven out, have more efficient hardware, and/or apply them only to new +- // applications. +- if (!(runtime_flags & RuntimeFlags::NATIVE_HEAP_ZERO_INIT)) { +- mallopt(M_BIONIC_ZERO_INIT, 0); +- } +- +- // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART +- // runtime. +- runtime_flags &= ~RuntimeFlags::NATIVE_HEAP_ZERO_INIT; +- +- bool forceEnableGwpAsan = false; +- switch (runtime_flags & RuntimeFlags::GWP_ASAN_LEVEL_MASK) { +- default: +- case RuntimeFlags::GWP_ASAN_LEVEL_NEVER: +- break; +- case RuntimeFlags::GWP_ASAN_LEVEL_ALWAYS: +- forceEnableGwpAsan = true; +- [[fallthrough]]; +- case RuntimeFlags::GWP_ASAN_LEVEL_LOTTERY: +- android_mallopt(M_INITIALIZE_GWP_ASAN, &forceEnableGwpAsan, sizeof(forceEnableGwpAsan)); +- } +- // Now that we've used the flag, clear it so that we don't pass unknown flags to the ART +- // runtime. +- runtime_flags &= ~RuntimeFlags::GWP_ASAN_LEVEL_MASK; ++ HandleRuntimeFlags(env, runtime_flags); + + if (NeedsNoRandomizeWorkaround()) { + // Work around ARM kernel ASLR lossage (http://b/5817320). +@@ -2642,6 +2646,10 @@ static void com_android_internal_os_Zygote_nativeAllowFilesOpenedByPreload(JNIEn + gPreloadFdsExtracted = true; + } + ++static void nativeHandleRuntimeFlagsWrapper(JNIEnv* env, jclass, jint runtime_flags) { ++ HandleRuntimeFlags(env, runtime_flags); ++} ++ + static const JNINativeMethod gMethods[] = { + {"nativeForkAndSpecialize", + "(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/" +@@ -2694,6 +2702,7 @@ static const JNINativeMethod gMethods[] = { + (void*)com_android_internal_os_Zygote_nativeMarkOpenedFilesBeforePreload}, + {"nativeAllowFilesOpenedByPreload", "()V", + (void*)com_android_internal_os_Zygote_nativeAllowFilesOpenedByPreload}, ++ {"nativeHandleRuntimeFlags", "(I)V", (void*)nativeHandleRuntimeFlagsWrapper}, + }; + + int register_com_android_internal_os_Zygote(JNIEnv* env) { diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-2.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-2.patch new file mode 100644 index 00000000..fc5a016e --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-2.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Tue, 21 May 2019 23:54:20 -0400 +Subject: [PATCH] disable exec spawning when using debugging options + +The debugging options are not yet supported probably, so disable exec +spawning when doing debugging. +--- + core/java/com/android/internal/os/ZygoteConnection.java | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java +index 756547706f60..27518dd4cdce 100644 +--- a/core/java/com/android/internal/os/ZygoteConnection.java ++++ b/core/java/com/android/internal/os/ZygoteConnection.java +@@ -536,7 +536,8 @@ class ZygoteConnection { + throw new IllegalStateException("WrapperInit.execApplication unexpectedly returned"); + } else { + if (!isZygote) { +- if (SystemProperties.getBoolean("sys.spawn.exec", true)) { ++ if (SystemProperties.getBoolean("sys.spawn.exec", true) && ++ (parsedArgs.mRuntimeFlags & ApplicationInfo.FLAG_DEBUGGABLE) == 0) { + ExecInit.execApplication(parsedArgs.mNiceName, parsedArgs.mTargetSdkVersion, + VMRuntime.getCurrentInstructionSet(), parsedArgs.mRemainingArgs); + diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-3.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-3.patch new file mode 100644 index 00000000..a441b3d1 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-3.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Tue, 14 May 2019 14:24:21 -0400 +Subject: [PATCH] add parameter for avoiding full preload with exec + +--- + core/java/com/android/internal/os/ExecInit.java | 2 +- + core/java/com/android/internal/os/ZygoteInit.java | 6 +++++- + 2 files changed, 6 insertions(+), 2 deletions(-) + +diff --git a/core/java/com/android/internal/os/ExecInit.java b/core/java/com/android/internal/os/ExecInit.java +index 2adcab7fdbe6..830e5b562a91 100644 +--- a/core/java/com/android/internal/os/ExecInit.java ++++ b/core/java/com/android/internal/os/ExecInit.java +@@ -33,7 +33,7 @@ public class ExecInit { + + // Mimic system Zygote preloading. + ZygoteInit.preload(new TimingsTraceLog("ExecInitTiming", +- Trace.TRACE_TAG_DALVIK)); ++ Trace.TRACE_TAG_DALVIK), false); + + // Launch the application. + String[] runtimeArgs = new String[args.length - 1]; +diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java +index 89b33590ab35..fefff67a66eb 100644 +--- a/core/java/com/android/internal/os/ZygoteInit.java ++++ b/core/java/com/android/internal/os/ZygoteInit.java +@@ -133,7 +133,7 @@ public class ZygoteInit { + */ + private static ClassLoader sCachedSystemServerClassLoader = null; + +- static void preload(TimingsTraceLog bootTimingsTraceLog) { ++ static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) { + Log.d(TAG, "begin preload"); + bootTimingsTraceLog.traceBegin("BeginPreload"); + beginPreload(); +@@ -165,6 +165,10 @@ public class ZygoteInit { + sPreloadComplete = true; + } + ++ static void preload(TimingsTraceLog bootTimingsTraceLog) { ++ preload(bootTimingsTraceLog, true); ++ } ++ + static void lazyPreload() { + Preconditions.checkState(!sPreloadComplete); + Log.i(TAG, "Lazily preloading resources."); diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-4.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-4.patch new file mode 100644 index 00000000..4348a674 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-4.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 11 Sep 2019 06:43:55 -0400 +Subject: [PATCH] pass through fullPreload to libcore + +--- + core/java/com/android/internal/os/ZygoteInit.java | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java +index fefff67a66eb..b07173d50b9d 100644 +--- a/core/java/com/android/internal/os/ZygoteInit.java ++++ b/core/java/com/android/internal/os/ZygoteInit.java +@@ -136,7 +136,7 @@ public class ZygoteInit { + static void preload(TimingsTraceLog bootTimingsTraceLog, boolean fullPreload) { + Log.d(TAG, "begin preload"); + bootTimingsTraceLog.traceBegin("BeginPreload"); +- beginPreload(); ++ beginPreload(fullPreload); + bootTimingsTraceLog.traceEnd(); // BeginPreload + bootTimingsTraceLog.traceBegin("PreloadClasses"); + preloadClasses(); +@@ -158,7 +158,7 @@ public class ZygoteInit { + // Ask the WebViewFactory to do any initialization that must run in the zygote process, + // for memory sharing purposes. + WebViewFactory.prepareWebViewInZygote(); +- endPreload(); ++ endPreload(fullPreload); + warmUpJcaProviders(); + Log.d(TAG, "end preload"); + +@@ -176,14 +176,14 @@ public class ZygoteInit { + preload(new TimingsTraceLog("ZygoteInitTiming_lazy", Trace.TRACE_TAG_DALVIK)); + } + +- private static void beginPreload() { ++ private static void beginPreload(boolean fullPreload) { + Log.i(TAG, "Calling ZygoteHooks.beginPreload()"); + +- ZygoteHooks.onBeginPreload(); ++ ZygoteHooks.onBeginPreload(fullPreload); + } + +- private static void endPreload() { +- ZygoteHooks.onEndPreload(); ++ private static void endPreload(boolean fullPreload) { ++ ZygoteHooks.onEndPreload(fullPreload); + + Log.i(TAG, "Called ZygoteHooks.endPreload()"); + } diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-5.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-5.patch new file mode 100644 index 00000000..fe726496 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-5.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Tue, 14 May 2019 14:28:27 -0400 +Subject: [PATCH] disable OpenGL preloading for exec spawning + +--- + core/java/com/android/internal/os/ZygoteInit.java | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java +index b07173d50b9d..d1f7ca14501e 100644 +--- a/core/java/com/android/internal/os/ZygoteInit.java ++++ b/core/java/com/android/internal/os/ZygoteInit.java +@@ -150,9 +150,11 @@ public class ZygoteInit { + Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs"); + nativePreloadAppProcessHALs(); + Trace.traceEnd(Trace.TRACE_TAG_DALVIK); +- Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver"); +- maybePreloadGraphicsDriver(); +- Trace.traceEnd(Trace.TRACE_TAG_DALVIK); ++ if (fullPreload) { ++ Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadGraphicsDriver"); ++ maybePreloadGraphicsDriver(); ++ Trace.traceEnd(Trace.TRACE_TAG_DALVIK); ++ } + preloadSharedLibraries(); + preloadTextResources(); + // Ask the WebViewFactory to do any initialization that must run in the zygote process, diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-6.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-6.patch new file mode 100644 index 00000000..78b2df3e --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-6.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Tue, 14 May 2019 14:28:52 -0400 +Subject: [PATCH] disable resource preloading for exec spawning + +--- + core/java/com/android/internal/os/ZygoteInit.java | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java +index b07173d50b9d..dbb1fb83f62d 100644 +--- a/core/java/com/android/internal/os/ZygoteInit.java ++++ b/core/java/com/android/internal/os/ZygoteInit.java +@@ -144,9 +144,11 @@ public class ZygoteInit { + bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders"); + cacheNonBootClasspathClassLoaders(); + bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders +- bootTimingsTraceLog.traceBegin("PreloadResources"); +- preloadResources(); +- bootTimingsTraceLog.traceEnd(); // PreloadResources ++ if (fullPreload) { ++ bootTimingsTraceLog.traceBegin("PreloadResources"); ++ preloadResources(); ++ bootTimingsTraceLog.traceEnd(); // PreloadResources ++ } + Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadAppProcessHALs"); + nativePreloadAppProcessHALs(); + Trace.traceEnd(Trace.TRACE_TAG_DALVIK); diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-7.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-7.patch new file mode 100644 index 00000000..dfe3348e --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-7.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Tue, 14 May 2019 14:30:59 -0400 +Subject: [PATCH] disable class preloading for exec spawning + +--- + core/java/com/android/internal/os/ZygoteInit.java | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java +index dbb1fb83f62d..2c681002eaf8 100644 +--- a/core/java/com/android/internal/os/ZygoteInit.java ++++ b/core/java/com/android/internal/os/ZygoteInit.java +@@ -138,9 +138,11 @@ public class ZygoteInit { + bootTimingsTraceLog.traceBegin("BeginPreload"); + beginPreload(fullPreload); + bootTimingsTraceLog.traceEnd(); // BeginPreload +- bootTimingsTraceLog.traceBegin("PreloadClasses"); +- preloadClasses(); +- bootTimingsTraceLog.traceEnd(); // PreloadClasses ++ if (fullPreload) { ++ bootTimingsTraceLog.traceBegin("PreloadClasses"); ++ preloadClasses(); ++ bootTimingsTraceLog.traceEnd(); // PreloadClasses ++ } + bootTimingsTraceLog.traceBegin("CacheNonBootClasspathClassLoaders"); + cacheNonBootClasspathClassLoaders(); + bootTimingsTraceLog.traceEnd(); // CacheNonBootClasspathClassLoaders diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-8.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-8.patch new file mode 100644 index 00000000..1e83e643 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-8.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Tue, 14 May 2019 14:31:29 -0400 +Subject: [PATCH] disable WebView reservation for exec spawning + +--- + core/java/com/android/internal/os/ZygoteInit.java | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java +index 2c681002eaf8..abef5cd17126 100644 +--- a/core/java/com/android/internal/os/ZygoteInit.java ++++ b/core/java/com/android/internal/os/ZygoteInit.java +@@ -159,9 +159,11 @@ public class ZygoteInit { + Trace.traceEnd(Trace.TRACE_TAG_DALVIK); + preloadSharedLibraries(); + preloadTextResources(); +- // Ask the WebViewFactory to do any initialization that must run in the zygote process, +- // for memory sharing purposes. +- WebViewFactory.prepareWebViewInZygote(); ++ if (fullPreload) { ++ // Ask the WebViewFactory to do any initialization that must run in the zygote process, ++ // for memory sharing purposes. ++ WebViewFactory.prepareWebViewInZygote(); ++ } + endPreload(fullPreload); + warmUpJcaProviders(); + Log.d(TAG, "end preload"); diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-9.patch b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-9.patch new file mode 100644 index 00000000..3b7ab7c3 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0018-Exec_Based_Spawning-9.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Tue, 14 May 2019 14:34:32 -0400 +Subject: [PATCH] disable JCA provider warm up for exec spawning + +--- + .../com/android/internal/os/ZygoteInit.java | 22 ++++++++++--------- + 1 file changed, 12 insertions(+), 10 deletions(-) + +diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java +index abef5cd17126..851e5e1fb5b1 100644 +--- a/core/java/com/android/internal/os/ZygoteInit.java ++++ b/core/java/com/android/internal/os/ZygoteInit.java +@@ -165,7 +165,7 @@ public class ZygoteInit { + WebViewFactory.prepareWebViewInZygote(); + } + endPreload(fullPreload); +- warmUpJcaProviders(); ++ warmUpJcaProviders(fullPreload); + Log.d(TAG, "end preload"); + + sPreloadComplete = true; +@@ -229,7 +229,7 @@ public class ZygoteInit { + * By doing it here we avoid that each app does it when requesting a service from the provider + * for the first time. + */ +- private static void warmUpJcaProviders() { ++ private static void warmUpJcaProviders(boolean fullPreload) { + long startTime = SystemClock.uptimeMillis(); + Trace.traceBegin( + Trace.TRACE_TAG_DALVIK, "Starting installation of AndroidKeyStoreProvider"); +@@ -239,15 +239,17 @@ public class ZygoteInit { + + (SystemClock.uptimeMillis() - startTime) + "ms."); + Trace.traceEnd(Trace.TRACE_TAG_DALVIK); + +- startTime = SystemClock.uptimeMillis(); +- Trace.traceBegin( +- Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers"); +- for (Provider p : Security.getProviders()) { +- p.warmUpServiceProvision(); ++ if (fullPreload) { ++ startTime = SystemClock.uptimeMillis(); ++ Trace.traceBegin( ++ Trace.TRACE_TAG_DALVIK, "Starting warm up of JCA providers"); ++ for (Provider p : Security.getProviders()) { ++ p.warmUpServiceProvision(); ++ } ++ Log.i(TAG, "Warmed up JCA providers in " ++ + (SystemClock.uptimeMillis() - startTime) + "ms."); ++ Trace.traceEnd(Trace.TRACE_TAG_DALVIK); + } +- Log.i(TAG, "Warmed up JCA providers in " +- + (SystemClock.uptimeMillis() - startTime) + "ms."); +- Trace.traceEnd(Trace.TRACE_TAG_DALVIK); + } + + /** diff --git a/Patches/LineageOS-19.1/android_frameworks_base/0020-Location_Indicators.patch b/Patches/LineageOS-19.1/android_frameworks_base/0020-Location_Indicators.patch new file mode 100644 index 00000000..d1c44133 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_base/0020-Location_Indicators.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Danny Lin +Date: Mon, 11 Oct 2021 15:03:59 -0700 +Subject: [PATCH] SystemUI: Use new privacy indicators for location + +Android has had location indicators for a while, but let's use the new +privacy indicator infrastructure for displaying them. This makes them +integrate better with the new camera and microphone indicators. + +Change-Id: Ie457bb2dad17bddbf9dc3a818e3ec586023ce918 +--- + core/java/android/permission/PermissionUsageHelper.java | 2 +- + .../src/com/android/systemui/privacy/PrivacyItemController.kt | 4 ++-- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/core/java/android/permission/PermissionUsageHelper.java b/core/java/android/permission/PermissionUsageHelper.java +index cf2361a1026a..5ba24a3d4e7a 100644 +--- a/core/java/android/permission/PermissionUsageHelper.java ++++ b/core/java/android/permission/PermissionUsageHelper.java +@@ -101,7 +101,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis + + private static boolean shouldShowLocationIndicator() { + return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, +- PROPERTY_LOCATION_INDICATORS_ENABLED, false); ++ PROPERTY_LOCATION_INDICATORS_ENABLED, true); + } + + private static long getRecentThreshold(Long now) { +diff --git a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItemController.kt b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItemController.kt +index e072b4a3646c..f7bf1c3af7a2 100644 +--- a/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItemController.kt ++++ b/packages/SystemUI/src/com/android/systemui/privacy/PrivacyItemController.kt +@@ -73,7 +73,7 @@ class PrivacyItemController @Inject constructor( + private const val MIC_CAMERA = SystemUiDeviceConfigFlags.PROPERTY_MIC_CAMERA_ENABLED + private const val LOCATION = SystemUiDeviceConfigFlags.PROPERTY_LOCATION_INDICATORS_ENABLED + private const val DEFAULT_MIC_CAMERA = true +- private const val DEFAULT_LOCATION = false ++ private const val DEFAULT_LOCATION = true + @VisibleForTesting const val TIME_TO_HOLD_INDICATORS = 5000L + } + +@@ -381,4 +381,4 @@ class PrivacyItemController @Inject constructor( + listeningCanceller = delegate.executeDelayed({ setListeningState() }, 0L) + } + } +-} +\ No newline at end of file ++} diff --git a/Patches/LineageOS-19.1/android_frameworks_ex/0001-constify_JNINativeMethod.patch b/Patches/LineageOS-19.1/android_frameworks_ex/0001-constify_JNINativeMethod.patch new file mode 100644 index 00000000..8dc18001 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_ex/0001-constify_JNINativeMethod.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Mon, 4 Jan 2021 19:56:14 -0500 +Subject: [PATCH] constify JNINativeMethod table + +--- + framesequence/jni/FrameSequenceJNI.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/framesequence/jni/FrameSequenceJNI.cpp b/framesequence/jni/FrameSequenceJNI.cpp +index c701f03..4041733 100644 +--- a/framesequence/jni/FrameSequenceJNI.cpp ++++ b/framesequence/jni/FrameSequenceJNI.cpp +@@ -141,7 +141,7 @@ static jlong JNICALL nativeGetFrame( + return delayMs; + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + { "nativeDecodeByteArray", + "([BII)L" JNI_PACKAGE "/FrameSequence;", + (void*) nativeDecodeByteArray diff --git a/Patches/LineageOS-19.1/android_frameworks_native/0001-Sensors_Permission.patch b/Patches/LineageOS-19.1/android_frameworks_native/0001-Sensors_Permission.patch new file mode 100644 index 00000000..f098b3c9 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_native/0001-Sensors_Permission.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sat, 7 Oct 2017 16:28:57 -0400 +Subject: [PATCH] require OTHER_SENSORS permission for sensors + +Ported from 10: ff005a6b6a38baef95c4a01d7e1fc75aac651a58 +--- + libs/sensor/Sensor.cpp | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/libs/sensor/Sensor.cpp b/libs/sensor/Sensor.cpp +index 0a49008584..94bac9177c 100644 +--- a/libs/sensor/Sensor.cpp ++++ b/libs/sensor/Sensor.cpp +@@ -59,6 +59,7 @@ Sensor::Sensor(struct sensor_t const& hwSensor, const uuid_t& uuid, int halVersi + mMinDelay = hwSensor.minDelay; + mFlags = 0; + mUuid = uuid; ++ mRequiredPermission = "android.permission.OTHER_SENSORS"; + + // Set fifo event count zero for older devices which do not support batching. Fused + // sensors also have their fifo counts set to zero. diff --git a/Patches/LineageOS-19.1/android_frameworks_opt_net_ims/0001-Fix_Calling.patch b/Patches/LineageOS-19.1/android_frameworks_opt_net_ims/0001-Fix_Calling.patch new file mode 100644 index 00000000..1fd2c2e9 --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_opt_net_ims/0001-Fix_Calling.patch @@ -0,0 +1,55 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tad +Date: Tue, 14 Apr 2020 16:59:46 -0400 +Subject: [PATCH] Fix calling after VoLTE is removed from devices that had it + previously enabled + +Change-Id: Id5e3b8f7793d0783104b8b59581688c8ef821396 +--- + src/java/com/android/ims/ImsManager.java | 26 +----------------------- + 1 file changed, 1 insertion(+), 25 deletions(-) + +diff --git a/src/java/com/android/ims/ImsManager.java b/src/java/com/android/ims/ImsManager.java +index 345cbc5..fbf0389 100644 +--- a/src/java/com/android/ims/ImsManager.java ++++ b/src/java/com/android/ims/ImsManager.java +@@ -534,13 +534,6 @@ public class ImsManager implements FeatureUpdates { + */ + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + public static boolean isEnhanced4gLteModeSettingEnabledByUser(Context context) { +- DefaultSubscriptionManagerProxy p = new DefaultSubscriptionManagerProxy(context); +- ImsManager mgr = ImsManager.getInstance(context, p.getDefaultVoicePhoneId()); +- if (mgr != null) { +- return mgr.isEnhanced4gLteModeSettingEnabledByUser(); +- } +- Rlog.e(TAG, "isEnhanced4gLteModeSettingEnabledByUser: ImsManager null, returning default" +- + " value."); + return false; + } + +@@ -555,24 +548,7 @@ public class ImsManager implements FeatureUpdates { + * return the default value. + */ + public boolean isEnhanced4gLteModeSettingEnabledByUser() { +- int setting = mSubscriptionManagerProxy.getIntegerSubscriptionProperty( +- getSubId(), SubscriptionManager.ENHANCED_4G_MODE_ENABLED, +- SUB_PROPERTY_NOT_INITIALIZED); +- boolean onByDefault = getBooleanCarrierConfig( +- CarrierConfigManager.KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL); +- boolean isUiUnEditable = +- !getBooleanCarrierConfig(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL) +- || getBooleanCarrierConfig(CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL); +- boolean isSettingNotInitialized = setting == SUB_PROPERTY_NOT_INITIALIZED; +- +- // If Enhanced 4G LTE Mode is uneditable, hidden, not initialized and VoIMS opt-in disabled +- // we use the default value. If VoIMS opt-in is enabled, we will always allow the user to +- // change the IMS enabled setting. +- if ((isUiUnEditable || isSettingNotInitialized) && !isVoImsOptInEnabled()) { +- return onByDefault; +- } else { +- return (setting == ProvisioningManager.PROVISIONING_VALUE_ENABLED); +- } ++ return false; + } + + /** diff --git a/Patches/LineageOS-19.1/android_frameworks_opt_net_wifi/0001-Random_MAC.patch b/Patches/LineageOS-19.1/android_frameworks_opt_net_wifi/0001-Random_MAC.patch new file mode 100644 index 00000000..4772dc9d --- /dev/null +++ b/Patches/LineageOS-19.1/android_frameworks_opt_net_wifi/0001-Random_MAC.patch @@ -0,0 +1,88 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: renlord +Date: Fri, 15 Oct 2021 19:11:18 +0530 +Subject: [PATCH] add support for always generating new random MAC + +To trigger re-generation of randomized MAC addressed for an already +connected AP. User simply has to toggle on/off wifi. Otherwise, on +re-connection, a new randomized MAC address also gets generated. + +based on https://github.com/GrapheneOS/platform_frameworks_opt_net_wifi/commit/a0d9bda06b71694f38fe02bbe24628ee21a7d270 +--- + .../wifitrackerlib/StandardWifiEntry.java | 32 ++++++++++++++----- + .../com/android/wifitrackerlib/WifiEntry.java | 1 + + 2 files changed, 25 insertions(+), 8 deletions(-) + +diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java +index 4f63ced83..3d3000d33 100644 +--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java ++++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java +@@ -260,7 +260,7 @@ public class StandardWifiEntry extends WifiEntry { + return wifiInfoMac; + } + } +- if (mTargetWifiConfig == null || getPrivacy() != PRIVACY_RANDOMIZED_MAC) { ++ if (mTargetWifiConfig == null || getPrivacy() == PRIVACY_DEVICE_MAC) { + final String[] factoryMacs = mWifiManager.getFactoryMacAddresses(); + if (factoryMacs.length > 0) { + return factoryMacs[0]; +@@ -522,12 +522,18 @@ public class StandardWifiEntry extends WifiEntry { + @Override + @Privacy + public synchronized int getPrivacy() { +- if (mTargetWifiConfig != null +- && mTargetWifiConfig.macRandomizationSetting +- == WifiConfiguration.RANDOMIZATION_NONE) { +- return PRIVACY_DEVICE_MAC; ++ if (mTargetWifiConfig != null) { ++ switch (mTargetWifiConfig.macRandomizationSetting) { ++ case WifiConfiguration.RANDOMIZATION_NONE: ++ return PRIVACY_DEVICE_MAC; ++ case WifiConfiguration.RANDOMIZATION_ALWAYS: ++ return PRIVACY_RANDOMIZATION_ALWAYS; ++ default: ++ // WifiConfiguration.RANDOMIZATION_AUTO and WifiConfiguration.RANDOMIZATION_PERSISTENT ++ return PRIVACY_RANDOMIZED_MAC; ++ } + } else { +- return PRIVACY_RANDOMIZED_MAC; ++ return PRIVACY_RANDOMIZATION_ALWAYS; + } + } + +@@ -537,11 +543,21 @@ public class StandardWifiEntry extends WifiEntry { + return; + } + +- mTargetWifiConfig.macRandomizationSetting = privacy == PRIVACY_RANDOMIZED_MAC +- ? WifiConfiguration.RANDOMIZATION_AUTO : WifiConfiguration.RANDOMIZATION_NONE; ++ mTargetWifiConfig.macRandomizationSetting = translatePrivacyToWifiConfigurationValues(privacy); + mWifiManager.save(mTargetWifiConfig, null /* listener */); + } + ++ private static int translatePrivacyToWifiConfigurationValues(int privacyValue) { ++ switch (privacyValue) { ++ case PRIVACY_RANDOMIZED_MAC: ++ return WifiConfiguration.RANDOMIZATION_PERSISTENT; ++ case PRIVACY_DEVICE_MAC: ++ return WifiConfiguration.RANDOMIZATION_NONE; ++ default: ++ return WifiConfiguration.RANDOMIZATION_ALWAYS; ++ } ++ } ++ + @Override + public synchronized boolean isAutoJoinEnabled() { + if (mTargetWifiConfig == null) { +diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java +index 15edf8a18..e3bc3a45b 100644 +--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java ++++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiEntry.java +@@ -156,6 +156,7 @@ public class WifiEntry implements Comparable { + public static final int PRIVACY_DEVICE_MAC = 0; + public static final int PRIVACY_RANDOMIZED_MAC = 1; + public static final int PRIVACY_UNKNOWN = 2; ++ public static final int PRIVACY_RANDOMIZATION_ALWAYS = 100; + + @Retention(RetentionPolicy.SOURCE) + @IntDef(value = { diff --git a/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-8996.patch b/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-8996.patch new file mode 100644 index 00000000..edbd16c7 --- /dev/null +++ b/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-8996.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: codeworkx +Date: Sun, 20 Jan 2019 17:48:20 +0100 +Subject: [PATCH] audio_extn: Fix unused parameter warning in utils.c + +The unused parameter warning appears if we are not building with +at least one of the following cflags enabled: + +* DEV_ARBI_ENABLED +* SOUND_TRIGGER_ENABLED +* AUDIO_LISTEN_ENABLED + + hardware/qcom/audio/hal/audio_extn/utils.c:2522:55: error: unused parameter 'snd_device' +[-Werror,-Wunused-parameter] + void audio_extn_utils_release_snd_device(snd_device_t snd_device) + ^ + +Change-Id: I694c683c9bfde60343f0f6ea8d806bc5e24437e6 +(cherry picked from commit 12981fb9f3c8a67bcc362c7badfb9189bc181cda) +--- + hal/audio_extn/audio_extn.h | 5 +++++ + hal/audio_extn/utils.c | 2 ++ + 2 files changed, 7 insertions(+) + +diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h +index 1187642d1..38ae1aed5 100644 +--- a/hal/audio_extn/audio_extn.h ++++ b/hal/audio_extn/audio_extn.h +@@ -688,7 +688,12 @@ bool audio_extn_utils_is_dolby_format(audio_format_t format); + int audio_extn_utils_get_bit_width_from_string(const char *); + int audio_extn_utils_get_sample_rate_from_string(const char *); + int audio_extn_utils_get_channels_from_string(const char *); ++ ++#if !defined(DEV_ARBI_ENABLED) && !defined(SOUND_TRIGGER_ENABLED) && !defined(AUDIO_LISTEN_ENABLED) ++#define audio_extn_utils_release_snd_device(snd_device) (0) ++#else + void audio_extn_utils_release_snd_device(snd_device_t snd_device); ++#endif + int audio_extn_utils_get_app_sample_rate_for_device(struct audio_device *adev, + struct audio_usecase *usecase, int snd_device); + +diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c +index cd788542f..10f1eb216 100644 +--- a/hal/audio_extn/utils.c ++++ b/hal/audio_extn/utils.c +@@ -2520,6 +2520,7 @@ int audio_extn_utils_get_channels_from_string(const char *id_string) + return -EINVAL; + } + ++#if defined(DEV_ARBI_ENABLED) || defined(SOUND_TRIGGER_ENABLED) || defined(AUDIO_LISTEN_ENABLED) + void audio_extn_utils_release_snd_device(snd_device_t snd_device) + { + audio_extn_dev_arbi_release(snd_device); +@@ -2528,3 +2529,4 @@ void audio_extn_utils_release_snd_device(snd_device_t snd_device) + audio_extn_listen_update_device_status(snd_device, + LISTEN_EVENT_SND_DEVICE_FREE); + } ++#endif diff --git a/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-8998.patch b/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-8998.patch new file mode 100644 index 00000000..3bcf1137 --- /dev/null +++ b/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-8998.patch @@ -0,0 +1,60 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: codeworkx +Date: Sun, 20 Jan 2019 17:48:20 +0100 +Subject: [PATCH] audio_extn: Fix unused parameter warning in utils.c + +The unused parameter warning appears if we are not building with +at least one of the following cflags enabled: + +* DEV_ARBI_ENABLED +* SOUND_TRIGGER_ENABLED +* AUDIO_LISTEN_ENABLED + + hardware/qcom/audio/hal/audio_extn/utils.c:2522:55: error: unused parameter 'snd_device' +[-Werror,-Wunused-parameter] + void audio_extn_utils_release_snd_device(snd_device_t snd_device) + ^ + +Change-Id: I694c683c9bfde60343f0f6ea8d806bc5e24437e6 +Signed-off-by: Atman +--- + hal/audio_extn/audio_extn.h | 4 ++++ + hal/audio_extn/utils.c | 2 ++ + 2 files changed, 6 insertions(+) + +diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h +index f37c948ec..c6b2051a7 100644 +--- a/hal/audio_extn/audio_extn.h ++++ b/hal/audio_extn/audio_extn.h +@@ -815,7 +815,11 @@ bool audio_extn_utils_is_dolby_format(audio_format_t format); + int audio_extn_utils_get_bit_width_from_string(const char *); + int audio_extn_utils_get_sample_rate_from_string(const char *); + int audio_extn_utils_get_channels_from_string(const char *); ++#if !defined(DEV_ARBI_ENABLED) && !defined(SOUND_TRIGGER_ENABLED) && !defined(AUDIO_LISTEN_ENABLED) ++#define audio_extn_utils_release_snd_device(snd_device) (0) ++#else + void audio_extn_utils_release_snd_device(snd_device_t snd_device); ++#endif + bool audio_extn_utils_is_vendor_enhanced_fwk(); + int audio_extn_utils_get_vendor_enhanced_info(); + int audio_extn_utils_get_app_sample_rate_for_device(struct audio_device *adev, +diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c +index 4675fc39c..4a5d91a97 100644 +--- a/hal/audio_extn/utils.c ++++ b/hal/audio_extn/utils.c +@@ -2917,6 +2917,7 @@ int audio_extn_utils_get_channels_from_string(const char *id_string) + return -EINVAL; + } + ++#if defined(DEV_ARBI_ENABLED) || defined(SOUND_TRIGGER_ENABLED) || defined(AUDIO_LISTEN_ENABLED) + void audio_extn_utils_release_snd_device(snd_device_t snd_device) + { + audio_extn_dev_arbi_release(snd_device); +@@ -2925,6 +2926,7 @@ void audio_extn_utils_release_snd_device(snd_device_t snd_device) + audio_extn_listen_update_device_status(snd_device, + LISTEN_EVENT_SND_DEVICE_FREE); + } ++#endif + + int audio_extn_utils_get_license_params( + const struct audio_device *adev, diff --git a/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-sdm845.patch b/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-sdm845.patch new file mode 100644 index 00000000..9c841bdd --- /dev/null +++ b/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-sdm845.patch @@ -0,0 +1,60 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: codeworkx +Date: Sun, 20 Jan 2019 17:48:20 +0100 +Subject: [PATCH] audio_extn: Fix unused parameter warning in utils.c + +The unused parameter warning appears if we are not building with +at least one of the following cflags enabled: + +* DEV_ARBI_ENABLED +* SOUND_TRIGGER_ENABLED +* AUDIO_LISTEN_ENABLED + + hardware/qcom/audio/hal/audio_extn/utils.c:2522:55: error: unused parameter 'snd_device' +[-Werror,-Wunused-parameter] + void audio_extn_utils_release_snd_device(snd_device_t snd_device) + ^ + +Change-Id: I694c683c9bfde60343f0f6ea8d806bc5e24437e6 +Signed-off-by: Atman +--- + hal/audio_extn/audio_extn.h | 4 ++++ + hal/audio_extn/utils.c | 2 ++ + 2 files changed, 6 insertions(+) + +diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h +index 85502ad91..95890ab12 100755 +--- a/hal/audio_extn/audio_extn.h ++++ b/hal/audio_extn/audio_extn.h +@@ -860,7 +860,11 @@ bool audio_extn_utils_is_dolby_format(audio_format_t format); + int audio_extn_utils_get_bit_width_from_string(const char *); + int audio_extn_utils_get_sample_rate_from_string(const char *); + int audio_extn_utils_get_channels_from_string(const char *); ++#if !defined(DEV_ARBI_ENABLED) && !defined(SOUND_TRIGGER_ENABLED) && !defined(AUDIO_LISTEN_ENABLED) ++#define audio_extn_utils_release_snd_device(snd_device) (0) ++#else + void audio_extn_utils_release_snd_device(snd_device_t snd_device); ++#endif + bool audio_extn_utils_is_vendor_enhanced_fwk(); + int audio_extn_utils_get_vendor_enhanced_info(); + int audio_extn_utils_get_app_sample_rate_for_device(struct audio_device *adev, +diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c +index 756faf544..0e25d3a39 100755 +--- a/hal/audio_extn/utils.c ++++ b/hal/audio_extn/utils.c +@@ -3272,6 +3272,7 @@ int audio_extn_utils_get_channels_from_string(const char *id_string) + return -EINVAL; + } + ++#if defined(DEV_ARBI_ENABLED) || defined(SOUND_TRIGGER_ENABLED) || defined(AUDIO_LISTEN_ENABLED) + void audio_extn_utils_release_snd_device(snd_device_t snd_device) + { + audio_extn_dev_arbi_release(snd_device); +@@ -3280,6 +3281,7 @@ void audio_extn_utils_release_snd_device(snd_device_t snd_device) + audio_extn_listen_update_device_status(snd_device, + LISTEN_EVENT_SND_DEVICE_FREE); + } ++#endif + + int audio_extn_utils_get_license_params( + const struct audio_device *adev, diff --git a/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-sm8150.patch b/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-sm8150.patch new file mode 100644 index 00000000..069c737a --- /dev/null +++ b/Patches/LineageOS-19.1/android_hardware_qcom_audio/0001-Unused-sm8150.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: codeworkx +Date: Mon, 1 Jul 2019 06:36:30 +0000 +Subject: [PATCH] audio_extn: Fix unused parameter warning in utils.c + +The unused parameter warning appears if we are not building with +at least one of the following cflags enabled: + +* DEV_ARBI_ENABLED +* SOUND_TRIGGER_ENABLED +* AUDIO_LISTEN_ENABLED + + hardware/qcom/audio/hal/audio_extn/utils.c:2522:55: error: unused parameter 'snd_device' +[-Werror,-Wunused-parameter] + void audio_extn_utils_release_snd_device(snd_device_t snd_device) + +Change-Id: I694c683c9bfde60343f0f6ea8d806bc5e24437e6 +--- + hal/audio_extn/audio_extn.h | 4 ++++ + hal/audio_extn/utils.c | 2 ++ + 2 files changed, 6 insertions(+) + +diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h +index da986ad63..82320356e 100644 +--- a/hal/audio_extn/audio_extn.h ++++ b/hal/audio_extn/audio_extn.h +@@ -834,7 +834,11 @@ bool audio_extn_utils_is_dolby_format(audio_format_t format); + int audio_extn_utils_get_bit_width_from_string(const char *); + int audio_extn_utils_get_sample_rate_from_string(const char *); + int audio_extn_utils_get_channels_from_string(const char *); ++#if !defined(DEV_ARBI_ENABLED) && !defined(SOUND_TRIGGER_ENABLED) && !defined(AUDIO_LISTEN_ENABLED) ++#define audio_extn_utils_release_snd_device(snd_device) (0) ++#else + void audio_extn_utils_release_snd_device(snd_device_t snd_device); ++#endif + bool audio_extn_utils_is_vendor_enhanced_fwk(); + int audio_extn_utils_get_vendor_enhanced_info(); + int audio_extn_utils_get_app_sample_rate_for_device(struct audio_device *adev, +diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c +index 0ba2f4f82..d179f4f03 100644 +--- a/hal/audio_extn/utils.c ++++ b/hal/audio_extn/utils.c +@@ -3072,6 +3072,7 @@ int audio_extn_utils_get_channels_from_string(const char *id_string) + return -EINVAL; + } + ++#if defined(DEV_ARBI_ENABLED) || defined(SOUND_TRIGGER_ENABLED) || defined(AUDIO_LISTEN_ENABLED) + void audio_extn_utils_release_snd_device(snd_device_t snd_device) + { + audio_extn_dev_arbi_release(snd_device); +@@ -3080,6 +3081,7 @@ void audio_extn_utils_release_snd_device(snd_device_t snd_device) + audio_extn_listen_update_device_status(snd_device, + LISTEN_EVENT_SND_DEVICE_FREE); + } ++#endif + + int audio_extn_utils_get_license_params( + const struct audio_device *adev, diff --git a/Patches/LineageOS-19.1/android_libcore/0001-Network_Permission.patch b/Patches/LineageOS-19.1/android_libcore/0001-Network_Permission.patch new file mode 100644 index 00000000..8e8bf556 --- /dev/null +++ b/Patches/LineageOS-19.1/android_libcore/0001-Network_Permission.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Dmitry Muhomor +Date: Tue, 14 Dec 2021 21:10:51 +0200 +Subject: [PATCH] don't throw SecurityException when INTERNET permission is + revoked + +--- + ojluni/src/main/java/java/net/Inet6AddressImpl.java | 11 +---------- + 1 file changed, 1 insertion(+), 10 deletions(-) + +diff --git a/ojluni/src/main/java/java/net/Inet6AddressImpl.java b/ojluni/src/main/java/java/net/Inet6AddressImpl.java +index 84bcf17edae..fda9674e08e 100644 +--- a/ojluni/src/main/java/java/net/Inet6AddressImpl.java ++++ b/ojluni/src/main/java/java/net/Inet6AddressImpl.java +@@ -141,16 +141,7 @@ class Inet6AddressImpl implements InetAddressImpl { + addressCache.put(host, netId, addresses); + return addresses; + } catch (GaiException gaiException) { +- // If the failure appears to have been a lack of INTERNET permission, throw a clear +- // SecurityException to aid in debugging this common mistake. +- // http://code.google.com/p/android/issues/detail?id=15722 +- if (gaiException.getCause() instanceof ErrnoException) { +- int errno = ((ErrnoException) gaiException.getCause()).errno; +- if (errno == EACCES || errno == EPERM) { +- throw new SecurityException("Permission denied (missing INTERNET permission?)", gaiException); +- } +- } +- // Otherwise, throw an UnknownHostException. ++ // Throw an UnknownHostException. + String detailMessage = "Unable to resolve host \"" + host + "\": " + Libcore.os.gai_strerror(gaiException.error); + addressCache.putUnknownHost(host, netId, detailMessage); + throw gaiException.rethrowAsUnknownHostException(detailMessage); diff --git a/Patches/LineageOS-19.1/android_libcore/0002-constify_JNINativeMethod.patch b/Patches/LineageOS-19.1/android_libcore/0002-constify_JNINativeMethod.patch new file mode 100644 index 00000000..6852442c --- /dev/null +++ b/Patches/LineageOS-19.1/android_libcore/0002-constify_JNINativeMethod.patch @@ -0,0 +1,199 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sun, 10 Oct 2021 18:47:54 -0400 +Subject: [PATCH] constify JNINativeMethod tables + +--- + luni/src/main/native/android_system_OsConstants.cpp | 2 +- + luni/src/main/native/java_lang_StringToReal.cpp | 2 +- + luni/src/main/native/java_lang_invoke_MethodHandle.cpp | 2 +- + luni/src/main/native/java_lang_invoke_VarHandle.cpp | 2 +- + luni/src/main/native/libcore_icu_ICU.cpp | 2 +- + luni/src/main/native/libcore_io_AsynchronousCloseMonitor.cpp | 2 +- + luni/src/main/native/libcore_io_Linux.cpp | 2 +- + luni/src/main/native/libcore_io_Memory.cpp | 2 +- + luni/src/main/native/libcore_math_NativeBN.cpp | 2 +- + .../src/main/native/libcore_util_NativeAllocationRegistry.cpp | 2 +- + luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp | 4 ++-- + luni/src/main/native/sun_misc_Unsafe.cpp | 2 +- + ojluni/src/main/native/Character.cpp | 2 +- + 13 files changed, 14 insertions(+), 14 deletions(-) + +diff --git a/luni/src/main/native/android_system_OsConstants.cpp b/luni/src/main/native/android_system_OsConstants.cpp +index 50e3c104666..8ad66d2742b 100644 +--- a/luni/src/main/native/android_system_OsConstants.cpp ++++ b/luni/src/main/native/android_system_OsConstants.cpp +@@ -722,7 +722,7 @@ static void OsConstants_initConstants(JNIEnv* env, jclass c) { + initConstant(env, c, "_SC_XOPEN_XCU_VERSION", _SC_XOPEN_XCU_VERSION); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(OsConstants, initConstants, "()V"), + }; + void register_android_system_OsConstants(JNIEnv* env) { +diff --git a/luni/src/main/native/java_lang_StringToReal.cpp b/luni/src/main/native/java_lang_StringToReal.cpp +index 7a492856394..edd71fad700 100644 +--- a/luni/src/main/native/java_lang_StringToReal.cpp ++++ b/luni/src/main/native/java_lang_StringToReal.cpp +@@ -892,7 +892,7 @@ static jdouble StringToReal_parseDblImpl(JNIEnv* env, jclass, jstring s, jint e) + return createDouble(env, str.c_str(), e); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(StringToReal, parseFltImpl, "(Ljava/lang/String;I)F"), + NATIVE_METHOD(StringToReal, parseDblImpl, "(Ljava/lang/String;I)D"), + }; +diff --git a/luni/src/main/native/java_lang_invoke_MethodHandle.cpp b/luni/src/main/native/java_lang_invoke_MethodHandle.cpp +index 0441d4552dc..3335c6de9ac 100644 +--- a/luni/src/main/native/java_lang_invoke_MethodHandle.cpp ++++ b/luni/src/main/native/java_lang_invoke_MethodHandle.cpp +@@ -29,7 +29,7 @@ static jobject MethodHandle_invoke(JNIEnv* env, jobject, jobjectArray) { + return nullptr; + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(MethodHandle, invokeExact, "([Ljava/lang/Object;)Ljava/lang/Object;"), + NATIVE_METHOD(MethodHandle, invoke, "([Ljava/lang/Object;)Ljava/lang/Object;"), + }; +diff --git a/luni/src/main/native/java_lang_invoke_VarHandle.cpp b/luni/src/main/native/java_lang_invoke_VarHandle.cpp +index e1cc1c7f8b5..9f5215a5204 100644 +--- a/luni/src/main/native/java_lang_invoke_VarHandle.cpp ++++ b/luni/src/main/native/java_lang_invoke_VarHandle.cpp +@@ -210,7 +210,7 @@ static jboolean VarHandle_weakCompareAndSetRelease(JNIEnv* env, jobject, jobject + return JNI_FALSE; + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(VarHandle, compareAndExchange, "([Ljava/lang/Object;)Ljava/lang/Object;"), + NATIVE_METHOD(VarHandle, compareAndExchangeAcquire, "([Ljava/lang/Object;)Ljava/lang/Object;"), + NATIVE_METHOD(VarHandle, compareAndExchangeRelease, "([Ljava/lang/Object;)Ljava/lang/Object;"), +diff --git a/luni/src/main/native/libcore_icu_ICU.cpp b/luni/src/main/native/libcore_icu_ICU.cpp +index f9401d1edb7..1531ad1ca59 100644 +--- a/luni/src/main/native/libcore_icu_ICU.cpp ++++ b/luni/src/main/native/libcore_icu_ICU.cpp +@@ -112,7 +112,7 @@ static jstring ICU_getUnicodeVersion(JNIEnv* env, jclass) { + return versionString(env, unicodeVersion); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(ICU, getAvailableLocalesNative, "()[Ljava/lang/String;"), + NATIVE_METHOD(ICU, getCldrVersion, "()Ljava/lang/String;"), + NATIVE_METHOD(ICU, getDefaultLocale, "()Ljava/lang/String;"), +diff --git a/luni/src/main/native/libcore_io_AsynchronousCloseMonitor.cpp b/luni/src/main/native/libcore_io_AsynchronousCloseMonitor.cpp +index e99edd6c4f9..61b75bcd358 100644 +--- a/luni/src/main/native/libcore_io_AsynchronousCloseMonitor.cpp ++++ b/luni/src/main/native/libcore_io_AsynchronousCloseMonitor.cpp +@@ -26,7 +26,7 @@ static void AsynchronousCloseMonitor_signalBlockedThreads(JNIEnv* env, jclass, j + AsynchronousCloseMonitor::signalBlockedThreads(fd); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(AsynchronousCloseMonitor, signalBlockedThreads, "(Ljava/io/FileDescriptor;)V"), + }; + void register_libcore_io_AsynchronousCloseMonitor(JNIEnv* env) { +diff --git a/luni/src/main/native/libcore_io_Linux.cpp b/luni/src/main/native/libcore_io_Linux.cpp +index d7b6c22aa57..996085b1423 100755 +--- a/luni/src/main/native/libcore_io_Linux.cpp ++++ b/luni/src/main/native/libcore_io_Linux.cpp +@@ -2741,7 +2741,7 @@ static jint Linux_writev(JNIEnv* env, jobject, jobject javaFd, jobjectArray buff + #define NATIVE_METHOD_OVERLOAD(className, functionName, signature, variant) \ + { #functionName, signature, reinterpret_cast(className ## _ ## functionName ## variant) } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(Linux, accept, "(Ljava/io/FileDescriptor;Ljava/net/SocketAddress;)Ljava/io/FileDescriptor;"), + NATIVE_METHOD(Linux, access, "(Ljava/lang/String;I)Z"), + NATIVE_METHOD(Linux, android_fdsan_exchange_owner_tag, "(Ljava/io/FileDescriptor;JJ)V"), +diff --git a/luni/src/main/native/libcore_io_Memory.cpp b/luni/src/main/native/libcore_io_Memory.cpp +index b8a88450006..7dec85dab80 100644 +--- a/luni/src/main/native/libcore_io_Memory.cpp ++++ b/luni/src/main/native/libcore_io_Memory.cpp +@@ -290,7 +290,7 @@ static void Memory_unsafeBulkPut(JNIEnv* env, jclass, jbyteArray dstArray, jint + env->ReleasePrimitiveArrayCritical(srcArray, srcBytes, 0); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(Memory, memmove, "(Ljava/lang/Object;ILjava/lang/Object;IJ)V"), + FAST_NATIVE_METHOD(Memory, peekByte, "(J)B"), + NATIVE_METHOD(Memory, peekByteArray, "(J[BII)V"), +diff --git a/luni/src/main/native/libcore_math_NativeBN.cpp b/luni/src/main/native/libcore_math_NativeBN.cpp +index dc4b947358b..c6af376f6bc 100644 +--- a/luni/src/main/native/libcore_math_NativeBN.cpp ++++ b/luni/src/main/native/libcore_math_NativeBN.cpp +@@ -164,7 +164,7 @@ static void NativeBN_BN_mod_exp(JNIEnv* env, jclass, jlong r, jlong a, jlong p, + } + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(NativeBN, BN_div, "(JJJJ)V"), + NATIVE_METHOD(NativeBN, BN_free, "(J)V"), + NATIVE_METHOD(NativeBN, BN_mod_exp, "(JJJJ)V"), +diff --git a/luni/src/main/native/libcore_util_NativeAllocationRegistry.cpp b/luni/src/main/native/libcore_util_NativeAllocationRegistry.cpp +index ded578a9580..faaa5c7a7c4 100644 +--- a/luni/src/main/native/libcore_util_NativeAllocationRegistry.cpp ++++ b/luni/src/main/native/libcore_util_NativeAllocationRegistry.cpp +@@ -29,7 +29,7 @@ static void NativeAllocationRegistry_applyFreeFunction(JNIEnv*, + nativeFreeFunction(nativePtr); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(NativeAllocationRegistry, applyFreeFunction, "(JJ)V"), + }; + +diff --git a/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp b/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp +index fdabcf71591..62a2cd37b76 100644 +--- a/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp ++++ b/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp +@@ -1366,7 +1366,7 @@ static void ExpatParser_staticInitialize(JNIEnv* env, jobject classObject, jstri + emptyString = reinterpret_cast(env->NewGlobalRef(empty)); + } + +-static JNINativeMethod parserMethods[] = { ++static const JNINativeMethod parserMethods[] = { + NATIVE_METHOD(ExpatParser, appendString, "(JLjava/lang/String;Z)V"), + NATIVE_METHOD(ExpatParser, appendBytes, "(J[BII)V"), + NATIVE_METHOD(ExpatParser, appendChars, "(J[CII)V"), +@@ -1380,7 +1380,7 @@ static JNINativeMethod parserMethods[] = { + NATIVE_METHOD(ExpatParser, staticInitialize, "(Ljava/lang/String;)V"), + }; + +-static JNINativeMethod attributeMethods[] = { ++static const JNINativeMethod attributeMethods[] = { + NATIVE_METHOD(ExpatAttributes, freeAttributes, "(J)V"), + NATIVE_METHOD(ExpatAttributes, getIndexForQName, "(JLjava/lang/String;)I"), + NATIVE_METHOD(ExpatAttributes, getIndex, "(JLjava/lang/String;Ljava/lang/String;)I"), +diff --git a/luni/src/main/native/sun_misc_Unsafe.cpp b/luni/src/main/native/sun_misc_Unsafe.cpp +index 49848a2db2b..87b2feac807 100644 +--- a/luni/src/main/native/sun_misc_Unsafe.cpp ++++ b/luni/src/main/native/sun_misc_Unsafe.cpp +@@ -23,7 +23,7 @@ static jobject Unsafe_allocateInstance(JNIEnv* env, jclass, jclass c) { + return env->AllocObject(c); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + NATIVE_METHOD(Unsafe, allocateInstance, "(Ljava/lang/Class;)Ljava/lang/Object;"), + }; + void register_sun_misc_Unsafe(JNIEnv* env) { +diff --git a/ojluni/src/main/native/Character.cpp b/ojluni/src/main/native/Character.cpp +index 3e27c674d2f..719190c81ae 100644 +--- a/ojluni/src/main/native/Character.cpp ++++ b/ojluni/src/main/native/Character.cpp +@@ -158,7 +158,7 @@ Character_getNameImpl(JNIEnv* env, jclass, jint codePoint) { + return (U_FAILURE(status) || byteCount == 0) ? NULL : env->NewStringUTF(buf); + } + +-static JNINativeMethod gMethods[] = { ++static const JNINativeMethod gMethods[] = { + FAST_NATIVE_METHOD(Character, digitImpl, "(II)I"), + FAST_NATIVE_METHOD(Character, getDirectionalityImpl, "(I)B"), + NATIVE_METHOD(Character, getNameImpl, "(I)Ljava/lang/String;"), diff --git a/Patches/LineageOS-19.1/android_libcore/0003-Exec_Based_Spawning-1.patch b/Patches/LineageOS-19.1/android_libcore/0003-Exec_Based_Spawning-1.patch new file mode 100644 index 00000000..2a526798 --- /dev/null +++ b/Patches/LineageOS-19.1/android_libcore/0003-Exec_Based_Spawning-1.patch @@ -0,0 +1,112 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Wed, 11 Sep 2019 06:46:38 -0400 +Subject: [PATCH] add parameter for avoiding full preload with exec + +--- + api/module-lib-current.txt | 2 ++ + .../main/java/dalvik/system/ZygoteHooks.java | 26 +++++++++++++++++-- + .../api/legacy_platform/current.txt | 2 ++ + .../api/stable_platform/current.txt | 2 ++ + 4 files changed, 30 insertions(+), 2 deletions(-) + +diff --git a/api/module-lib-current.txt b/api/module-lib-current.txt +index 15741a78057..e554dd77cb8 100644 +--- a/api/module-lib-current.txt ++++ b/api/module-lib-current.txt +@@ -366,7 +366,9 @@ package dalvik.system { + public final class ZygoteHooks { + method public static void gcAndFinalize(); + method public static boolean isIndefiniteThreadSuspensionSafe(); ++ method public static void onBeginPreload(boolean); + method public static void onBeginPreload(); ++ method public static void onEndPreload(boolean); + method public static void onEndPreload(); + method public static void postForkChild(int, boolean, boolean, String); + method public static void postForkCommon(); +diff --git a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java +index a17a2574f7b..763511d2187 100644 +--- a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java ++++ b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java +@@ -62,7 +62,7 @@ public final class ZygoteHooks { + */ + @SystemApi(client = MODULE_LIBRARIES) + @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) +- public static void onBeginPreload() { ++ public static void onBeginPreload(boolean fullPreload) { + com.android.i18n.system.ZygoteHooks.onBeginPreload(); + + ICU.initializeCacheInZygote(); +@@ -81,6 +81,17 @@ public final class ZygoteHooks { + } + } + ++ /** ++ * Called when the zygote begins preloading classes and data. ++ * ++ * @hide ++ */ ++ @SystemApi(client = MODULE_LIBRARIES) ++ @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) ++ public static void onBeginPreload() { ++ onBeginPreload(true); ++ } ++ + /** + * Called when the zygote has completed preloading classes and data. + * +@@ -88,7 +99,7 @@ public final class ZygoteHooks { + */ + @SystemApi(client = MODULE_LIBRARIES) + @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) +- public static void onEndPreload() { ++ public static void onEndPreload(boolean fullPreload) { + com.android.i18n.system.ZygoteHooks.onEndPreload(); + + // Clone standard descriptors as originals closed / rebound during zygote post fork. +@@ -97,6 +108,17 @@ public final class ZygoteHooks { + FileDescriptor.err.cloneForFork(); + } + ++ /** ++ * Called when the zygote has completed preloading classes and data. ++ * ++ * @hide ++ */ ++ @SystemApi(client = MODULE_LIBRARIES) ++ @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) ++ public static void onEndPreload() { ++ onEndPreload(true); ++ } ++ + /** + * Runs several special GCs to try to clean up a few generations of + * softly- and final-reachable objects, along with any other garbage. +diff --git a/mmodules/core_platform_api/api/legacy_platform/current.txt b/mmodules/core_platform_api/api/legacy_platform/current.txt +index 15741a78057..e554dd77cb8 100644 +--- a/mmodules/core_platform_api/api/legacy_platform/current.txt ++++ b/mmodules/core_platform_api/api/legacy_platform/current.txt +@@ -366,7 +366,9 @@ package dalvik.system { + public final class ZygoteHooks { + method public static void gcAndFinalize(); + method public static boolean isIndefiniteThreadSuspensionSafe(); ++ method public static void onBeginPreload(boolean); + method public static void onBeginPreload(); ++ method public static void onEndPreload(boolean); + method public static void onEndPreload(); + method public static void postForkChild(int, boolean, boolean, String); + method public static void postForkCommon(); +diff --git a/mmodules/core_platform_api/api/stable_platform/current.txt b/mmodules/core_platform_api/api/stable_platform/current.txt +index 15741a78057..e554dd77cb8 100644 +--- a/mmodules/core_platform_api/api/stable_platform/current.txt ++++ b/mmodules/core_platform_api/api/stable_platform/current.txt +@@ -366,7 +366,9 @@ package dalvik.system { + public final class ZygoteHooks { + method public static void gcAndFinalize(); + method public static boolean isIndefiniteThreadSuspensionSafe(); ++ method public static void onBeginPreload(boolean); + method public static void onBeginPreload(); ++ method public static void onEndPreload(boolean); + method public static void onEndPreload(); + method public static void postForkChild(int, boolean, boolean, String); + method public static void postForkCommon(); diff --git a/Patches/LineageOS-19.1/android_libcore/0003-Exec_Based_Spawning-2.patch b/Patches/LineageOS-19.1/android_libcore/0003-Exec_Based_Spawning-2.patch new file mode 100644 index 00000000..31f46ac4 --- /dev/null +++ b/Patches/LineageOS-19.1/android_libcore/0003-Exec_Based_Spawning-2.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Thu, 14 Oct 2021 17:00:10 -0400 +Subject: [PATCH] disable ICU cache pinning for exec spawning + +--- + dalvik/src/main/java/dalvik/system/ZygoteHooks.java | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java +index 763511d2187..179c19ac8d5 100644 +--- a/dalvik/src/main/java/dalvik/system/ZygoteHooks.java ++++ b/dalvik/src/main/java/dalvik/system/ZygoteHooks.java +@@ -63,9 +63,11 @@ public final class ZygoteHooks { + @SystemApi(client = MODULE_LIBRARIES) + @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) + public static void onBeginPreload(boolean fullPreload) { +- com.android.i18n.system.ZygoteHooks.onBeginPreload(); ++ if (fullPreload) { ++ com.android.i18n.system.ZygoteHooks.onBeginPreload(); + +- ICU.initializeCacheInZygote(); ++ ICU.initializeCacheInZygote(); ++ } + + // Look up JaCoCo on the boot classpath, if it exists. This will be used later for enabling + // memory-mapped Java coverage. +@@ -100,7 +102,9 @@ public final class ZygoteHooks { + @SystemApi(client = MODULE_LIBRARIES) + @libcore.api.CorePlatformApi(status = libcore.api.CorePlatformApi.Status.STABLE) + public static void onEndPreload(boolean fullPreload) { +- com.android.i18n.system.ZygoteHooks.onEndPreload(); ++ if (fullPreload) { ++ com.android.i18n.system.ZygoteHooks.onEndPreload(); ++ } + + // Clone standard descriptors as originals closed / rebound during zygote post fork. + FileDescriptor.in.cloneForFork(); diff --git a/Patches/LineageOS-19.1/android_packages_apps_Bluetooth/0001-constify_JNINativeMethod.patch b/Patches/LineageOS-19.1/android_packages_apps_Bluetooth/0001-constify_JNINativeMethod.patch new file mode 100644 index 00000000..0e0a6336 --- /dev/null +++ b/Patches/LineageOS-19.1/android_packages_apps_Bluetooth/0001-constify_JNINativeMethod.patch @@ -0,0 +1,259 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Daniel Micay +Date: Sun, 10 Oct 2021 18:35:08 -0400 +Subject: [PATCH] constify JNINativeMethod tables + +--- + jni/com_android_bluetooth_a2dp.cpp | 2 +- + jni/com_android_bluetooth_a2dp_sink.cpp | 2 +- + jni/com_android_bluetooth_avrcp_controller.cpp | 2 +- + jni/com_android_bluetooth_avrcp_target.cpp | 2 +- + ...om_android_bluetooth_btservice_ActivityAttribution.cpp | 2 +- + jni/com_android_bluetooth_btservice_AdapterService.cpp | 2 +- + jni/com_android_bluetooth_btservice_BluetoothKeystore.cpp | 2 +- + jni/com_android_bluetooth_gatt.cpp | 8 ++++---- + jni/com_android_bluetooth_hearing_aid.cpp | 2 +- + jni/com_android_bluetooth_hfp.cpp | 2 +- + jni/com_android_bluetooth_hfpclient.cpp | 2 +- + jni/com_android_bluetooth_hid_device.cpp | 2 +- + jni/com_android_bluetooth_hid_host.cpp | 2 +- + jni/com_android_bluetooth_le_audio.cpp | 2 +- + jni/com_android_bluetooth_pan.cpp | 2 +- + jni/com_android_bluetooth_sdp.cpp | 2 +- + 16 files changed, 19 insertions(+), 19 deletions(-) + +diff --git a/jni/com_android_bluetooth_a2dp.cpp b/jni/com_android_bluetooth_a2dp.cpp +index a94990437..1f0560860 100644 +--- a/jni/com_android_bluetooth_a2dp.cpp ++++ b/jni/com_android_bluetooth_a2dp.cpp +@@ -505,7 +505,7 @@ static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object, + return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initNative", + "(I[Landroid/bluetooth/BluetoothCodecConfig;[Landroid/bluetooth/BluetoothCodecConfig;)V", +diff --git a/jni/com_android_bluetooth_a2dp_sink.cpp b/jni/com_android_bluetooth_a2dp_sink.cpp +index d7cbeb770..08cd8f419 100644 +--- a/jni/com_android_bluetooth_a2dp_sink.cpp ++++ b/jni/com_android_bluetooth_a2dp_sink.cpp +@@ -243,7 +243,7 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject object, + return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initNative", "(I)V", (void*)initNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_avrcp_controller.cpp b/jni/com_android_bluetooth_avrcp_controller.cpp +index 86bf06879..642f73ea3 100755 +--- a/jni/com_android_bluetooth_avrcp_controller.cpp ++++ b/jni/com_android_bluetooth_avrcp_controller.cpp +@@ -1284,7 +1284,7 @@ static void playItemNative(JNIEnv* env, jobject object, jbyteArray address, + env->ReleaseByteArrayElements(address, addr, 0); + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initNative", "()V", (void*)initNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_avrcp_target.cpp b/jni/com_android_bluetooth_avrcp_target.cpp +index fb8c56086..a7434e365 100644 +--- a/jni/com_android_bluetooth_avrcp_target.cpp ++++ b/jni/com_android_bluetooth_avrcp_target.cpp +@@ -900,7 +900,7 @@ static void setBipClientStatusNative(JNIEnv* env, jobject object, + sServiceInterface->SetBipClientStatus(bdaddr, status); + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initNative", "()V", (void*)initNative}, + {"registerBipServerNative", "(I)V", (void*)registerBipServerNative}, +diff --git a/jni/com_android_bluetooth_btservice_ActivityAttribution.cpp b/jni/com_android_bluetooth_btservice_ActivityAttribution.cpp +index 791e42a0e..cb0082244 100644 +--- a/jni/com_android_bluetooth_btservice_ActivityAttribution.cpp ++++ b/jni/com_android_bluetooth_btservice_ActivityAttribution.cpp +@@ -157,7 +157,7 @@ static void cleanupNative(JNIEnv* env, jobject object) { + } + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initNative", "()V", (void*)initNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_btservice_AdapterService.cpp b/jni/com_android_bluetooth_btservice_AdapterService.cpp +index 62c7d522d..9fa89ded9 100644 +--- a/jni/com_android_bluetooth_btservice_AdapterService.cpp ++++ b/jni/com_android_bluetooth_btservice_AdapterService.cpp +@@ -1689,7 +1689,7 @@ static int getMetricIdNative(JNIEnv* env, jobject obj, jbyteArray address) { + return sBluetoothInterface->get_metric_id(addr_obj); + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + /* name, signature, funcPtr */ + {"classInitNative", "()V", (void*)classInitNative}, + {"initNative", "(ZZI[Ljava/lang/String;Z)Z", (void*)initNative}, +diff --git a/jni/com_android_bluetooth_btservice_BluetoothKeystore.cpp b/jni/com_android_bluetooth_btservice_BluetoothKeystore.cpp +index bceea1d73..6b8a317bc 100644 +--- a/jni/com_android_bluetooth_btservice_BluetoothKeystore.cpp ++++ b/jni/com_android_bluetooth_btservice_BluetoothKeystore.cpp +@@ -155,7 +155,7 @@ static void cleanupNative(JNIEnv* env, jobject object) { + } + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initNative", "()V", (void*)initNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_gatt.cpp b/jni/com_android_bluetooth_gatt.cpp +index 8f996a012..5273bfacd 100644 +--- a/jni/com_android_bluetooth_gatt.cpp ++++ b/jni/com_android_bluetooth_gatt.cpp +@@ -2343,7 +2343,7 @@ static void gattTestNative(JNIEnv* env, jobject object, jint command, + */ + + // JNI functions defined in AdvertiseManager class. +-static JNINativeMethod sAdvertiseMethods[] = { ++static const JNINativeMethod sAdvertiseMethods[] = { + {"classInitNative", "()V", (void*)advertiseClassInitNative}, + {"initializeNative", "()V", (void*)advertiseInitializeNative}, + {"cleanupNative", "()V", (void*)advertiseCleanupNative}, +@@ -2370,7 +2370,7 @@ static JNINativeMethod sAdvertiseMethods[] = { + }; + + // JNI functions defined in PeriodicScanManager class. +-static JNINativeMethod sPeriodicScanMethods[] = { ++static const JNINativeMethod sPeriodicScanMethods[] = { + {"classInitNative", "()V", (void*)periodicScanClassInitNative}, + {"initializeNative", "()V", (void*)periodicScanInitializeNative}, + {"cleanupNative", "()V", (void*)periodicScanCleanupNative}, +@@ -2384,7 +2384,7 @@ static JNINativeMethod sPeriodicScanMethods[] = { + }; + + // JNI functions defined in ScanManager class. +-static JNINativeMethod sScanMethods[] = { ++static const JNINativeMethod sScanMethods[] = { + {"registerScannerNative", "(JJ)V", (void*)registerScannerNative}, + {"unregisterScannerNative", "(I)V", (void*)unregisterScannerNative}, + {"gattClientScanNative", "(Z)V", (void*)gattClientScanNative}, +@@ -2417,7 +2417,7 @@ static JNINativeMethod sScanMethods[] = { + }; + + // JNI functions defined in GattService class. +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initializeNative", "()V", (void*)initializeNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_hearing_aid.cpp b/jni/com_android_bluetooth_hearing_aid.cpp +index e359faf8a..c72b0c915 100644 +--- a/jni/com_android_bluetooth_hearing_aid.cpp ++++ b/jni/com_android_bluetooth_hearing_aid.cpp +@@ -218,7 +218,7 @@ static void setVolumeNative(JNIEnv* env, jclass clazz, jint volume) { + sHearingAidInterface->SetVolume(volume); + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initNative", "()V", (void*)initNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_hfp.cpp b/jni/com_android_bluetooth_hfp.cpp +index 813bdd081..5b21b543b 100644 +--- a/jni/com_android_bluetooth_hfp.cpp ++++ b/jni/com_android_bluetooth_hfp.cpp +@@ -954,7 +954,7 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject object, + return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initializeNative", "(IZ)V", (void*)initializeNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_hfpclient.cpp b/jni/com_android_bluetooth_hfpclient.cpp +index 83c6b20f3..5534b00ff 100644 +--- a/jni/com_android_bluetooth_hfpclient.cpp ++++ b/jni/com_android_bluetooth_hfpclient.cpp +@@ -836,7 +836,7 @@ static jboolean sendATCmdNative(JNIEnv* env, jobject object, jbyteArray address, + return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initializeNative", "()V", (void*)initializeNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_hid_device.cpp b/jni/com_android_bluetooth_hid_device.cpp +index 17b6e97c0..c3a00d5d2 100644 +--- a/jni/com_android_bluetooth_hid_device.cpp ++++ b/jni/com_android_bluetooth_hid_device.cpp +@@ -497,7 +497,7 @@ static jboolean disconnectNative(JNIEnv* env, jobject thiz) { + return result; + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initNative", "()V", (void*)initNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_hid_host.cpp b/jni/com_android_bluetooth_hid_host.cpp +index 074e39d5b..b1116ef47 100644 +--- a/jni/com_android_bluetooth_hid_host.cpp ++++ b/jni/com_android_bluetooth_hid_host.cpp +@@ -506,7 +506,7 @@ static jboolean setIdleTimeNative(JNIEnv* env, jobject object, + return status == BT_STATUS_SUCCESS ? JNI_TRUE : JNI_FALSE; + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initializeNative", "()V", (void*)initializeNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_le_audio.cpp b/jni/com_android_bluetooth_le_audio.cpp +index a8f5dbe1e..11b2a5d09 100644 +--- a/jni/com_android_bluetooth_le_audio.cpp ++++ b/jni/com_android_bluetooth_le_audio.cpp +@@ -261,7 +261,7 @@ static void groupStopNative(JNIEnv* env, jobject object, jint group_id) { + sLeAudioClientInterface->GroupStop(group_id); + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initNative", "()V", (void*)initNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_pan.cpp b/jni/com_android_bluetooth_pan.cpp +index b02ae9f9b..3edc1ad98 100644 +--- a/jni/com_android_bluetooth_pan.cpp ++++ b/jni/com_android_bluetooth_pan.cpp +@@ -215,7 +215,7 @@ static jboolean disconnectPanNative(JNIEnv* env, jobject object, + return ret; + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + {"classInitNative", "()V", (void*)classInitNative}, + {"initializeNative", "()V", (void*)initializeNative}, + {"cleanupNative", "()V", (void*)cleanupNative}, +diff --git a/jni/com_android_bluetooth_sdp.cpp b/jni/com_android_bluetooth_sdp.cpp +index bba109ac4..791ca06f2 100755 +--- a/jni/com_android_bluetooth_sdp.cpp ++++ b/jni/com_android_bluetooth_sdp.cpp +@@ -510,7 +510,7 @@ static void cleanupNative(JNIEnv* env, jobject object) { + } + } + +-static JNINativeMethod sMethods[] = { ++static const JNINativeMethod sMethods[] = { + /* name, signature, funcPtr */ + {"classInitNative", "()V", (void*)classInitNative}, + {"initializeNative", "()V", (void*)initializeNative}, diff --git a/Patches/LineageOS-19.1/android_packages_apps_Dialer/0001-Not_Private_Banner.patch b/Patches/LineageOS-19.1/android_packages_apps_Dialer/0001-Not_Private_Banner.patch new file mode 100644 index 00000000..2792383a --- /dev/null +++ b/Patches/LineageOS-19.1/android_packages_apps_Dialer/0001-Not_Private_Banner.patch @@ -0,0 +1,185 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Torsten Grote +Date: Thu, 18 Jun 2020 13:15:16 -0300 +Subject: [PATCH] Show privacy warning on in-call screen + +Includes: +Author: Chirayu Desai +Date: Tue Jul 28 02:23:37 2020 +0530 + + Move the incall warning back to the center + + * Instead of left/started aligned. + +Change-Id: Ic9b18c110481df7042ca1daa36182e0999fe948f +--- + .../res/drawable/ic_baseline_warning.xml | 9 +++++ + .../dialer/theme/common/res/values/colors.xml | 1 + + .../res/layout/fragment_incoming_call.xml | 7 +++- + .../contactgrid/res/layout/incall_header.xml | 39 +++++++++++++++++++ + .../impl/res/layout/frag_incall_voice.xml | 7 ++++ + .../android/incallui/res/values/strings.xml | 3 ++ + .../incallui/theme/res/values/styles.xml | 4 +- + 7 files changed, 67 insertions(+), 3 deletions(-) + create mode 100644 java/com/android/dialer/common/res/drawable/ic_baseline_warning.xml + create mode 100644 java/com/android/incallui/contactgrid/res/layout/incall_header.xml + +diff --git a/java/com/android/dialer/common/res/drawable/ic_baseline_warning.xml b/java/com/android/dialer/common/res/drawable/ic_baseline_warning.xml +new file mode 100644 +index 000000000..c2baa9bdb +--- /dev/null ++++ b/java/com/android/dialer/common/res/drawable/ic_baseline_warning.xml +@@ -0,0 +1,9 @@ ++ ++ ++ ++ +\ No newline at end of file +diff --git a/java/com/android/dialer/theme/common/res/values/colors.xml b/java/com/android/dialer/theme/common/res/values/colors.xml +index 1831862b1..6f6795cea 100644 +--- a/java/com/android/dialer/theme/common/res/values/colors.xml ++++ b/java/com/android/dialer/theme/common/res/values/colors.xml +@@ -21,6 +21,7 @@ + #D8D8D8 + #2A56C6 + #4285F4 ++ #f3b514 + + + #097138 +diff --git a/java/com/android/incallui/answer/impl/res/layout/fragment_incoming_call.xml b/java/com/android/incallui/answer/impl/res/layout/fragment_incoming_call.xml +index 1672bf984..63de75999 100644 +--- a/java/com/android/incallui/answer/impl/res/layout/fragment_incoming_call.xml ++++ b/java/com/android/incallui/answer/impl/res/layout/fragment_incoming_call.xml +@@ -78,18 +78,23 @@ + android:id="@+id/incall_contact_grid" + android:layout_width="match_parent" + android:layout_height="match_parent" +- android:layout_marginTop="24dp" + android:clipChildren="false" + android:clipToPadding="false" + android:focusable="true" + android:gravity="top|center_horizontal" + android:orientation="vertical"> + ++ ++ + +diff --git a/java/com/android/incallui/contactgrid/res/layout/incall_header.xml b/java/com/android/incallui/contactgrid/res/layout/incall_header.xml +new file mode 100644 +index 000000000..7e8e90e5d +--- /dev/null ++++ b/java/com/android/incallui/contactgrid/res/layout/incall_header.xml +@@ -0,0 +1,39 @@ ++ ++ ++ ++ ++ ++ ++ +diff --git a/java/com/android/incallui/incall/impl/res/layout/frag_incall_voice.xml b/java/com/android/incallui/incall/impl/res/layout/frag_incall_voice.xml +index 9cc599dc7..fac420908 100644 +--- a/java/com/android/incallui/incall/impl/res/layout/frag_incall_voice.xml ++++ b/java/com/android/incallui/incall/impl/res/layout/frag_incall_voice.xml +@@ -29,11 +29,18 @@ + android:clipToPadding="false" + android:fitsSystemWindows="true"> + ++ ++ + + +diff --git a/java/com/android/incallui/res/values/strings.xml b/java/com/android/incallui/res/values/strings.xml +index c18ee495e..a5d08d3ec 100644 +--- a/java/com/android/incallui/res/values/strings.xml ++++ b/java/com/android/incallui/res/values/strings.xml +@@ -212,4 +212,7 @@ + + Join RTT + ++ ++ The location and audio of this call are not private. ++ + +diff --git a/java/com/android/incallui/theme/res/values/styles.xml b/java/com/android/incallui/theme/res/values/styles.xml +index 5b65cc3d9..19e7fdc4f 100644 +--- a/java/com/android/incallui/theme/res/values/styles.xml ++++ b/java/com/android/incallui/theme/res/values/styles.xml +@@ -21,7 +21,7 @@ + Theme.Black.NoTitleBar directly, since we want any popups or dialogs from the + InCallActivity to have the correct Material style. --> +