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

Commit 331417bf authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes I7d55925e,I6706588d

* changes:
  Change callback name to more meaningfull name
  BluetoothManagerService test
parents 602dae03 e787a7e5
Loading
Loading
Loading
Loading
+20 −16
Original line number Diff line number Diff line
@@ -4240,23 +4240,25 @@ public class AdapterService extends Service {
        }

        @Override
        public void onLeServiceUp(AttributionSource source, SynchronousResultReceiver receiver) {
        public void startBrEdr(AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                onLeServiceUp(source);
                startBrEdr(source);
                receiver.send(null);
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @VisibleForTesting
        @RequiresPermission(allOf = {
        @RequiresPermission(
                allOf = {
                    android.Manifest.permission.BLUETOOTH_CONNECT,
                    android.Manifest.permission.BLUETOOTH_PRIVILEGED,
                })
        void onLeServiceUp(AttributionSource source) {
        void startBrEdr(AttributionSource source) {
            AdapterService service = getService();
            if (service == null
                    || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onLeServiceUp")
                    || !callerIsSystemOrActiveOrManagedUser(service, TAG, "startBrEdr")
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                return;
            }
@@ -4267,23 +4269,25 @@ public class AdapterService extends Service {
        }

        @Override
        public void onBrEdrDown(AttributionSource source, SynchronousResultReceiver receiver) {
        public void stopBle(AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                onBrEdrDown(source);
                stopBle(source);
                receiver.send(null);
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        @VisibleForTesting
        @RequiresPermission(allOf = {
        @RequiresPermission(
                allOf = {
                    android.Manifest.permission.BLUETOOTH_CONNECT,
                    android.Manifest.permission.BLUETOOTH_PRIVILEGED,
                })
        void onBrEdrDown(AttributionSource source) {
        void stopBle(AttributionSource source) {
            AdapterService service = getService();
            if (service == null
                    || !callerIsSystemOrActiveOrManagedUser(service, TAG, "onBrEdrDown")
                    || !callerIsSystemOrActiveOrManagedUser(service, TAG, "stopBle")
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                return;
            }
+1 −1
Original line number Diff line number Diff line
@@ -374,7 +374,7 @@ public class AdapterServiceFactoryResetTest {
        verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON,
                invocationNumber + 1, NATIVE_INIT_MS);

        mServiceBinder.onLeServiceUp(mAttributionSource);
        mServiceBinder.startBrEdr(mAttributionSource);

        verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_TURNING_ON,
                invocationNumber + 1, CONTEXT_SWITCH_MS);
+9 −6
Original line number Diff line number Diff line
@@ -382,7 +382,7 @@ public class AdapterServiceTest {
        verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON,
                invocationNumber + 1, NATIVE_INIT_MS);

        mServiceBinder.onLeServiceUp(mAttributionSource);
        mServiceBinder.startBrEdr(mAttributionSource);

        verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_TURNING_ON,
                invocationNumber + 1, CONTEXT_SWITCH_MS);
@@ -435,7 +435,7 @@ public class AdapterServiceTest {
        verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON,
                invocationNumber + 1, PROFILE_SERVICE_TOGGLE_TIME_MS);

        mServiceBinder.onBrEdrDown(mAttributionSource);
        mServiceBinder.stopBle(mAttributionSource);

        verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF,
                invocationNumber + 1, CONTEXT_SWITCH_MS);
@@ -560,7 +560,7 @@ public class AdapterServiceTest {
        verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON, 1,
                CONTEXT_SWITCH_MS);

        mServiceBinder.onBrEdrDown(mAttributionSource);
        mServiceBinder.stopBle(mAttributionSource);

        verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, 1,
                CONTEXT_SWITCH_MS);
@@ -595,7 +595,7 @@ public class AdapterServiceTest {
        verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_ON, BluetoothAdapter.STATE_BLE_ON, 1,
                NATIVE_INIT_MS);

        mServiceBinder.onLeServiceUp(mAttributionSource);
        mServiceBinder.startBrEdr(mAttributionSource);

        verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_TURNING_ON, 1,
                CONTEXT_SWITCH_MS);
@@ -684,9 +684,12 @@ public class AdapterServiceTest {
        verifyStateChange(BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_BLE_ON, 1,
                CONTEXT_SWITCH_MS);

        // Don't call onBrEdrDown().  The Adapter should turn itself off.
        // Don't call stopBle().  The Adapter should turn itself off.

        verifyStateChange(BluetoothAdapter.STATE_BLE_ON, BluetoothAdapter.STATE_BLE_TURNING_OFF, 1,
        verifyStateChange(
                BluetoothAdapter.STATE_BLE_ON,
                BluetoothAdapter.STATE_BLE_TURNING_OFF,
                1,
                CONTEXT_SWITCH_MS);

        // Stop GATT
+4 −4
Original line number Diff line number Diff line
@@ -64,16 +64,16 @@ class AdapterBinder(rawBinder: IBinder) {
    }

    @Throws(RemoteException::class, TimeoutException::class)
    fun onBrEdrDown(source: AttributionSource) {
    fun stopBle(source: AttributionSource) {
        val recv: SynchronousResultReceiver<Any> = SynchronousResultReceiver.get()
        adapterBinder.onBrEdrDown(source, recv)
        adapterBinder.stopBle(source, recv)
        recv.awaitResultNoInterrupt(SYNC_TIMEOUT).getValue(null)
    }

    @Throws(RemoteException::class, TimeoutException::class)
    fun onLeServiceUp(source: AttributionSource) {
    fun startBrEdr(source: AttributionSource) {
        val recv: SynchronousResultReceiver<Any> = SynchronousResultReceiver.get()
        adapterBinder.onLeServiceUp(source, recv)
        adapterBinder.startBrEdr(source, recv)
        recv.awaitResultNoInterrupt(SYNC_TIMEOUT).getValue(null)
    }

+14 −14
Original line number Diff line number Diff line
@@ -354,7 +354,7 @@ class BluetoothManagerService {
                        BluetoothProtoEnums.ENABLE_DISABLE_REASON_FACTORY_RESET,
                        mContext.getPackageName(),
                        false);
                mAdapter.onBrEdrDown(source);
                mAdapter.stopBle(source);
                return true;
            } else if (state == STATE_ON) {
                addActiveLog(
@@ -503,7 +503,7 @@ class BluetoothManagerService {
                // Clear registered LE apps to force shut-off
                clearBleApps();

                // If state is BLE_ON make sure we trigger disableBLE
                // If state is BLE_ON make sure we trigger stopBle
                if (st == STATE_BLE_ON) {
                    mAdapterLock.readLock().lock();
                    try {
@@ -512,12 +512,12 @@ class BluetoothManagerService {
                                    BluetoothProtoEnums.ENABLE_DISABLE_REASON_AIRPLANE_MODE,
                                    mContext.getPackageName(),
                                    false);
                            mAdapter.onBrEdrDown(mContext.getAttributionSource());
                            mAdapter.stopBle(mContext.getAttributionSource());
                            mEnable = false;
                            mEnableExternal = false;
                        }
                    } catch (RemoteException | TimeoutException e) {
                        Log.e(TAG, "Unable to call onBrEdrDown", e);
                        Log.e(TAG, "Unable to call stopBle", e);
                    } finally {
                        mAdapterLock.readLock().unlock();
                    }
@@ -638,7 +638,7 @@ class BluetoothManagerService {
                            mEnable = false;
                            mEnableExternal = false;
                            if (mAdapter != null && mState.oneOf(STATE_BLE_ON)) {
                                mAdapter.onBrEdrDown(mContext.getAttributionSource());
                                mAdapter.stopBle(mContext.getAttributionSource());
                            } else if (mAdapter != null && mState.oneOf(STATE_ON)) {
                                mAdapter.disable(mContext.getAttributionSource());
                            }
@@ -1056,7 +1056,7 @@ class BluetoothManagerService {
                                                .ENABLE_DISABLE_REASON_APPLICATION_REQUEST,
                                        mContext.getPackageName(),
                                        false);
                                mAdapter.onBrEdrDown(mContext.getAttributionSource());
                                mAdapter.stopBle(mContext.getAttributionSource());
                            }
                        } catch (RemoteException | TimeoutException e) {
                            Log.e(TAG, "error when disabling bluetooth", e);
@@ -1214,8 +1214,8 @@ class BluetoothManagerService {
    }

    /**
     * Call IBluetooth.onLeServiceUp() to continue if Bluetooth should be on, call
     * IBluetooth.onBrEdrDown() to disable if Bluetooth should be off.
     * Will call startBrEdr() if bluetooth classic should be on and will call stopBle if bluetooth
     * BLE should be off
     */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
    private void continueFromBleOnState() {
@@ -1231,12 +1231,12 @@ class BluetoothManagerService {
            if (!mEnableExternal && !isBleAppPresent()) {
                Log.i(TAG, "Bluetooth was disabled while enabling BLE, disable BLE now");
                mEnable = false;
                mAdapter.onBrEdrDown(mContext.getAttributionSource());
                mAdapter.stopBle(mContext.getAttributionSource());
                return;
            }
            if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) {
                // This triggers transition to STATE_ON
                mAdapter.onLeServiceUp(mContext.getAttributionSource());
                mAdapter.startBrEdr(mContext.getAttributionSource());
                persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH);
            }
        } catch (RemoteException | TimeoutException e) {
@@ -1278,10 +1278,10 @@ class BluetoothManagerService {
            mAdapterLock.readLock().lock();
            try {
                if (mAdapter != null) {
                    mAdapter.onBrEdrDown(source);
                    mAdapter.stopBle(source);
                }
            } catch (RemoteException | TimeoutException e) {
                Log.e(TAG, "Call to onBrEdrDown() failed.", e);
                Log.e(TAG, "Call to stopBle() failed.", e);
            } finally {
                mAdapterLock.readLock().unlock();
            }
@@ -1978,7 +1978,7 @@ class BluetoothManagerService {
                                        Log.i(TAG, "Already at BLE_ON State");
                                    } else {
                                        Log.w(TAG, "BT Enable in BLE_ON State, going to ON");
                                        mAdapter.onLeServiceUp(mContext.getAttributionSource());
                                        mAdapter.startBrEdr(mContext.getAttributionSource());
                                    }
                                    break;
                                case STATE_BLE_TURNING_ON:
@@ -2495,7 +2495,7 @@ class BluetoothManagerService {
            mState.set(STATE_OFF);
            // enable
            addActiveLog(reason, mContext.getPackageName(), true);
            // mEnable flag could have been reset on disableBLE. Reenable it.
            // mEnable flag could have been reset on stopBle. Reenable it.
            mEnable = true;
            handleEnable(mQuietEnable);
        }
Loading