summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lei Yu <jackqdyulei@google.com> 2018-08-29 17:14:03 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2018-08-29 17:14:03 +0000
commitf1a35071bb228b81ec47d8e516d265ff038ec78f (patch)
treeb7167d4d092f8dd29d1a96daf39f3bb1387fece1
parent04cd9b4a008e9a1d8a6d61fa91a6b8c229a05711 (diff)
parent0e249a7a60ae2c6a7b37889afc71841185368c06 (diff)
Merge "Fix crash in CachedBluetoothDevice."
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java2
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java1
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManagerTest.java37
3 files changed, 21 insertions, 19 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java
index 1c50953bac12..51601a509b9d 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothManager.java
@@ -75,6 +75,8 @@ public class LocalBluetoothManager {
mCachedDeviceManager, context);
mProfileManager = new LocalBluetoothProfileManager(context,
mLocalAdapter, mCachedDeviceManager, mEventManager);
+
+ mProfileManager.updateLocalProfiles();
mEventManager.readPairedDevices();
}
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java
index d2544939bbb8..36d209e96269 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManager.java
@@ -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");
}
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManagerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManagerTest.java
index f223176795b8..5550b7e5e865 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManagerTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/LocalBluetoothProfileManagerTest.java
@@ -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);