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

Commit e787a7e5 authored by William Escande's avatar William Escande
Browse files

Change callback name to more meaningfull name

Previously both these method were used to switch from Ble to BrEdr or to
off. The name `onLeServiceUp` is not accurate as the AdapterService is
already sending a "le is up" notification to BluetoothManagerService
with `onBluetoothStateChange(x, BLE_ON)`
Changing the name to not be a callback but the actual action asked to
the adapter, AKA startBrEdr.
Same for onBrEdrDown that will instead be called stopBle

This is a no-op change

Bug: 262605980
Test: None
Change-Id: I7d55925e6a34f7f0a9eb2d0cf338ad5cc74d678f
parent 536fdac3
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
@@ -351,7 +351,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(
@@ -500,7 +500,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 {
@@ -509,12 +509,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();
                    }
@@ -635,7 +635,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());
                            }
@@ -1053,7 +1053,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);
@@ -1211,8 +1211,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() {
@@ -1228,12 +1228,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) {
@@ -1275,10 +1275,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();
            }
@@ -1997,7 +1997,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:
@@ -2514,7 +2514,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