Merge "Avoid AudioManager#getMode in isFilterMatched" into main
This commit is contained in:
@@ -39,6 +39,7 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
|||||||
|
|
||||||
private final AudioManager mAudioManager;
|
private final AudioManager mAudioManager;
|
||||||
private final LocalBluetoothManager mLocalBtManager;
|
private final LocalBluetoothManager mLocalBtManager;
|
||||||
|
private int mAudioMode;
|
||||||
|
|
||||||
public AvailableMediaBluetoothDeviceUpdater(
|
public AvailableMediaBluetoothDeviceUpdater(
|
||||||
Context context,
|
Context context,
|
||||||
@@ -47,21 +48,23 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
|||||||
super(context, devicePreferenceCallback, metricsCategory);
|
super(context, devicePreferenceCallback, metricsCategory);
|
||||||
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
mLocalBtManager = Utils.getLocalBtManager(context);
|
mLocalBtManager = Utils.getLocalBtManager(context);
|
||||||
|
mAudioMode = mAudioManager.getMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAudioModeChanged() {
|
public void onAudioModeChanged() {
|
||||||
|
// TODO: move to background thread
|
||||||
|
mAudioMode = mAudioManager.getMode();
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||||
final int audioMode = mAudioManager.getMode();
|
|
||||||
final int currentAudioProfile;
|
final int currentAudioProfile;
|
||||||
|
|
||||||
if (audioMode == AudioManager.MODE_RINGTONE
|
if (mAudioMode == AudioManager.MODE_RINGTONE
|
||||||
|| audioMode == AudioManager.MODE_IN_CALL
|
|| mAudioMode == AudioManager.MODE_IN_CALL
|
||||||
|| audioMode == AudioManager.MODE_IN_COMMUNICATION) {
|
|| mAudioMode == AudioManager.MODE_IN_COMMUNICATION) {
|
||||||
// in phone call
|
// in phone call
|
||||||
currentAudioProfile = BluetoothProfile.HEADSET;
|
currentAudioProfile = BluetoothProfile.HEADSET;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -39,26 +39,29 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
|
|||||||
private static final String PREF_KEY_PREFIX = "connected_bt_";
|
private static final String PREF_KEY_PREFIX = "connected_bt_";
|
||||||
|
|
||||||
private final AudioManager mAudioManager;
|
private final AudioManager mAudioManager;
|
||||||
|
private int mAudioMode;
|
||||||
|
|
||||||
public ConnectedBluetoothDeviceUpdater(Context context,
|
public ConnectedBluetoothDeviceUpdater(Context context,
|
||||||
DevicePreferenceCallback devicePreferenceCallback, int metricsCategory) {
|
DevicePreferenceCallback devicePreferenceCallback, int metricsCategory) {
|
||||||
super(context, devicePreferenceCallback, metricsCategory);
|
super(context, devicePreferenceCallback, metricsCategory);
|
||||||
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
mAudioMode = mAudioManager.getMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAudioModeChanged() {
|
public void onAudioModeChanged() {
|
||||||
|
// TODO: move to background thread
|
||||||
|
mAudioMode = mAudioManager.getMode();
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
|
||||||
final int audioMode = mAudioManager.getMode();
|
|
||||||
final int currentAudioProfile;
|
final int currentAudioProfile;
|
||||||
|
|
||||||
if (audioMode == AudioManager.MODE_RINGTONE
|
if (mAudioMode == AudioManager.MODE_RINGTONE
|
||||||
|| audioMode == AudioManager.MODE_IN_CALL
|
|| mAudioMode == AudioManager.MODE_IN_CALL
|
||||||
|| audioMode == AudioManager.MODE_IN_COMMUNICATION) {
|
|| mAudioMode == AudioManager.MODE_IN_COMMUNICATION) {
|
||||||
// in phone call
|
// in phone call
|
||||||
currentAudioProfile = BluetoothProfile.HEADSET;
|
currentAudioProfile = BluetoothProfile.HEADSET;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -124,24 +124,17 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
|
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
|
||||||
when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(ImmutableSet.of());
|
when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(ImmutableSet.of());
|
||||||
|
|
||||||
mBluetoothDeviceUpdater =
|
|
||||||
spy(
|
|
||||||
new AvailableMediaBluetoothDeviceUpdater(
|
|
||||||
mContext, mDevicePreferenceCallback, /* metricsCategory= */ 0));
|
|
||||||
mBluetoothDeviceUpdater.setPrefContext(mContext);
|
|
||||||
mPreference =
|
mPreference =
|
||||||
new BluetoothDevicePreference(
|
new BluetoothDevicePreference(
|
||||||
mContext,
|
mContext,
|
||||||
mCachedBluetoothDevice,
|
mCachedBluetoothDevice,
|
||||||
false,
|
false,
|
||||||
BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
||||||
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
|
|
||||||
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onAudioModeChanged_hfpDeviceConnected_inCall_addPreference() {
|
public void onAudioModeChanged_hfpDeviceConnected_inCall_addPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -153,7 +146,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onAudioModeChanged_hfpDeviceConnected_notInCall_removePreference() {
|
public void onAudioModeChanged_hfpDeviceConnected_notInCall_removePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -165,7 +158,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onAudioModeChanged_a2dpDeviceConnected_inCall_removePreference() {
|
public void onAudioModeChanged_a2dpDeviceConnected_inCall_removePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
@@ -177,7 +170,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onAudioModeChanged_a2dpDeviceConnected_notInCall_addPreference() {
|
public void onAudioModeChanged_a2dpDeviceConnected_notInCall_addPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
@@ -189,7 +182,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_addPreference() {
|
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_addPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
@@ -202,7 +195,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_removePreference() {
|
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_removePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
@@ -215,7 +208,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_removePreference() {
|
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_removePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -228,7 +221,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_addPreference() {
|
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_addPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -241,7 +234,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_ashaHearingAidConnected_notInCall_addPreference() {
|
public void onProfileConnectionStateChanged_ashaHearingAidConnected_notInCall_addPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
|
||||||
@@ -256,7 +249,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_ashaHearingAidConnected_inCall_addPreference() {
|
public void onProfileConnectionStateChanged_ashaHearingAidConnected_inCall_addPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
|
||||||
@@ -272,7 +265,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_leaConnected_notInCallSharingFlagOff_addPref() {
|
public void onProfileConnectionStateChanged_leaConnected_notInCallSharingFlagOff_addPref() {
|
||||||
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -292,7 +285,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_leaConnected_notInCallNotInSharing_addPref() {
|
public void onProfileConnectionStateChanged_leaConnected_notInCallNotInSharing_addPref() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -309,7 +302,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_leaConnected_inCallSharingFlagOff_addPref() {
|
public void onProfileConnectionStateChanged_leaConnected_inCallSharingFlagOff_addPref() {
|
||||||
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -326,7 +319,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_leaConnected_inCallNotInSharing_addPref() {
|
public void onProfileConnectionStateChanged_leaConnected_inCallNotInSharing_addPref() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -344,7 +337,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
public void onProfileConnectionStateChanged_leaConnected_notInCallInSharing_removePref() {
|
public void onProfileConnectionStateChanged_leaConnected_notInCallInSharing_removePref() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -367,7 +360,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
onProfileConnectionStateChanged_leaConnected_noInCallInSharing_hysteresis_removePref() {
|
onProfileConnectionStateChanged_leaConnected_noInCallInSharing_hysteresis_removePref() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -388,7 +381,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
public void onProfileConnectionStateChanged_leaConnected_inCallSharing_removePref() {
|
public void onProfileConnectionStateChanged_leaConnected_inCallSharing_removePref() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -410,7 +403,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
public void onProfileConnectionStateChanged_leaConnected_inCallSharing_hysteresis_removePref() {
|
public void onProfileConnectionStateChanged_leaConnected_inCallSharing_hysteresis_removePref() {
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||||
mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -430,7 +423,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void
|
public void
|
||||||
onProfileConnectionStateChanged_deviceIsNotInList_notInCall_invokesRemovePreference() {
|
onProfileConnectionStateChanged_deviceIsNotInList_notInCall_invokesRemovePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -446,7 +439,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovePreference() {
|
public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -462,6 +455,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
||||||
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(
|
||||||
mCachedBluetoothDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
|
mCachedBluetoothDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
@@ -470,8 +464,19 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onClick_Preference_setActive() {
|
public void onClick_Preference_setActive() {
|
||||||
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
mBluetoothDeviceUpdater.onPreferenceClick(mPreference);
|
mBluetoothDeviceUpdater.onPreferenceClick(mPreference);
|
||||||
|
|
||||||
verify(mDevicePreferenceCallback).onDeviceClick(mPreference);
|
verify(mDevicePreferenceCallback).onDeviceClick(mPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setUpDeviceUpdaterWithAudioMode(int audioMode) {
|
||||||
|
mAudioManager.setMode(audioMode);
|
||||||
|
mBluetoothDeviceUpdater =
|
||||||
|
spy(new AvailableMediaBluetoothDeviceUpdater(
|
||||||
|
mContext, mDevicePreferenceCallback, /* metricsCategory= */ 0));
|
||||||
|
mBluetoothDeviceUpdater.setPrefContext(mContext);
|
||||||
|
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
|
||||||
|
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,16 +112,11 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
|
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
|
||||||
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
|
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
|
||||||
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
|
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
|
||||||
mBluetoothDeviceUpdater = spy(new ConnectedBluetoothDeviceUpdater(mContext,
|
|
||||||
mDevicePreferenceCallback, /* metricsCategory= */ 0));
|
|
||||||
mBluetoothDeviceUpdater.setPrefContext(mContext);
|
|
||||||
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
|
|
||||||
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onAudioModeChanged_hfpDeviceConnected_notInCall_addPreference() {
|
public void onAudioModeChanged_hfpDeviceConnected_notInCall_addPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -133,7 +128,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onAudioModeChanged_hfpDeviceConnected_inCall_removePreference() {
|
public void onAudioModeChanged_hfpDeviceConnected_inCall_removePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -145,7 +140,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onAudioModeChanged_a2dpDeviceConnected_notInCall_removePreference() {
|
public void onAudioModeChanged_a2dpDeviceConnected_notInCall_removePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
@@ -157,7 +152,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onAudioModeChanged_a2dpDeviceConnected_inCall_addPreference() {
|
public void onAudioModeChanged_a2dpDeviceConnected_inCall_addPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
@@ -169,7 +164,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() {
|
public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
@@ -182,7 +177,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovePreference() {
|
public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
@@ -196,7 +191,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
|
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
@@ -209,7 +204,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() {
|
public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -222,7 +217,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() {
|
public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -236,7 +231,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_ashaHearingAidConnected_inCall_removePreference()
|
public void onProfileConnectionStateChanged_ashaHearingAidConnected_inCall_removePreference()
|
||||||
{
|
{
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
|
||||||
@@ -250,7 +245,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_ashaHearingAidConnected_notInCall_removePreference()
|
public void onProfileConnectionStateChanged_ashaHearingAidConnected_notInCall_removePreference()
|
||||||
{
|
{
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
|
||||||
@@ -263,7 +258,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_leAudioDeviceConnected_inCall_removesPreference() {
|
public void onProfileConnectionStateChanged_leAudioDeviceConnected_inCall_removesPreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater
|
when(mBluetoothDeviceUpdater
|
||||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -277,7 +272,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_leAudioDeviceConnected_notInCall_removesPreference()
|
public void onProfileConnectionStateChanged_leAudioDeviceConnected_notInCall_removesPreference()
|
||||||
{
|
{
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater
|
when(mBluetoothDeviceUpdater
|
||||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -290,7 +285,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovesPreference()
|
public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovesPreference()
|
||||||
{
|
{
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL);
|
||||||
when(mBluetoothDeviceUpdater
|
when(mBluetoothDeviceUpdater
|
||||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -305,7 +300,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_deviceIsNotInList_notInCall_invokesRemovesPreference
|
public void onProfileConnectionStateChanged_deviceIsNotInList_notInCall_invokesRemovesPreference
|
||||||
() {
|
() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater
|
when(mBluetoothDeviceUpdater
|
||||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||||
@@ -319,6 +314,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
||||||
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
|
BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP);
|
||||||
|
|
||||||
@@ -327,6 +323,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addPreference_addPreference_shouldHideSecondTarget() {
|
public void addPreference_addPreference_shouldHideSecondTarget() {
|
||||||
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
BluetoothDevicePreference btPreference =
|
BluetoothDevicePreference btPreference =
|
||||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||||
true, BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
true, BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
||||||
@@ -340,7 +337,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
@Test
|
@Test
|
||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
|
||||||
public void update_notExclusiveManagedDevice_addDevice() {
|
public void update_notExclusiveManagedDevice_addDevice() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater
|
when(mBluetoothDeviceUpdater
|
||||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -356,7 +353,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
|
||||||
public void update_exclusivelyManagedDevice_packageNotInstalled_addDevice()
|
public void update_exclusivelyManagedDevice_packageNotInstalled_addDevice()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater
|
when(mBluetoothDeviceUpdater
|
||||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -376,7 +373,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
ApplicationInfo appInfo = new ApplicationInfo();
|
ApplicationInfo appInfo = new ApplicationInfo();
|
||||||
appInfo.enabled = false;
|
appInfo.enabled = false;
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater
|
when(mBluetoothDeviceUpdater
|
||||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -393,7 +390,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_HIDE_EXCLUSIVELY_MANAGED_BLUETOOTH_DEVICE)
|
||||||
public void update_exclusivelyManagedDevice_packageInstalledAndEnabled_removePreference()
|
public void update_exclusivelyManagedDevice_packageInstalledAndEnabled_removePreference()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL);
|
||||||
when(mBluetoothDeviceUpdater
|
when(mBluetoothDeviceUpdater
|
||||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
@@ -407,4 +404,13 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||||
verify(mBluetoothDeviceUpdater, never()).addPreference(mCachedBluetoothDevice);
|
verify(mBluetoothDeviceUpdater, never()).addPreference(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setUpDeviceUpdaterWithAudioMode(int audioMode) {
|
||||||
|
mAudioManager.setMode(audioMode);
|
||||||
|
mBluetoothDeviceUpdater = spy(new ConnectedBluetoothDeviceUpdater(mContext,
|
||||||
|
mDevicePreferenceCallback, /* metricsCategory= */ 0));
|
||||||
|
mBluetoothDeviceUpdater.setPrefContext(mContext);
|
||||||
|
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
|
||||||
|
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user