From 5053f4720450bbb072d9ea48d6a56e76e8637a84 Mon Sep 17 00:00:00 2001 From: Dmitry Muhomor Date: Thu, 14 Mar 2024 17:09:50 +0200 Subject: [PATCH] allow users to disable hardened_malloc for Bluetooth app --- core/java/android/ext/BluetoothUtils.java | 21 +++++++++++++++++++ .../settings/app/AswUseHardenedMalloc.java | 16 +++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 core/java/android/ext/BluetoothUtils.java diff --git a/core/java/android/ext/BluetoothUtils.java b/core/java/android/ext/BluetoothUtils.java new file mode 100644 index 000000000000..e85357efdaf7 --- /dev/null +++ b/core/java/android/ext/BluetoothUtils.java @@ -0,0 +1,21 @@ +package android.ext; + +import android.content.Context; +import android.ext.settings.BoolSysProperty; + +import com.android.internal.R; + +/** @hide */ +public class BluetoothUtils { + private static volatile String bluetoothStackPackageName; + + public static String getBluetoothStackPackageName(Context ctx) { + String cache = bluetoothStackPackageName; + if (cache != null) { + return cache; + } + String res = ctx.getString(R.string.config_systemBluetoothStack); + bluetoothStackPackageName = res; + return res; + } +} diff --git a/core/java/android/ext/settings/app/AswUseHardenedMalloc.java b/core/java/android/ext/settings/app/AswUseHardenedMalloc.java index 64cdea3f7b16..515cba32bf9e 100644 --- a/core/java/android/ext/settings/app/AswUseHardenedMalloc.java +++ b/core/java/android/ext/settings/app/AswUseHardenedMalloc.java @@ -5,9 +5,12 @@ import android.content.pm.ApplicationInfo; import android.content.pm.GosPackageState; import android.content.pm.GosPackageStateBase; +import android.ext.BluetoothUtils; import com.android.server.os.nano.AppCompatProtos; +import java.util.Objects; + import dalvik.system.VMRuntime; /** @hide */ @@ -23,6 +26,14 @@ private AswUseHardenedMalloc() { @Override public Boolean getImmutableValue(Context ctx, int userId, ApplicationInfo appInfo, @Nullable GosPackageStateBase ps, StateInfo si) { + if (appInfo.isSystemApp()) { + if (Objects.equals(appInfo.packageName, BluetoothUtils.getBluetoothStackPackageName(ctx))) { + return null; + } + si.immutabilityReason = IR_IS_SYSTEM_APP; + return true; + } + String primaryAbi = appInfo.primaryCpuAbi; if (primaryAbi == null) { si.immutabilityReason = IR_NO_NATIVE_CODE; @@ -42,11 +53,6 @@ public Boolean getImmutableValue(Context ctx, int userId, ApplicationInfo appInf return true; } - if (appInfo.isSystemApp()) { - si.immutabilityReason = IR_IS_SYSTEM_APP; - return true; - } - if (ps != null && ps.hasFlags(GosPackageState.FLAG_ENABLE_EXPLOIT_PROTECTION_COMPAT_MODE)) { si.immutabilityReason = IR_EXPLOIT_PROTECTION_COMPAT_MODE; return false;