Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b32f30e3 authored by Zach Johnson's avatar Zach Johnson Committed by Automerger Merge Worker
Browse files

Pipe down init flags to the native stack am: cc08b05b

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/11727028

Change-Id: Ia08a688256b8830b969a238598f10f6f2a88f9c9
parents 3e96a228 cc08b05b
Loading
Loading
Loading
Loading
+25 −3
Original line number Original line Diff line number Diff line
@@ -680,7 +680,8 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
}
}


static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest,
static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest,
                       jboolean isNiapMode, int configCompareResult) {
                       jboolean isNiapMode, int configCompareResult,
                       jobjectArray initFlags) {
  ALOGV("%s", __func__);
  ALOGV("%s", __func__);


  android_bluetooth_UidTraffic.clazz =
  android_bluetooth_UidTraffic.clazz =
@@ -694,9 +695,30 @@ static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest,
    return JNI_FALSE;
    return JNI_FALSE;
  }
  }


  int flagCount = env->GetArrayLength(initFlags);
  jstring* flagObjs = new jstring[flagCount];
  const char** flags = nullptr;
  if (flagCount > 0) {
    flags = new const char*[flagCount + 1];
    flags[flagCount] = nullptr;
  }

  for (int i = 0; i < flagCount; i++) {
    flagObjs[i] = (jstring)env->GetObjectArrayElement(initFlags, i);
    flags[i] = env->GetStringUTFChars(flagObjs[i], NULL);
  }

  int ret = sBluetoothInterface->init(
  int ret = sBluetoothInterface->init(
      &sBluetoothCallbacks, isGuest == JNI_TRUE ? 1 : 0,
      &sBluetoothCallbacks, isGuest == JNI_TRUE ? 1 : 0,
      isNiapMode == JNI_TRUE ? 1 : 0, configCompareResult);
      isNiapMode == JNI_TRUE ? 1 : 0, configCompareResult, flags);

  for (int i = 0; i < flagCount; i++) {
    env->ReleaseStringUTFChars(flagObjs[i], flags[i]);
  }

  delete[] flags;
  delete[] flagObjs;

  if (ret != BT_STATUS_SUCCESS) {
  if (ret != BT_STATUS_SUCCESS) {
    ALOGE("Error while setting the callbacks: %d\n", ret);
    ALOGE("Error while setting the callbacks: %d\n", ret);
    sBluetoothInterface = NULL;
    sBluetoothInterface = NULL;
@@ -1312,7 +1334,7 @@ static int getMetricIdNative(JNIEnv* env, jobject obj, jbyteArray address) {
static JNINativeMethod sMethods[] = {
static JNINativeMethod sMethods[] = {
    /* name, signature, funcPtr */
    /* name, signature, funcPtr */
    {"classInitNative", "()V", (void*)classInitNative},
    {"classInitNative", "()V", (void*)classInitNative},
    {"initNative", "(ZZI)Z", (void*)initNative},
    {"initNative", "(ZZI[Ljava/lang/String;)Z", (void*)initNative},
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"enableNative", "()Z", (void*)enableNative},
    {"enableNative", "()Z", (void*)enableNative},
    {"disableNative", "()Z", (void*)disableNative},
    {"disableNative", "()Z", (void*)disableNative},
+13 −3
Original line number Original line Diff line number Diff line
@@ -71,6 +71,7 @@ import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Base64;
@@ -441,7 +442,7 @@ public class AdapterService extends Service {
        mBluetoothKeystoreService = new BluetoothKeystoreService(isNiapMode());
        mBluetoothKeystoreService = new BluetoothKeystoreService(isNiapMode());
        mBluetoothKeystoreService.start();
        mBluetoothKeystoreService.start();
        int configCompareResult = mBluetoothKeystoreService.getCompareResult();
        int configCompareResult = mBluetoothKeystoreService.getCompareResult();
        initNative(isGuest(), isNiapMode(), configCompareResult);
        initNative(isGuest(), isNiapMode(), configCompareResult, getInitFlags());
        mNativeAvailable = true;
        mNativeAvailable = true;
        mCallbacks = new RemoteCallbackList<IBluetoothCallback>();
        mCallbacks = new RemoteCallbackList<IBluetoothCallback>();
        mAppOps = getSystemService(AppOpsManager.class);
        mAppOps = getSystemService(AppOpsManager.class);
@@ -3052,6 +3053,15 @@ public class AdapterService extends Service {
                .isCommonCriteriaModeEnabled(null);
                .isCommonCriteriaModeEnabled(null);
    }
    }


    private static final String GD_CORE_FLAG = "INIT_gd_core";
    private String[] getInitFlags() {
        ArrayList<String> initFlags = new ArrayList<>();
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_CORE_FLAG, false)) {
            initFlags.add(GD_CORE_FLAG);
        }
        return initFlags.toArray(new String[0]);
    }

    /**
    /**
     *  Obfuscate Bluetooth MAC address into a PII free ID string
     *  Obfuscate Bluetooth MAC address into a PII free ID string
     *
     *
@@ -3081,8 +3091,8 @@ public class AdapterService extends Service {


    static native void classInitNative();
    static native void classInitNative();


    native boolean initNative(boolean startRestricted, boolean isNiapMode,
    native boolean initNative(boolean startRestricted, boolean isNiapMode, int configCompareResult,
            int configCompareResult);
            String[] initFlags);


    native void cleanupNative();
    native void cleanupNative();


+1 −1
Original line number Original line Diff line number Diff line
@@ -109,7 +109,7 @@ public class AdapterServiceTest {
        Assert.assertNotNull(Looper.myLooper());
        Assert.assertNotNull(Looper.myLooper());
        AdapterService adapterService = new AdapterService();
        AdapterService adapterService = new AdapterService();
        adapterService.initNative(false /* is_restricted */, false /* is_niap_mode */,
        adapterService.initNative(false /* is_restricted */, false /* is_niap_mode */,
                0 /* config_compare_result */);
                0 /* config_compare_result */, new String[0]);
        adapterService.cleanupNative();
        adapterService.cleanupNative();
        HashMap<String, HashMap<String, String>> adapterConfig = TestUtils.readAdapterConfig();
        HashMap<String, HashMap<String, String>> adapterConfig = TestUtils.readAdapterConfig();
        Assert.assertNotNull(adapterConfig);
        Assert.assertNotNull(adapterConfig);
+1 −1
Original line number Original line Diff line number Diff line
@@ -97,7 +97,7 @@ public class ProfileServiceTest {
        mProfiles = Config.getSupportedProfiles();
        mProfiles = Config.getSupportedProfiles();


        mMockAdapterService.initNative(false /* is_restricted */, false /* is_niap_mode */,
        mMockAdapterService.initNative(false /* is_restricted */, false /* is_niap_mode */,
                0 /* config_compare_result */);
                0 /* config_compare_result */, new String[0]);


        TestUtils.setAdapterService(mMockAdapterService);
        TestUtils.setAdapterService(mMockAdapterService);