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

Commit 6c3f9ab1 authored by William Escande's avatar William Escande
Browse files

SystemServer: One unique method to call Disable

Bug: 311772251
Test: None
Flag: Exempt refactor
Change-Id: Iad84fcf4228cb1269fb0350a6108a9ed82184d56
parent 9377a19e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -51,8 +51,8 @@ interface IBluetooth

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    oneway void offToBleOn(boolean quietMode, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    oneway void disable(in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    oneway void onToBleOn(in AttributionSource attributionSource);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.LOCAL_MAC_ADDRESS})")
    String getAddress(in AttributionSource attributionSource);
+7 −7
Original line number Diff line number Diff line
@@ -2307,16 +2307,16 @@ public class AdapterService extends Service {
        }

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

            service.disable();
            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);

            service.onToBleOn();
        }

        @Override
@@ -4600,8 +4600,8 @@ public class AdapterService extends Service {
        mAdapterStateMachine.sendMessage(AdapterState.BLE_TURN_ON);
    }

    void disable() {
        Log.d(TAG, "disable() called with mRunningProfiles.size() = " + mRunningProfiles.size());
    void onToBleOn() {
        Log.d(TAG, "onToBleOn() called with mRunningProfiles.size() = " + mRunningProfiles.size());
        mAdapterStateMachine.sendMessage(AdapterState.USER_TURN_OFF);
    }

+3 −3
Original line number Diff line number Diff line
@@ -435,7 +435,7 @@ public class AdapterServiceTest {
            IBluetoothCallback callback,
            boolean onlyGatt,
            List<ProfileService> services) {
        adapter.disable();
        adapter.onToBleOn();
        TestUtils.syncHandler(looper, AdapterState.USER_TURN_OFF);
        verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF);

@@ -789,7 +789,7 @@ public class AdapterServiceTest {

        assertThat(mAdapterService.getState()).isEqualTo(STATE_ON);

        mAdapterService.disable();
        mAdapterService.onToBleOn();
        TestUtils.syncHandler(mLooper, AdapterState.USER_TURN_OFF);
        verifyStateChange(callback, STATE_ON, STATE_TURNING_OFF);

@@ -858,7 +858,7 @@ public class AdapterServiceTest {
    public void testProfileStopTimeout() {
        doEnable(false);

        mAdapterService.disable();
        mAdapterService.onToBleOn();
        syncHandler(AdapterState.USER_TURN_OFF);
        verifyStateChange(STATE_ON, STATE_TURNING_OFF);
        assertThat(mAdapterService.mSetProfileServiceStateCounter).isEqualTo(4);
+2 −2
Original line number Diff line number Diff line
@@ -34,8 +34,8 @@ class AdapterBinder(rawBinder: IBinder) {
            "]"

    @Throws(RemoteException::class)
    fun disable(source: AttributionSource) {
        adapterBinder.disable(source)
    fun onToBleOn(source: AttributionSource) {
        adapterBinder.onToBleOn(source)
    }

    @Throws(RemoteException::class)
+25 −24
Original line number Diff line number Diff line
@@ -273,7 +273,7 @@ class BluetoothManagerService {
                return true;
            } else if (state == STATE_ON) {
                ActiveLogs.add(ENABLE_DISABLE_REASON_FACTORY_RESET, false);
                mAdapter.disable(mContext.getAttributionSource());
                onToBleOn();
                return true;
            }
        } catch (RemoteException e) {
@@ -404,13 +404,12 @@ class BluetoothManagerService {
        if (currentState == STATE_ON) {
            mAdapterLock.readLock().lock();
            try {
                if (mAdapter != null) {
                if (mAdapter == null) {
                    return;
                }
                mEnable = false;
                ActiveLogs.add(reason, false);
                    mAdapter.disable(mContext.getAttributionSource());
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Unable to call disable", e);
                onToBleOn();
            } finally {
                mAdapterLock.readLock().unlock();
            }
@@ -547,10 +546,13 @@ class BluetoothManagerService {
                        try {
                            mEnable = false;
                            mEnableExternal = false;
                            if (mAdapter != null && mState.oneOf(STATE_BLE_ON)) {
                            if (mAdapter == null) {
                                return;
                            }
                            if (mState.oneOf(STATE_BLE_ON)) {
                                mAdapter.stopBle(mContext.getAttributionSource());
                            } else if (mAdapter != null && mState.oneOf(STATE_ON)) {
                                mAdapter.disable(mContext.getAttributionSource());
                            } else if (mState.oneOf(STATE_ON)) {
                                onToBleOn();
                            }
                        } catch (RemoteException e) {
                            Log.e(TAG, "Unable to shutdown Bluetooth", e);
@@ -1549,7 +1551,7 @@ class BluetoothManagerService {
                        // should move forward to the next step.
                        mWaitForDisableRetry = 0;
                        mEnable = false;
                        handleDisable();
                        onToBleOn();
                        // Wait for state exiting STATE_ON
                        Message disableDelayedMsg =
                                mHandler.obtainMessage(MESSAGE_HANDLE_DISABLE_DELAYED, 1, 0);
@@ -1639,7 +1641,7 @@ class BluetoothManagerService {

                    if (!mEnable) {
                        waitForState(STATE_ON);
                        handleDisable();
                        onToBleOn();
                        waitForState(
                                STATE_OFF,
                                STATE_TURNING_ON,
@@ -1820,7 +1822,7 @@ class BluetoothManagerService {

            // disable
            ActiveLogs.add(ENABLE_DISABLE_REASON_USER_SWITCH, false);
            handleDisable();
            onToBleOn();
            // Pbap service need receive STATE_TURNING_OFF intent to close
            bluetoothStateChangeHandler(STATE_ON, STATE_TURNING_OFF);

@@ -1948,7 +1950,7 @@ class BluetoothManagerService {
                    MESSAGE_HANDLE_DISABLE_DELAYED, ENABLE_DISABLE_DELAY_MS);
        } else {
            mEnable = false;
            handleDisable();
            onToBleOn();
        }
    }

@@ -2001,17 +2003,16 @@ class BluetoothManagerService {
        }
    }

    private void handleDisable() {
        mAdapterLock.readLock().lock();
        try {
            if (mAdapter != null) {
                Log.d(TAG, "handleDisable: Sending off request.");
                mAdapter.disable(mContext.getAttributionSource());
    private void onToBleOn() {
        if (!mState.oneOf(STATE_ON)) {
            Log.d(TAG, "onToBleOn: Impossible transition from " + mState);
            return;
        }
        Log.d(TAG, "onToBleOn: Sending request");
        try {
            mAdapter.onToBleOn(mContext.getAttributionSource());
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to call disable()", e);
        } finally {
            mAdapterLock.readLock().unlock();
            Log.e(TAG, "Unable to call onToBleOn()", e);
        }
    }

@@ -2148,7 +2149,7 @@ class BluetoothManagerService {

        // disable
        ActiveLogs.add(ENABLE_DISABLE_REASON_START_ERROR, false);
        handleDisable();
        onToBleOn();

        waitForState(STATE_OFF);