Use another callback to notify the updater that UI should be updated
Replace onConnectionStateChanged callback with onProfileConnectionStateChanged. While updater is notified, isFilterMatched(cachedDevice) will decide whether to add/remove from UI based on audio profiles and audio mode. Bug: 76447449 Test: make RunSettingsRoboTests -j28 Change-Id: Icfba1ce2297e4638679158f9f99bae276940d885
This commit is contained in:
@@ -16,11 +16,11 @@
|
|||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
@@ -57,18 +57,20 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
|
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
|
||||||
|
int bluetoothProfile) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG,"onConnectionStateChanged() device : " +
|
Log.d(TAG, "onProfileConnectionStateChanged() device: " +
|
||||||
cachedDevice.getName() + ", state : " + state);
|
cachedDevice.getName() + ", state: " + state + ", bluetoothProfile: "
|
||||||
|
+ bluetoothProfile);
|
||||||
}
|
}
|
||||||
if (state == BluetoothAdapter.STATE_CONNECTED) {
|
if (state == BluetoothProfile.STATE_CONNECTED) {
|
||||||
if (isFilterMatched(cachedDevice)) {
|
if (isFilterMatched(cachedDevice)) {
|
||||||
addPreference(cachedDevice);
|
addPreference(cachedDevice);
|
||||||
} else {
|
} else {
|
||||||
removePreference(cachedDevice);
|
removePreference(cachedDevice);
|
||||||
}
|
}
|
||||||
} else if (state == BluetoothAdapter.STATE_DISCONNECTED) {
|
} else if (state == BluetoothProfile.STATE_DISCONNECTED) {
|
||||||
removePreference(cachedDevice);
|
removePreference(cachedDevice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -161,6 +161,11 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
|
|||||||
public void onAudioModeChanged() {
|
public void onAudioModeChanged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
|
||||||
|
int bluetoothProfile) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected() {
|
public void onServiceConnected() {
|
||||||
// When bluetooth service connected update the UI
|
// When bluetooth service connected update the UI
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -60,19 +59,20 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
|
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
|
||||||
|
int bluetoothProfile) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG,"onConnectionStateChanged() device : " +
|
Log.d(TAG, "onProfileConnectionStateChanged() device: " +
|
||||||
cachedDevice.getName() + ", state : " + state);
|
cachedDevice.getName() + ", state: " + state + ", bluetoothProfile: "
|
||||||
|
+ bluetoothProfile);
|
||||||
}
|
}
|
||||||
|
if (state == BluetoothProfile.STATE_CONNECTED) {
|
||||||
if (state == BluetoothAdapter.STATE_CONNECTED) {
|
|
||||||
if (isFilterMatched(cachedDevice)) {
|
if (isFilterMatched(cachedDevice)) {
|
||||||
addPreference(cachedDevice);
|
addPreference(cachedDevice);
|
||||||
} else {
|
} else {
|
||||||
removePreference(cachedDevice);
|
removePreference(cachedDevice);
|
||||||
}
|
}
|
||||||
} else if (state == BluetoothAdapter.STATE_DISCONNECTED) {
|
} else if (state == BluetoothProfile.STATE_DISCONNECTED) {
|
||||||
removePreference(cachedDevice);
|
removePreference(cachedDevice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
|
||||||
@@ -43,10 +43,11 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
|
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
|
||||||
if (state == BluetoothAdapter.STATE_CONNECTED) {
|
int bluetoothProfile) {
|
||||||
|
if (state == BluetoothProfile.STATE_CONNECTED) {
|
||||||
removePreference(cachedDevice);
|
removePreference(cachedDevice);
|
||||||
} else if (state == BluetoothAdapter.STATE_DISCONNECTED) {
|
} else if (state == BluetoothProfile.STATE_DISCONNECTED) {
|
||||||
addPreference(cachedDevice);
|
addPreference(cachedDevice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -161,7 +161,6 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
|
public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
|
||||||
updateState(mPreference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -174,6 +173,12 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
|
|||||||
updateState(mPreference);
|
updateState(mPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
|
||||||
|
int bluetoothProfile) {
|
||||||
|
updateState(mPreference);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBluetoothStateChanged(int bluetoothState) {
|
public void onBluetoothStateChanged(int bluetoothState) {
|
||||||
}
|
}
|
||||||
|
@@ -15,11 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
|
||||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
@@ -150,60 +150,61 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_a2dpDeviceConnected_notInCall_addPreference() {
|
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_addPreference() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
|
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothAdapter.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_a2dpDeviceConnected_inCall_removePreference() {
|
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_removePreference() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothAdapter.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_hfpDeviceConnected_notInCall_removePreference() {
|
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_removePreference() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
|
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothAdapter.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_hfpDeviceConnected_inCall_addPreference() {
|
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_addPreference() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothAdapter.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_deviceDisconnected_removePreference() {
|
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
||||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothAdapter.STATE_DISCONNECTED);
|
BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
@@ -23,11 +24,11 @@ import static org.mockito.Mockito.spy;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
|
||||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
@@ -75,6 +76,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
private Collection<CachedBluetoothDevice> cachedDevices;
|
private Collection<CachedBluetoothDevice> cachedDevices;
|
||||||
private ShadowAudioManager mShadowAudioManager;
|
private ShadowAudioManager mShadowAudioManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
@@ -151,60 +153,61 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() {
|
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothAdapter.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
|
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
|
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isA2dpDevice()).thenReturn(true);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothAdapter.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() {
|
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
mShadowAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothAdapter.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() {
|
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
|
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isHfpDevice()).thenReturn(true);
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothAdapter.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onConnectionStateChanged_deviceDisconnected_removePreference() {
|
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
||||||
mBluetoothDeviceUpdater.onConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothAdapter.STATE_DISCONNECTED);
|
BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ import static org.mockito.Mockito.spy;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class SavedBluetoothDeviceUpdaterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate_filterMatch_addPreference() {
|
public void update_filterMatch_addPreference() {
|
||||||
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
|
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
|
||||||
doReturn(false).when(mBluetoothDevice).isConnected();
|
doReturn(false).when(mBluetoothDevice).isConnected();
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ public class SavedBluetoothDeviceUpdaterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate_filterNotMatch_removePreference() {
|
public void update_filterNotMatch_removePreference() {
|
||||||
doReturn(BluetoothDevice.BOND_NONE).when(mBluetoothDevice).getBondState();
|
doReturn(BluetoothDevice.BOND_NONE).when(mBluetoothDevice).getBondState();
|
||||||
doReturn(true).when(mBluetoothDevice).isConnected();
|
doReturn(true).when(mBluetoothDevice).isConnected();
|
||||||
|
|
||||||
@@ -96,17 +96,17 @@ public class SavedBluetoothDeviceUpdaterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnConnectionStateChanged_deviceConnected_removePreference() {
|
public void onProfileConnectionStateChanged_deviceConnected_removePreference() {
|
||||||
mBluetoothDeviceUpdater
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
.onConnectionStateChanged(mCachedBluetoothDevice, BluetoothAdapter.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnConnectionStateChanged_deviceDisconnected_addPreference() {
|
public void onProfileConnectionStateChanged_deviceDisconnected_addPreference() {
|
||||||
mBluetoothDeviceUpdater
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
.onConnectionStateChanged(mCachedBluetoothDevice, BluetoothAdapter.STATE_DISCONNECTED);
|
BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user