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