diff --git a/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java index 44ef4be3dce..2b9c2cb5565 100644 --- a/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java @@ -59,25 +59,6 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater forceUpdate(); } - @Override - public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state, - int bluetoothProfile) { - if (DBG) { - Log.d(TAG, "onProfileConnectionStateChanged() device: " + - cachedDevice.getName() + ", state: " + state + ", bluetoothProfile: " - + bluetoothProfile); - } - if (state == BluetoothProfile.STATE_CONNECTED) { - if (isFilterMatched(cachedDevice)) { - addPreference(cachedDevice); - } else { - removePreference(cachedDevice); - } - } else if (state == BluetoothProfile.STATE_DISCONNECTED) { - removePreference(cachedDevice); - } - } - @Override public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { final int audioMode = mAudioManager.getMode(); diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java index 0c0c5eaa173..dece0ccccf6 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java @@ -162,6 +162,11 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback, @Override public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state, int bluetoothProfile) { + if (DBG) { + Log.d(TAG, "onProfileConnectionStateChanged() device: " + cachedDevice.getName() + + ", state: " + state + ", bluetoothProfile: " + bluetoothProfile); + } + update(cachedDevice); } @Override diff --git a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java index 500fb067622..259a403625b 100644 --- a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java @@ -59,25 +59,6 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater { forceUpdate(); } - @Override - public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state, - int bluetoothProfile) { - if (DBG) { - Log.d(TAG, "onProfileConnectionStateChanged() device: " + - cachedDevice.getName() + ", state: " + state + ", bluetoothProfile: " - + bluetoothProfile); - } - if (state == BluetoothProfile.STATE_CONNECTED) { - if (isFilterMatched(cachedDevice)) { - addPreference(cachedDevice); - } else { - removePreference(cachedDevice); - } - } else if (state == BluetoothProfile.STATE_DISCONNECTED) { - removePreference(cachedDevice); - } - } - @Override public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { final int audioMode = mAudioManager.getMode(); diff --git a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java index db11164922e..059a920b3d2 100644 --- a/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdater.java @@ -48,16 +48,6 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater super(fragment, devicePreferenceCallback, localBluetoothManager); } - @Override - public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state, - int bluetoothProfile) { - if (state == BluetoothProfile.STATE_CONNECTED) { - removePreference(cachedDevice); - } else if (state == BluetoothProfile.STATE_DISCONNECTED) { - addPreference(cachedDevice); - } - } - @Override public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { final BluetoothDevice device = cachedDevice.getDevice(); diff --git a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java index a88d8ff446e..def8c4db37c 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/SavedBluetoothDeviceUpdaterTest.java @@ -68,6 +68,7 @@ public class SavedBluetoothDeviceUpdaterTest { doReturn(mContext).when(mDashboardFragment).getContext(); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager); + when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment, mDevicePreferenceCallback, mLocalManager)); @@ -99,6 +100,8 @@ public class SavedBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_deviceConnected_removePreference() { + when(mBluetoothDevice.isConnected()).thenReturn(true); + mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP); @@ -107,6 +110,8 @@ public class SavedBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_deviceDisconnected_addPreference() { + when(mBluetoothDevice.isConnected()).thenReturn(false); + mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);