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

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

Merge "Pipe down init flags to the native stack" am: 7d8e7854

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

Change-Id: I017164dcfdcd0450e75a920f23a29f2d2be3f709
parents 8b80e960 7d8e7854
Loading
Loading
Loading
Loading
+25 −3
Original line number 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,
                       jboolean isNiapMode, int configCompareResult) {
                       jboolean isNiapMode, int configCompareResult,
                       jobjectArray initFlags) {
  ALOGV("%s", __func__);

  android_bluetooth_UidTraffic.clazz =
@@ -694,9 +695,30 @@ static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest,
    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(
      &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) {
    ALOGE("Error while setting the callbacks: %d\n", ret);
    sBluetoothInterface = NULL;
@@ -1312,7 +1334,7 @@ static int getMetricIdNative(JNIEnv* env, jobject obj, jbyteArray address) {
static JNINativeMethod sMethods[] = {
    /* name, signature, funcPtr */
    {"classInitNative", "()V", (void*)classInitNative},
    {"initNative", "(ZZI)Z", (void*)initNative},
    {"initNative", "(ZZI[Ljava/lang/String;)Z", (void*)initNative},
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"enableNative", "()Z", (void*)enableNative},
    {"disableNative", "()Z", (void*)disableNative},
+13 −3
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Base64;
@@ -439,7 +440,7 @@ public class AdapterService extends Service {
        mBluetoothKeystoreService = new BluetoothKeystoreService(isNiapMode());
        mBluetoothKeystoreService.start();
        int configCompareResult = mBluetoothKeystoreService.getCompareResult();
        initNative(isGuest(), isNiapMode(), configCompareResult);
        initNative(isGuest(), isNiapMode(), configCompareResult, getInitFlags());
        mNativeAvailable = true;
        mCallbacks = new RemoteCallbackList<IBluetoothCallback>();
        mAppOps = getSystemService(AppOpsManager.class);
@@ -3008,6 +3009,15 @@ public class AdapterService extends Service {
        return Settings.Global.getInt(getContentResolver(), "niap_mode", 0) == 1;
    }

    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
     *
@@ -3037,8 +3047,8 @@ public class AdapterService extends Service {

    static native void classInitNative();

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

    native void cleanupNative();

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

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

        TestUtils.setAdapterService(mMockAdapterService);