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

Commit 8f449786 authored by William Escande's avatar William Escande
Browse files

AdapterService: Fix fastBindToApp

Some fields need to be initialized earlier when we are attempting the
fast bind path

Bug: 323672160
Test: atest BluetoothInstrumentationTests with & without fastBindToApp
Change-Id: I5e85c9c5b96b937fa79a9129b52fd106449d823e
parent 92ccaa32
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -622,6 +622,7 @@ public class AdapterService extends Service {
            return;
        }
        // OnCreate must perform the minimum of infaillible and mandatory initialization
        mRemoteDevices = new RemoteDevices(this, mLooper);
        mAdapterProperties = new AdapterProperties(this);
        mAdapterStateMachine = new AdapterState(this, mLooper);
        mBinder = new AdapterServiceBinder(this);
@@ -630,6 +631,7 @@ public class AdapterService extends Service {
        mPowerManager = getNonNullSystemService(PowerManager.class);
        mBatteryStatsManager = getNonNullSystemService(BatteryStatsManager.class);
        mCompanionDeviceManager = getNonNullSystemService(CompanionDeviceManager.class);
        setAdapterService(this);
    }

    private void init() {
@@ -645,9 +647,9 @@ public class AdapterService extends Service {
            mPowerManager = getNonNullSystemService(PowerManager.class);
            mBatteryStatsManager = getNonNullSystemService(BatteryStatsManager.class);
            mCompanionDeviceManager = getNonNullSystemService(CompanionDeviceManager.class);
            mRemoteDevices = new RemoteDevices(this, mLooper);
        }

        mRemoteDevices = new RemoteDevices(this, mLooper);
        clearDiscoveringPackages();
        if (!Flags.fastBindToApp()) {
            mBinder = new AdapterServiceBinder(this);
@@ -735,7 +737,9 @@ public class AdapterService extends Service {

        mBluetoothSocketManagerBinder = new BluetoothSocketManagerBinder(this);

        if (!Flags.fastBindToApp()) {
            setAdapterService(this);
        }

        invalidateBluetoothCaches();

+6 −0
Original line number Diff line number Diff line
@@ -403,6 +403,9 @@ public class AdapterServiceTest {
            IBluetoothCallback callback,
            AdapterNativeInterface nativeInterface) {
        adapter.enable(false);
        if (Flags.fastBindToApp()) {
            TestUtils.syncHandler(looper, 0); // when fastBindToApp is enable init need to be run
        }
        TestUtils.syncHandler(looper, AdapterState.BLE_TURN_ON);
        verifyStateChange(callback, STATE_OFF, STATE_BLE_TURNING_ON);

@@ -617,6 +620,9 @@ public class AdapterServiceTest {
        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);

        mAdapterService.enable(false);
        if (Flags.fastBindToApp()) {
            syncHandler(0); // when fastBindToApp is enable init need to be run
        }
        syncHandler(AdapterState.BLE_TURN_ON);
        verifyStateChange(STATE_OFF, STATE_BLE_TURNING_ON);
        assertThat(mAdapterService.getBluetoothGatt()).isNotNull();