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

Commit dedb69bd authored by Martin Brabham's avatar Martin Brabham
Browse files

NIAP: Add new argument to determine single user mode status.

Bug: 117993149
Test: atest BluetoothInstrumentationTests
Change-Id: Iae9b94d6b5ae10b8303b30cbbabbfa80470f8e7f
parent 09a68500
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -683,7 +683,8 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
  }
}

static bool initNative(JNIEnv* env, jobject obj) {
static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest,
                       jboolean isSingleUserMode) {
  ALOGV("%s", __func__);

  android_bluetooth_UidTraffic.clazz =
@@ -697,7 +698,9 @@ static bool initNative(JNIEnv* env, jobject obj) {
    return JNI_FALSE;
  }

  int ret = sBluetoothInterface->init(&sBluetoothCallbacks);
  int ret = sBluetoothInterface->init(&sBluetoothCallbacks,
                                      isGuest == JNI_TRUE ? 1 : 0,
                                      isSingleUserMode == JNI_TRUE ? 1 : 0);
  if (ret != BT_STATUS_SUCCESS) {
    ALOGE("Error while setting the callbacks: %d\n", ret);
    sBluetoothInterface = NULL;
@@ -750,11 +753,11 @@ static bool cleanupNative(JNIEnv* env, jobject obj) {
  return JNI_TRUE;
}

static jboolean enableNative(JNIEnv* env, jobject obj, jboolean isGuest) {
static jboolean enableNative(JNIEnv* env, jobject obj) {
  ALOGV("%s", __func__);

  if (!sBluetoothInterface) return JNI_FALSE;
  int ret = sBluetoothInterface->enable(isGuest == JNI_TRUE ? 1 : 0);
  int ret = sBluetoothInterface->enable();
  return (ret == BT_STATUS_SUCCESS || ret == BT_STATUS_DONE) ? JNI_TRUE
                                                             : JNI_FALSE;
}
@@ -1237,9 +1240,9 @@ static jbyteArray obfuscateAddressNative(JNIEnv* env, jobject obj,
static JNINativeMethod sMethods[] = {
    /* name, signature, funcPtr */
    {"classInitNative", "()V", (void*)classInitNative},
    {"initNative", "()Z", (void*)initNative},
    {"initNative", "(ZZ)Z", (void*)initNative},
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"enableNative", "(Z)Z", (void*)enableNative},
    {"enableNative", "()Z", (void*)enableNative},
    {"disableNative", "()Z", (void*)disableNative},
    {"setAdapterPropertyNative", "(I[B)Z", (void*)setAdapterPropertyNative},
    {"getAdapterPropertiesNative", "()Z", (void*)getAdapterPropertiesNative},
+10 −9
Original line number Diff line number Diff line
@@ -286,7 +286,7 @@ public class AdapterService extends Service {
                    }
                    mRunningProfiles.add(profile);
                    if (GattService.class.getSimpleName().equals(profile.getName())) {
                        enableNativeWithGuestFlag();
                        enableNative();
                    } else if (mRegisteredProfiles.size() == Config.getSupportedProfiles().length
                            && mRegisteredProfiles.size() == mRunningProfiles.size()) {
                        mAdapterProperties.onBluetoothReady();
@@ -393,7 +393,7 @@ public class AdapterService extends Service {
        mAdapterProperties = new AdapterProperties(this);
        mAdapterStateMachine = AdapterState.make(this);
        mJniCallbacks = new JniCallbacks(this, mAdapterProperties);
        initNative();
        initNative(isGuest(), isSingleUserMode());
        mNativeAvailable = true;
        mCallbacks = new RemoteCallbackList<IBluetoothCallback>();
        mAppOps = getSystemService(AppOpsManager.class);
@@ -2853,11 +2853,12 @@ public class AdapterService extends Service {
        }
    };

    private void enableNativeWithGuestFlag() {
        boolean isGuest = UserManager.get(this).isGuestUser();
        if (!enableNative(isGuest)) {
            Log.e(TAG, "enableNative() returned false");
    private boolean isGuest() {
        return UserManager.get(this).isGuestUser();
    }

    private boolean isSingleUserMode() {
        return UserManager.get(this).hasUserRestriction(UserManager.DISALLOW_ADD_USER);
    }

    /**
@@ -2876,12 +2877,12 @@ public class AdapterService extends Service {

    static native void classInitNative();

    native boolean initNative();
    native boolean initNative(boolean startRestricted, boolean isSingleUserMode);

    native void cleanupNative();

    /*package*/
    native boolean enableNative(boolean startRestricted);
    native boolean enableNative();

    /*package*/
    native boolean disableNative();
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public class AdapterServiceTest {
        }
        Assert.assertNotNull(Looper.myLooper());
        AdapterService adapterService = new AdapterService();
        adapterService.initNative();
        adapterService.initNative(false /* is_restricted */, false /* is_single_user_mode */);
        adapterService.cleanupNative();
        HashMap<String, HashMap<String, String>> adapterConfig = TestUtils.readAdapterConfig();
        Assert.assertNotNull(adapterConfig);
+1 −1
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ public class ProfileServiceTest {

        mProfiles = Config.getSupportedProfiles();

        mMockAdapterService.initNative();
        mMockAdapterService.initNative(false /* is_restricted */, false /* is_single_user_mode */);

        TestUtils.setAdapterService(mMockAdapterService);