Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +6 −16 Original line number Diff line number Diff line Loading @@ -555,22 +555,17 @@ public class BluetoothUtils { * connected 2) is Hearing Aid or LE Audio OR 3) connected profile matches currentAudioProfile * * @param cachedDevice the CachedBluetoothDevice * @param audioManager audio manager to get the current audio profile * @param isOngoingCall get the current audio profile based on if in phone call * @return if the device is AvailableMediaBluetoothDevice */ @WorkerThread public static boolean isAvailableMediaBluetoothDevice( CachedBluetoothDevice cachedDevice, AudioManager audioManager) { int audioMode = audioManager.getMode(); CachedBluetoothDevice cachedDevice, boolean isOngoingCall) { int currentAudioProfile; if (audioMode == AudioManager.MODE_RINGTONE || audioMode == AudioManager.MODE_IN_CALL || audioMode == AudioManager.MODE_IN_COMMUNICATION) { // in phone call if (isOngoingCall) { currentAudioProfile = BluetoothProfile.HEADSET; } else { // without phone call currentAudioProfile = BluetoothProfile.A2DP; } Loading Loading @@ -859,22 +854,17 @@ public class BluetoothUtils { * currentAudioProfile * * @param cachedDevice the CachedBluetoothDevice * @param audioManager audio manager to get the current audio profile * @param isOngoingCall get the current audio profile based on if in phone call * @return if the device is AvailableMediaBluetoothDevice */ @WorkerThread public static boolean isConnectedBluetoothDevice( CachedBluetoothDevice cachedDevice, AudioManager audioManager) { int audioMode = audioManager.getMode(); CachedBluetoothDevice cachedDevice, boolean isOngoingCall) { int currentAudioProfile; if (audioMode == AudioManager.MODE_RINGTONE || audioMode == AudioManager.MODE_IN_CALL || audioMode == AudioManager.MODE_IN_COMMUNICATION) { // in phone call if (isOngoingCall) { currentAudioProfile = BluetoothProfile.HEADSET; } else { // without phone call currentAudioProfile = BluetoothProfile.A2DP; } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +14 −22 Original line number Diff line number Diff line Loading @@ -87,7 +87,6 @@ public class BluetoothUtilsTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private BluetoothDevice mBluetoothDevice; @Mock private AudioManager mAudioManager; @Mock private PackageManager mPackageManager; @Mock private LeAudioProfile mA2dpProfile; @Mock private LeAudioProfile mLeAudioProfile; Loading Loading @@ -446,13 +445,12 @@ public class BluetoothUtilsTest { assertThat( BluetoothUtils.isAvailableMediaBluetoothDevice( mCachedBluetoothDevice, mAudioManager)) mCachedBluetoothDevice, /* isOngoingCall= */ false)) .isTrue(); } @Test public void isAvailableMediaBluetoothDevice_isHeadset_isConnectedA2dpDevice_returnFalse() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_RINGTONE); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); Loading @@ -460,13 +458,12 @@ public class BluetoothUtilsTest { assertThat( BluetoothUtils.isAvailableMediaBluetoothDevice( mCachedBluetoothDevice, mAudioManager)) mCachedBluetoothDevice, /* isOngoingCall= */ true)) .isFalse(); } @Test public void isAvailableMediaBluetoothDevice_isA2dp_isConnectedA2dpDevice_returnTrue() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); Loading @@ -474,13 +471,12 @@ public class BluetoothUtilsTest { assertThat( BluetoothUtils.isAvailableMediaBluetoothDevice( mCachedBluetoothDevice, mAudioManager)) mCachedBluetoothDevice, /* isOngoingCall= */ false)) .isTrue(); } @Test public void isAvailableMediaBluetoothDevice_isHeadset_isConnectedHfpDevice_returnTrue() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_RINGTONE); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); Loading @@ -488,7 +484,7 @@ public class BluetoothUtilsTest { assertThat( BluetoothUtils.isAvailableMediaBluetoothDevice( mCachedBluetoothDevice, mAudioManager)) mCachedBluetoothDevice, /* isOngoingCall= */ true)) .isTrue(); } Loading @@ -499,56 +495,52 @@ public class BluetoothUtilsTest { when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.isConnected()).thenReturn(true); assertThat(BluetoothUtils.isConnectedBluetoothDevice(mCachedBluetoothDevice, mAudioManager)) .isFalse(); assertThat(BluetoothUtils.isConnectedBluetoothDevice( mCachedBluetoothDevice, /* isOngoingCall= */ false)).isFalse(); } @Test public void isConnectedBluetoothDevice_isHeadset_isConnectedA2dpDevice_returnTrue() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_RINGTONE); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.isConnected()).thenReturn(true); assertThat(BluetoothUtils.isConnectedBluetoothDevice(mCachedBluetoothDevice, mAudioManager)) .isTrue(); assertThat(BluetoothUtils.isConnectedBluetoothDevice( mCachedBluetoothDevice, /* isOngoingCall= */ true)).isTrue(); } @Test public void isConnectedBluetoothDevice_isA2dp_isConnectedA2dpDevice_returnFalse() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.isConnected()).thenReturn(true); assertThat(BluetoothUtils.isConnectedBluetoothDevice(mCachedBluetoothDevice, mAudioManager)) .isFalse(); assertThat(BluetoothUtils.isConnectedBluetoothDevice( mCachedBluetoothDevice, /* isOngoingCall= */ false)).isFalse(); } @Test public void isConnectedBluetoothDevice_isHeadset_isConnectedHfpDevice_returnFalse() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_RINGTONE); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.isConnected()).thenReturn(true); assertThat(BluetoothUtils.isConnectedBluetoothDevice(mCachedBluetoothDevice, mAudioManager)) .isFalse(); assertThat(BluetoothUtils.isConnectedBluetoothDevice( mCachedBluetoothDevice, /* isOngoingCall= */ true)).isFalse(); } @Test public void isConnectedBluetoothDevice_isNotConnected_returnFalse() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_RINGTONE); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.isConnected()).thenReturn(false); assertThat(BluetoothUtils.isConnectedBluetoothDevice(mCachedBluetoothDevice, mAudioManager)) .isFalse(); assertThat(BluetoothUtils.isConnectedBluetoothDevice( mCachedBluetoothDevice, /* isOngoingCall= */ true)).isFalse(); } @Test Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +6 −16 Original line number Diff line number Diff line Loading @@ -555,22 +555,17 @@ public class BluetoothUtils { * connected 2) is Hearing Aid or LE Audio OR 3) connected profile matches currentAudioProfile * * @param cachedDevice the CachedBluetoothDevice * @param audioManager audio manager to get the current audio profile * @param isOngoingCall get the current audio profile based on if in phone call * @return if the device is AvailableMediaBluetoothDevice */ @WorkerThread public static boolean isAvailableMediaBluetoothDevice( CachedBluetoothDevice cachedDevice, AudioManager audioManager) { int audioMode = audioManager.getMode(); CachedBluetoothDevice cachedDevice, boolean isOngoingCall) { int currentAudioProfile; if (audioMode == AudioManager.MODE_RINGTONE || audioMode == AudioManager.MODE_IN_CALL || audioMode == AudioManager.MODE_IN_COMMUNICATION) { // in phone call if (isOngoingCall) { currentAudioProfile = BluetoothProfile.HEADSET; } else { // without phone call currentAudioProfile = BluetoothProfile.A2DP; } Loading Loading @@ -859,22 +854,17 @@ public class BluetoothUtils { * currentAudioProfile * * @param cachedDevice the CachedBluetoothDevice * @param audioManager audio manager to get the current audio profile * @param isOngoingCall get the current audio profile based on if in phone call * @return if the device is AvailableMediaBluetoothDevice */ @WorkerThread public static boolean isConnectedBluetoothDevice( CachedBluetoothDevice cachedDevice, AudioManager audioManager) { int audioMode = audioManager.getMode(); CachedBluetoothDevice cachedDevice, boolean isOngoingCall) { int currentAudioProfile; if (audioMode == AudioManager.MODE_RINGTONE || audioMode == AudioManager.MODE_IN_CALL || audioMode == AudioManager.MODE_IN_COMMUNICATION) { // in phone call if (isOngoingCall) { currentAudioProfile = BluetoothProfile.HEADSET; } else { // without phone call currentAudioProfile = BluetoothProfile.A2DP; } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +14 −22 Original line number Diff line number Diff line Loading @@ -87,7 +87,6 @@ public class BluetoothUtilsTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private BluetoothDevice mBluetoothDevice; @Mock private AudioManager mAudioManager; @Mock private PackageManager mPackageManager; @Mock private LeAudioProfile mA2dpProfile; @Mock private LeAudioProfile mLeAudioProfile; Loading Loading @@ -446,13 +445,12 @@ public class BluetoothUtilsTest { assertThat( BluetoothUtils.isAvailableMediaBluetoothDevice( mCachedBluetoothDevice, mAudioManager)) mCachedBluetoothDevice, /* isOngoingCall= */ false)) .isTrue(); } @Test public void isAvailableMediaBluetoothDevice_isHeadset_isConnectedA2dpDevice_returnFalse() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_RINGTONE); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); Loading @@ -460,13 +458,12 @@ public class BluetoothUtilsTest { assertThat( BluetoothUtils.isAvailableMediaBluetoothDevice( mCachedBluetoothDevice, mAudioManager)) mCachedBluetoothDevice, /* isOngoingCall= */ true)) .isFalse(); } @Test public void isAvailableMediaBluetoothDevice_isA2dp_isConnectedA2dpDevice_returnTrue() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); Loading @@ -474,13 +471,12 @@ public class BluetoothUtilsTest { assertThat( BluetoothUtils.isAvailableMediaBluetoothDevice( mCachedBluetoothDevice, mAudioManager)) mCachedBluetoothDevice, /* isOngoingCall= */ false)) .isTrue(); } @Test public void isAvailableMediaBluetoothDevice_isHeadset_isConnectedHfpDevice_returnTrue() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_RINGTONE); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); Loading @@ -488,7 +484,7 @@ public class BluetoothUtilsTest { assertThat( BluetoothUtils.isAvailableMediaBluetoothDevice( mCachedBluetoothDevice, mAudioManager)) mCachedBluetoothDevice, /* isOngoingCall= */ true)) .isTrue(); } Loading @@ -499,56 +495,52 @@ public class BluetoothUtilsTest { when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.isConnected()).thenReturn(true); assertThat(BluetoothUtils.isConnectedBluetoothDevice(mCachedBluetoothDevice, mAudioManager)) .isFalse(); assertThat(BluetoothUtils.isConnectedBluetoothDevice( mCachedBluetoothDevice, /* isOngoingCall= */ false)).isFalse(); } @Test public void isConnectedBluetoothDevice_isHeadset_isConnectedA2dpDevice_returnTrue() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_RINGTONE); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.isConnected()).thenReturn(true); assertThat(BluetoothUtils.isConnectedBluetoothDevice(mCachedBluetoothDevice, mAudioManager)) .isTrue(); assertThat(BluetoothUtils.isConnectedBluetoothDevice( mCachedBluetoothDevice, /* isOngoingCall= */ true)).isTrue(); } @Test public void isConnectedBluetoothDevice_isA2dp_isConnectedA2dpDevice_returnFalse() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.isConnected()).thenReturn(true); assertThat(BluetoothUtils.isConnectedBluetoothDevice(mCachedBluetoothDevice, mAudioManager)) .isFalse(); assertThat(BluetoothUtils.isConnectedBluetoothDevice( mCachedBluetoothDevice, /* isOngoingCall= */ false)).isFalse(); } @Test public void isConnectedBluetoothDevice_isHeadset_isConnectedHfpDevice_returnFalse() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_RINGTONE); when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.isConnected()).thenReturn(true); assertThat(BluetoothUtils.isConnectedBluetoothDevice(mCachedBluetoothDevice, mAudioManager)) .isFalse(); assertThat(BluetoothUtils.isConnectedBluetoothDevice( mCachedBluetoothDevice, /* isOngoingCall= */ true)).isFalse(); } @Test public void isConnectedBluetoothDevice_isNotConnected_returnFalse() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_RINGTONE); when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mBluetoothDevice.isConnected()).thenReturn(false); assertThat(BluetoothUtils.isConnectedBluetoothDevice(mCachedBluetoothDevice, mAudioManager)) .isFalse(); assertThat(BluetoothUtils.isConnectedBluetoothDevice( mCachedBluetoothDevice, /* isOngoingCall= */ true)).isFalse(); } @Test Loading