Check the device is connected when receive onProfileConnectionStateChanged()

Use isFilterMatched() to decide the prefernce should be added
or removed when receive onProfileConnectionStateChanged()

Bug: 80161203
Test: make -j42 RunSettingsRoboTests
Change-Id: Icccdb9007b587d3f481a23856edd7b2f7c9b04e0
This commit is contained in:
hughchen
2018-07-31 16:09:17 +08:00
parent 75bafefa49
commit 70758584dc
5 changed files with 10 additions and 48 deletions

View File

@@ -59,25 +59,6 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
forceUpdate(); 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 @Override
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
final int audioMode = mAudioManager.getMode(); final int audioMode = mAudioManager.getMode();

View File

@@ -162,6 +162,11 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
@Override @Override
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state, public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
int bluetoothProfile) { int bluetoothProfile) {
if (DBG) {
Log.d(TAG, "onProfileConnectionStateChanged() device: " + cachedDevice.getName()
+ ", state: " + state + ", bluetoothProfile: " + bluetoothProfile);
}
update(cachedDevice);
} }
@Override @Override

View File

@@ -59,25 +59,6 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
forceUpdate(); 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 @Override
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
final int audioMode = mAudioManager.getMode(); final int audioMode = mAudioManager.getMode();

View File

@@ -48,16 +48,6 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
super(fragment, devicePreferenceCallback, localBluetoothManager); 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 @Override
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
final BluetoothDevice device = cachedDevice.getDevice(); final BluetoothDevice device = cachedDevice.getDevice();

View File

@@ -68,6 +68,7 @@ public class SavedBluetoothDeviceUpdaterTest {
doReturn(mContext).when(mDashboardFragment).getContext(); doReturn(mContext).when(mDashboardFragment).getContext();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager); when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment, mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mDashboardFragment,
mDevicePreferenceCallback, mLocalManager)); mDevicePreferenceCallback, mLocalManager));
@@ -99,6 +100,8 @@ public class SavedBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_deviceConnected_removePreference() { public void onProfileConnectionStateChanged_deviceConnected_removePreference() {
when(mBluetoothDevice.isConnected()).thenReturn(true);
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP); BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
@@ -107,6 +110,8 @@ public class SavedBluetoothDeviceUpdaterTest {
@Test @Test
public void onProfileConnectionStateChanged_deviceDisconnected_addPreference() { public void onProfileConnectionStateChanged_deviceDisconnected_addPreference() {
when(mBluetoothDevice.isConnected()).thenReturn(false);
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP); BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);