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

Commit 70359c02 authored by Joseph Pirozzo's avatar Joseph Pirozzo
Browse files

Update Adapter State after native layer complete

Update Adapter state only after native layer completes shutdown.
Previously adapter state would be updated after task was scheduled but
not necessarily completed, this could cause hci timeouts on User
switching.

Bug: 124232677
Test: am switch-user (every 10 seconds 1000X)
Change-Id: I810f30013aa448a831f289774467f0470eed644e
(cherry picked from commit 5d14c8a19014afa1106f4b92618349ec9078987c)
parent b8b822bc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -310,7 +310,6 @@ public class AdapterService extends Service {
                        mAdapterStateMachine.sendMessage(AdapterState.BREDR_STOPPED);
                    } else if (mRunningProfiles.size() == 0) {
                        disableNative();
                        mAdapterStateMachine.sendMessage(AdapterState.BLE_STOPPED);
                    }
                    break;
                default:
@@ -545,6 +544,7 @@ public class AdapterService extends Service {
    void stateChangeCallback(int status) {
        if (status == AbstractionLayer.BT_STATE_OFF) {
            debugLog("stateChangeCallback: disableNative() completed");
            mAdapterStateMachine.sendMessage(AdapterState.BLE_STOPPED);
        } else if (status == AbstractionLayer.BT_STATE_ON) {
            mAdapterStateMachine.sendMessage(AdapterState.BLE_STARTED);
        } else {
+6 −5
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ public class AdapterServiceTest {
    private static final int CONTEXT_SWITCH_MS = 100;
    private static final int ONE_SECOND_MS = 1000;
    private static final int NATIVE_INIT_MS = 8000;
    private static final int NATIVE_DISABLE_MS = 1000;

    private PowerManager mPowerManager;
    private PackageManager mMockPackageManager;
@@ -255,7 +256,7 @@ public class AdapterServiceTest {
        mAdapterService.onProfileServiceStateChanged(mMockGattService, BluetoothAdapter.STATE_OFF);

        verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_OFF, BluetoothAdapter.STATE_OFF,
                invocationNumber + 1, CONTEXT_SWITCH_MS);
                invocationNumber + 1, NATIVE_DISABLE_MS);

        Assert.assertFalse(mAdapterService.isEnabled());
    }
@@ -331,7 +332,7 @@ public class AdapterServiceTest {
                .times(2)).startService(any());

        verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_OFF, BluetoothAdapter.STATE_OFF, 1,
                CONTEXT_SWITCH_MS);
                NATIVE_DISABLE_MS);

        Assert.assertFalse(mAdapterService.isEnabled());
    }
@@ -367,7 +368,7 @@ public class AdapterServiceTest {
        verify(mMockContext, timeout(ONE_SECOND_MS).times(6)).startService(any());

        verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_OFF, BluetoothAdapter.STATE_OFF, 1,
                AdapterState.BLE_STOP_TIMEOUT_DELAY + CONTEXT_SWITCH_MS);
                AdapterState.BLE_STOP_TIMEOUT_DELAY + NATIVE_DISABLE_MS);

        Assert.assertFalse(mAdapterService.isEnabled());
    }
@@ -443,7 +444,7 @@ public class AdapterServiceTest {
        mAdapterService.onProfileServiceStateChanged(mMockGattService, BluetoothAdapter.STATE_OFF);

        verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_OFF, BluetoothAdapter.STATE_OFF, 1,
                AdapterState.BLE_STOP_TIMEOUT_DELAY + CONTEXT_SWITCH_MS);
                AdapterState.BLE_STOP_TIMEOUT_DELAY + NATIVE_DISABLE_MS);

        Assert.assertFalse(mAdapterService.isEnabled());
    }
@@ -490,7 +491,7 @@ public class AdapterServiceTest {
        mAdapterService.onProfileServiceStateChanged(mMockGattService, BluetoothAdapter.STATE_OFF);

        verifyStateChange(BluetoothAdapter.STATE_BLE_TURNING_OFF, BluetoothAdapter.STATE_OFF, 1,
                CONTEXT_SWITCH_MS);
                NATIVE_DISABLE_MS);

        Assert.assertFalse(mAdapterService.isEnabled());