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

Commit 8ba42e6b authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "SystemServer: One unique method to call StopBle" into main

parents ffb2cac3 de91e69b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -227,8 +227,8 @@ interface IBluetooth

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    oneway void startBrEdr(in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    oneway void stopBle(in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    oneway void bleOnToOff(in AttributionSource attributionSource);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED,android.Manifest.permission.MODIFY_PHONE_STATE})")
    int connectAllEnabledProfiles(in BluetoothDevice device, in AttributionSource attributionSource);
+4 −5
Original line number Diff line number Diff line
@@ -3814,17 +3814,16 @@ public class AdapterService extends Service {
        }

        @Override
        public void stopBle(AttributionSource source) {
        public void bleOnToOff(AttributionSource source) {
            AdapterService service = getService();
            if (service == null
                    || !callerIsSystemOrActiveOrManagedUser(service, TAG, "stopBle")
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                    || !callerIsSystemOrActiveOrManagedUser(service, TAG, "bleOnToOff")) {
                return;
            }

            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);

            service.stopBle();
            service.bleOnToOff();
        }

        @Override
@@ -5767,7 +5766,7 @@ public class AdapterService extends Service {
    }

    @VisibleForTesting
    void stopBle() {
    void bleOnToOff() {
        mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_OFF);
    }

+4 −4
Original line number Diff line number Diff line
@@ -540,7 +540,7 @@ public class AdapterServiceTest {

        onToBleOn(looper, adapter, ctx, callback, onlyGatt, services);

        adapter.stopBle();
        adapter.bleOnToOff();
        TestUtils.syncHandler(looper, AdapterState.BLE_TURN_OFF);
        verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF);

@@ -661,7 +661,7 @@ public class AdapterServiceTest {
                false,
                listOfMockServices());

        mAdapterService.stopBle();
        mAdapterService.bleOnToOff();
        syncHandler(AdapterState.BLE_TURN_OFF);
        verifyStateChange(STATE_BLE_ON, STATE_BLE_TURNING_OFF, CONTEXT_SWITCH_MS);
        assertThat(mAdapterService.getBluetoothGatt()).isNull();
@@ -723,7 +723,7 @@ public class AdapterServiceTest {
        assertThat(mAdapterService.getBluetoothScan()).isNotNull();
        assertThat(mAdapterService.getBluetoothGatt()).isNull();

        mAdapterService.stopBle();
        mAdapterService.bleOnToOff();
        syncHandler(AdapterState.BLE_TURN_OFF);
        verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF);

@@ -910,7 +910,7 @@ public class AdapterServiceTest {
                false,
                listOfMockServices());

        // Do not call stopBle().  The Adapter should turn itself off.
        // Do not call bleOnToOff().  The Adapter should turn itself off.
        syncHandler(AdapterState.BLE_TURN_OFF);
        verifyStateChange(STATE_BLE_ON, STATE_BLE_TURNING_OFF, CONTEXT_SWITCH_MS);

+2 −2
Original line number Diff line number Diff line
@@ -54,8 +54,8 @@ class AdapterBinder(rawBinder: IBinder) {
    }

    @Throws(RemoteException::class)
    fun stopBle(source: AttributionSource) {
        adapterBinder.stopBle(source)
    fun bleOnToOff(source: AttributionSource) {
        adapterBinder.bleOnToOff(source)
    }

    @Throws(RemoteException::class)
+25 −23
Original line number Diff line number Diff line
@@ -269,15 +269,13 @@ class BluetoothManagerService {
            }
            if (state == STATE_BLE_ON) {
                ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false);
                mAdapter.stopBle(mContext.getAttributionSource());
                bleOnToOff();
                return true;
            } else if (state == STATE_ON) {
                ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false);
                onToBleOn();
                return true;
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to shutdown Bluetooth", e);
        } finally {
            mAdapterLock.readLock().unlock();
        }
@@ -417,14 +415,13 @@ class BluetoothManagerService {
            // If currentState is BLE_ON make sure we trigger stopBle
            mAdapterLock.readLock().lock();
            try {
                if (mAdapter != null) {
                if (mAdapter == null) {
                    return;
                }
                mEnable = false;
                mEnableExternal = false;
                ActiveLogs.add(reason, false);
                    mAdapter.stopBle(mContext.getAttributionSource());
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Unable to call stopBle", e);
                bleOnToOff();
            } finally {
                mAdapterLock.readLock().unlock();
            }
@@ -550,12 +547,10 @@ class BluetoothManagerService {
                                return;
                            }
                            if (mState.oneOf(STATE_BLE_ON)) {
                                mAdapter.stopBle(mContext.getAttributionSource());
                                bleOnToOff();
                            } else if (mState.oneOf(STATE_ON)) {
                                onToBleOn();
                            }
                        } catch (RemoteException e) {
                            Log.e(TAG, "Unable to shutdown Bluetooth", e);
                        } finally {
                            mAdapterLock.readLock().unlock();
                        }
@@ -667,11 +662,7 @@ class BluetoothManagerService {
        }
        if (mState.oneOf(STATE_BLE_ON)) {
            Log.i(TAG, "onBleScanDisabled: Shutting down BLE_ON mode");
            try {
                mAdapter.stopBle(mContext.getAttributionSource());
            } catch (RemoteException e) {
                Log.e(TAG, "onBleScanDisabled: stopBle failed", e);
            }
            bleOnToOff();
        } else {
            Log.i(TAG, "onBleScanDisabled: Bluetooth is not in BLE_ON, staying on");
        }
@@ -914,10 +905,8 @@ class BluetoothManagerService {
                        try {
                            if (mAdapter != null) {
                                ActiveLogs.add(ENABLE_DISABLE_REASON_APPLICATION_REQUEST, false);
                                mAdapter.stopBle(mContext.getAttributionSource());
                                bleOnToOff();
                            }
                        } catch (RemoteException e) {
                            Log.e(TAG, "error when disabling bluetooth", e);
                        } finally {
                            mAdapterLock.readLock().unlock();
                        }
@@ -1074,7 +1063,7 @@ class BluetoothManagerService {
                // enableBle & disableBle are executed on the handler
                Log.i(TAG, "continueFromBleOnState: Disabled while enabling BLE, disable BLE now");
                mEnable = false;
                mAdapter.stopBle(mContext.getAttributionSource());
                bleOnToOff();
                return;
            }
            if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) {
@@ -1113,7 +1102,7 @@ class BluetoothManagerService {
                mAdapter.unregAllGattClient(mContext.getAttributionSource());
            } else {
                Log.i(TAG, "sendBrEdrDownCallback: Stopping ble");
                mAdapter.stopBle(mContext.getAttributionSource());
                bleOnToOff();
            }
        } catch (RemoteException e) {
            Log.e(TAG, "sendBrEdrDownCallback: Call to mAdapter failed.", e);
@@ -2047,6 +2036,19 @@ class BluetoothManagerService {
        }
    }

    private void bleOnToOff() {
        if (!mState.oneOf(STATE_BLE_ON)) {
            Log.d(TAG, "bleOnToOff: Impossible transition from " + mState);
            return;
        }
        Log.d(TAG, "bleOnToOff: Sending request");
        try {
            mAdapter.bleOnToOff(mContext.getAttributionSource());
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to call bleOnToOff()", e);
        }
    }

    private void broadcastIntentStateChange(String action, int prevState, int newState) {
        Log.d(
                TAG,