Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
allow users to disable hardened_malloc for Bluetooth app
Browse files Browse the repository at this point in the history
  • Loading branch information
muhomorr authored and thestinger committed Mar 14, 2024
1 parent 3fd0aae commit 5053f47
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
21 changes: 21 additions & 0 deletions core/java/android/ext/BluetoothUtils.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 11 additions & 5 deletions core/java/android/ext/settings/app/AswUseHardenedMalloc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 5053f47

Please sign in to comment.