From 8800b9e1ffba134143f1f6f47c8cbbace632177a Mon Sep 17 00:00:00 2001 From: jackqdyulei Date: Mon, 24 Sep 2018 18:09:01 -0700 Subject: [PATCH] Use isConnected in CachedBluetoothDevice This method check whether it has connected profile, not physical connection between devices. It make more sense to use it in settings: 1. We only care about whether it has active profile(i.e. A2dp, hfp..) 2. Sometime when profile is disconnected, BluetoothDevice.isConnected() still return true. This may make UI flaky. Bug: 79947085 Test: RunSettingsRoboTests Change-Id: I44039704508a742c7a8aef0a035afcf169b08939 --- .../settings/bluetooth/BluetoothDeviceUpdater.java | 2 +- .../settings/bluetooth/SavedBluetoothDeviceUpdater.java | 2 +- .../settings/bluetooth/BluetoothDeviceUpdaterTest.java | 4 ++-- .../bluetooth/SavedBluetoothDeviceUpdaterTest.java | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java index 4cc329cd356..cac4565bddb 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java @@ -272,6 +272,6 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, ", is connected : " + device.isConnected() + " , is profile connected : " + cachedDevice.isConnected()); } - return device.getBondState() == BluetoothDevice.BOND_BONDED && device.isConnected(); + return device.getBondState() == BluetoothDevice.BOND_BONDED && cachedDevice.isConnected(); } } diff --git a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java index 6d034fda96f..127cb03e18f 100644 --- a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java @@ -46,7 +46,7 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater ", is connected : " + device.isConnected() + ", is profile connected : " + cachedDevice.isConnected()); } - return device.getBondState() == BluetoothDevice.BOND_BONDED && !device.isConnected(); + return device.getBondState() == BluetoothDevice.BOND_BONDED && !cachedDevice.isConnected(); } @Override diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java index 28bf3ab8903..4ede9477995 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java @@ -161,7 +161,7 @@ public class BluetoothDeviceUpdaterTest { @Test public void isDeviceConnected_deviceConnected() { doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState(); - doReturn(true).when(mBluetoothDevice).isConnected(); + doReturn(true).when(mCachedBluetoothDevice).isConnected(); assertThat(mBluetoothDeviceUpdater.isDeviceConnected(mCachedBluetoothDevice)).isTrue(); } @@ -169,7 +169,7 @@ public class BluetoothDeviceUpdaterTest { @Test public void isDeviceConnected_deviceNotConnected() { doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState(); - doReturn(false).when(mBluetoothDevice).isConnected(); + doReturn(false).when(mCachedBluetoothDevice).isConnected(); assertThat(mBluetoothDeviceUpdater.isDeviceConnected(mCachedBluetoothDevice)).isFalse(); } diff --git a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java index e25e4b22744..4d4a711ff5e 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java @@ -77,7 +77,7 @@ public class SavedBluetoothDeviceUpdaterTest { @Test public void update_filterMatch_addPreference() { doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState(); - doReturn(false).when(mBluetoothDevice).isConnected(); + doReturn(false).when(mCachedBluetoothDevice).isConnected(); mBluetoothDeviceUpdater.update(mCachedBluetoothDevice); @@ -87,7 +87,7 @@ public class SavedBluetoothDeviceUpdaterTest { @Test public void update_filterNotMatch_removePreference() { doReturn(BluetoothDevice.BOND_NONE).when(mBluetoothDevice).getBondState(); - doReturn(true).when(mBluetoothDevice).isConnected(); + doReturn(true).when(mCachedBluetoothDevice).isConnected(); mBluetoothDeviceUpdater.update(mCachedBluetoothDevice); @@ -96,7 +96,7 @@ public class SavedBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_deviceConnected_removePreference() { - when(mBluetoothDevice.isConnected()).thenReturn(true); + when(mCachedBluetoothDevice.isConnected()).thenReturn(true); mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP); @@ -106,7 +106,7 @@ public class SavedBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_deviceDisconnected_addPreference() { - when(mBluetoothDevice.isConnected()).thenReturn(false); + when(mCachedBluetoothDevice.isConnected()).thenReturn(false); mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);