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

Commit f1a35071 authored by Lei Yu's avatar Lei Yu Committed by Android (Google) Code Review
Browse files

Merge "Fix crash in CachedBluetoothDevice."

parents 04cd9b4a 0e249a7a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ public class LocalBluetoothManager {
                mCachedDeviceManager, context);
        mProfileManager = new LocalBluetoothProfileManager(context,
                mLocalAdapter, mCachedDeviceManager, mEventManager);

        mProfileManager.updateLocalProfiles();
        mEventManager.readPairedDevices();
    }

+0 −1
Original line number Diff line number Diff line
@@ -121,7 +121,6 @@ public class LocalBluetoothProfileManager {
        // pass this reference to adapter and event manager (circular dependency)
        adapter.setProfileManager(this);

        updateLocalProfiles();
        if (DEBUG) Log.d(TAG, "LocalBluetoothProfileManager construction complete");
    }

+19 −18
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ public class LocalBluetoothProfileManagerTest {
                mContext));
        mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
        when(mDeviceManager.findDevice(mDevice)).thenReturn(mCachedBluetoothDevice);
        mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager);
    }

    /**
@@ -88,20 +90,26 @@ public class LocalBluetoothProfileManagerTest {
    public void constructor_initiateHidAndHidDeviceProfile() {
        mShadowBluetoothAdapter.setSupportedProfiles(generateList(
                new int[] {BluetoothProfile.HID_HOST, BluetoothProfile.HID_DEVICE}));
        mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager);
        mProfileManager.updateLocalProfiles();

        assertThat(mProfileManager.getHidProfile()).isNotNull();
        assertThat(mProfileManager.getHidDeviceProfile()).isNotNull();
    }

    @Test
    public void constructor_doNotUpdateProfiles() {
        mProfileManager = spy(new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager));

        verify(mProfileManager, never()).updateLocalProfiles();
    }

    /**
     * Verify updateLocalProfiles() for a local A2DP source adds A2dpProfile
     */
    @Test
    public void updateLocalProfiles_addA2dpToLocalProfiles() {
        mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager);
        mProfileManager.updateLocalProfiles();
        assertThat(mProfileManager.getA2dpProfile()).isNull();
        assertThat(mProfileManager.getHeadsetProfile()).isNull();

@@ -120,8 +128,7 @@ public class LocalBluetoothProfileManagerTest {
    public void updateProfiles_addHidProfileForRemoteDevice() {
        mShadowBluetoothAdapter.setSupportedProfiles(generateList(
                new int[] {BluetoothProfile.HID_HOST}));
        mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager);
        mProfileManager.updateLocalProfiles();
        ParcelUuid[] uuids = new ParcelUuid[]{BluetoothUuid.Hid};
        ParcelUuid[] localUuids = new ParcelUuid[]{};
        List<LocalBluetoothProfile> profiles = new ArrayList<>();
@@ -143,8 +150,7 @@ public class LocalBluetoothProfileManagerTest {
    public void stateChangedHandler_receiveA2dpConnectionStateChanged_shouldDispatchCallback() {
        mShadowBluetoothAdapter.setSupportedProfiles(generateList(
                new int[] {BluetoothProfile.A2DP}));
        mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager);
        mProfileManager.updateLocalProfiles();
        // Refer to BluetoothControllerImpl, it will call setReceiverHandler after
        // LocalBluetoothProfileManager created.
        mEventManager.setReceiverHandler(null);
@@ -167,8 +173,7 @@ public class LocalBluetoothProfileManagerTest {
    public void stateChangedHandler_receiveHeadsetConnectionStateChanged_shouldDispatchCallback() {
        mShadowBluetoothAdapter.setSupportedProfiles(generateList(
                new int[] {BluetoothProfile.HEADSET}));
        mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager);
        mProfileManager.updateLocalProfiles();
        // Refer to BluetoothControllerImpl, it will call setReceiverHandler after
        // LocalBluetoothProfileManager created.
        mEventManager.setReceiverHandler(null);
@@ -191,8 +196,7 @@ public class LocalBluetoothProfileManagerTest {
    public void stateChangedHandler_receiveHAPConnectionStateChanged_shouldDispatchCallback() {
        mShadowBluetoothAdapter.setSupportedProfiles(generateList(
                new int[] {BluetoothProfile.HEARING_AID}));
        mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager);
        mProfileManager.updateLocalProfiles();
        // Refer to BluetoothControllerImpl, it will call setReceiverHandler after
        // LocalBluetoothProfileManager created.
        mEventManager.setReceiverHandler(null);
@@ -215,8 +219,7 @@ public class LocalBluetoothProfileManagerTest {
    public void stateChangedHandler_receivePanConnectionStateChanged_shouldNotDispatchCallback() {
        mShadowBluetoothAdapter.setSupportedProfiles(generateList(
                new int[] {BluetoothProfile.PAN}));
        mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager);
        mProfileManager.updateLocalProfiles();
        // Refer to BluetoothControllerImpl, it will call setReceiverHandler after
        // LocalBluetoothProfileManager created.
        mEventManager.setReceiverHandler(null);
@@ -239,8 +242,7 @@ public class LocalBluetoothProfileManagerTest {
    public void stateChangedHandler_receivePanConnectionStateChangedWithoutProfile_shouldNotRefresh
    () {
        mShadowBluetoothAdapter.setSupportedProfiles(null);
        mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager);
        mProfileManager.updateLocalProfiles();
        // Refer to BluetoothControllerImpl, it will call setReceiverHandler after
        // LocalBluetoothProfileManager created.
        mEventManager.setReceiverHandler(null);
@@ -262,8 +264,7 @@ public class LocalBluetoothProfileManagerTest {
    public void stateChangedHandler_receivePanConnectionStateChangedWithProfile_shouldRefresh() {
        mShadowBluetoothAdapter.setSupportedProfiles(generateList(
                new int[] {BluetoothProfile.PAN}));
        mProfileManager = new LocalBluetoothProfileManager(mContext, mLocalBluetoothAdapter,
                mDeviceManager, mEventManager);
        mProfileManager.updateLocalProfiles();
        // Refer to BluetoothControllerImpl, it will call setReceiverHandler after
        // LocalBluetoothProfileManager created.
        mEventManager.setReceiverHandler(null);