Replace deprecated APIs in audio switcher.
- Remove isWiredHeadsetOn() and isBluetoothA2dpOn() in MediaOutputPreferenceController. - Remove isWiredHeadsetOn() and isBluetoothScoOn() in HandsFreeProfileOutputPreferenceController. - Replace with AudioManager.getDevicesForStream(). - Update test cases. Bug: 78141441 Test: make RunSettingsRoboTests ROBOTEST_FILTER="MediaOutputPreferenceControllerTest" -j40 Test: make RunSettingsRoboTests ROBOTEST_FILTER="HandsFreeProfileOutputPreferenceControllerTest" -j40 Test: make RunSettingsRoboTests ROBOTEST_FILTER="AudioOutputSwitchPreferenceControllerTest" -j40 Change-Id: Ic57c40badf0fd5633f1b7412d63a0b5417d0f47a
This commit is contained in:
@@ -193,8 +193,12 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
|
|||||||
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
|
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isStreamFromOutputDevice(int streamType, int device) {
|
||||||
|
return mAudioManager.getDevicesForStream(streamType) == device;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean isOngoingCallStatus() {
|
protected boolean isOngoingCallStatus() {
|
||||||
int audioMode = mAudioManager.getMode();
|
final int audioMode = mAudioManager.getMode();
|
||||||
return audioMode == AudioManager.MODE_RINGTONE
|
return audioMode == AudioManager.MODE_RINGTONE
|
||||||
|| audioMode == AudioManager.MODE_IN_CALL
|
|| audioMode == AudioManager.MODE_IN_CALL
|
||||||
|| audioMode == AudioManager.MODE_IN_COMMUNICATION;
|
|| audioMode == AudioManager.MODE_IN_COMMUNICATION;
|
||||||
|
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.sound;
|
package com.android.settings.sound;
|
||||||
|
|
||||||
|
import static android.media.AudioManager.STREAM_VOICE_CALL;
|
||||||
|
import static android.media.AudioSystem.DEVICE_OUT_USB_HEADSET;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
@@ -76,7 +79,7 @@ public class HandsFreeProfileOutputPreferenceController extends
|
|||||||
// Setup devices entries, select active connected device
|
// Setup devices entries, select active connected device
|
||||||
setupPreferenceEntries(mediaOutputs, mediaValues, activeDevice);
|
setupPreferenceEntries(mediaOutputs, mediaValues, activeDevice);
|
||||||
|
|
||||||
if (mAudioManager.isWiredHeadsetOn() && !mAudioManager.isBluetoothScoOn()) {
|
if (isStreamFromOutputDevice(STREAM_VOICE_CALL, DEVICE_OUT_USB_HEADSET)) {
|
||||||
// If wired headset is plugged in and active, select to default device.
|
// If wired headset is plugged in and active, select to default device.
|
||||||
mSelectedIndex = getDefaultDeviceIndex();
|
mSelectedIndex = getDefaultDeviceIndex();
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.sound;
|
package com.android.settings.sound;
|
||||||
|
|
||||||
|
import static android.media.AudioManager.STREAM_VOICE_CALL;
|
||||||
|
import static android.media.AudioSystem.DEVICE_OUT_USB_HEADSET;
|
||||||
import static android.media.MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY;
|
import static android.media.MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
@@ -91,7 +93,7 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
|
|||||||
// Setup devices entries, select active connected device
|
// Setup devices entries, select active connected device
|
||||||
setupPreferenceEntries(mediaOutputs, mediaValues, activeDevice);
|
setupPreferenceEntries(mediaOutputs, mediaValues, activeDevice);
|
||||||
|
|
||||||
if (mAudioManager.isWiredHeadsetOn() && !mAudioManager.isBluetoothA2dpOn()) {
|
if (isStreamFromOutputDevice(STREAM_VOICE_CALL, DEVICE_OUT_USB_HEADSET)) {
|
||||||
// If wired headset is plugged in and active, select to default device.
|
// If wired headset is plugged in and active, select to default device.
|
||||||
mSelectedIndex = getDefaultDeviceIndex();
|
mSelectedIndex = getDefaultDeviceIndex();
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
package com.android.settings.sound;
|
package com.android.settings.sound;
|
||||||
|
|
||||||
|
|
||||||
|
import static android.media.AudioSystem.DEVICE_OUT_USB_HEADSET;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@@ -205,10 +207,9 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
|
|||||||
* Preference summary should be "This device"
|
* Preference summary should be "This device"
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void hapBtDevicesAreAvailableButWiredHeadsetIsActivated_shouldSetDefaultSummary() {
|
public void updateState_withAvailableDevicesWiredHeadsetActivated_shouldSetDefaultSummary() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
||||||
mShadowAudioManager.setWiredHeadsetOn(true);
|
mShadowAudioManager.setStream(DEVICE_OUT_USB_HEADSET);
|
||||||
mShadowAudioManager.setBluetoothScoOn(false);
|
|
||||||
when(mHeadsetProfile.getConnectedDevices()).thenReturn(mConnectedDevices);
|
when(mHeadsetProfile.getConnectedDevices()).thenReturn(mConnectedDevices);
|
||||||
when(mHeadsetProfile.getActiveDevice()).thenReturn(
|
when(mHeadsetProfile.getActiveDevice()).thenReturn(
|
||||||
mBluetoothDevice); // BT device is still activated in this case
|
mBluetoothDevice); // BT device is still activated in this case
|
||||||
@@ -226,7 +227,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
|
|||||||
* Preference summary should be "This device"
|
* Preference summary should be "This device"
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void noAvailableHeadsetBtDevices_preferenceEnableIsFalse_shouldSetDefaultSummary() {
|
public void updateState_noAvailableHeadsetBtDevices_shouldSetDefaultSummary() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
||||||
List<BluetoothDevice> emptyDeviceList = new ArrayList<>();
|
List<BluetoothDevice> emptyDeviceList = new ArrayList<>();
|
||||||
when(mHeadsetProfile.getConnectedDevices()).thenReturn(emptyDeviceList);
|
when(mHeadsetProfile.getConnectedDevices()).thenReturn(emptyDeviceList);
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
package com.android.settings.sound;
|
package com.android.settings.sound;
|
||||||
|
|
||||||
|
|
||||||
|
import static android.media.AudioSystem.DEVICE_OUT_USB_HEADSET;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@@ -256,8 +258,7 @@ public class MediaOutputPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateState_a2dpDevicesAvailableWiredHeadsetIsActivated_shouldSetDefaultSummary() {
|
public void updateState_a2dpDevicesAvailableWiredHeadsetIsActivated_shouldSetDefaultSummary() {
|
||||||
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
|
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
mShadowAudioManager.setWiredHeadsetOn(true);
|
mShadowAudioManager.setStream(DEVICE_OUT_USB_HEADSET);
|
||||||
mShadowAudioManager.setBluetoothA2dpOn(false);
|
|
||||||
when(mA2dpProfile.getConnectedDevices()).thenReturn(mConnectedDevices);
|
when(mA2dpProfile.getConnectedDevices()).thenReturn(mConnectedDevices);
|
||||||
when(mA2dpProfile.getActiveDevice()).thenReturn(
|
when(mA2dpProfile.getActiveDevice()).thenReturn(
|
||||||
mBluetoothDevice); // BT device is still activated in this case
|
mBluetoothDevice); // BT device is still activated in this case
|
||||||
|
@@ -16,6 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.testutils.shadow;
|
package com.android.settings.testutils.shadow;
|
||||||
|
|
||||||
|
import static android.media.AudioManager.STREAM_ACCESSIBILITY;
|
||||||
|
import static android.media.AudioManager.STREAM_ALARM;
|
||||||
|
import static android.media.AudioManager.STREAM_MUSIC;
|
||||||
|
import static android.media.AudioManager.STREAM_NOTIFICATION;
|
||||||
|
import static android.media.AudioManager.STREAM_RING;
|
||||||
|
import static android.media.AudioManager.STREAM_SYSTEM;
|
||||||
|
import static android.media.AudioManager.STREAM_VOICE_CALL;
|
||||||
|
import static android.media.AudioManager.STREAM_DTMF;
|
||||||
|
|
||||||
import static org.robolectric.RuntimeEnvironment.application;
|
import static org.robolectric.RuntimeEnvironment.application;
|
||||||
|
|
||||||
import android.media.AudioDeviceCallback;
|
import android.media.AudioDeviceCallback;
|
||||||
@@ -32,6 +41,7 @@ import java.util.ArrayList;
|
|||||||
@Implements(value = AudioManager.class, inheritImplementationMethods = true)
|
@Implements(value = AudioManager.class, inheritImplementationMethods = true)
|
||||||
public class ShadowAudioManager extends org.robolectric.shadows.ShadowAudioManager {
|
public class ShadowAudioManager extends org.robolectric.shadows.ShadowAudioManager {
|
||||||
private int mRingerMode;
|
private int mRingerMode;
|
||||||
|
private int mStream;
|
||||||
private boolean mMusicActiveRemotely = false;
|
private boolean mMusicActiveRemotely = false;
|
||||||
private ArrayList<AudioDeviceCallback> mDeviceCallbacks = new ArrayList();
|
private ArrayList<AudioDeviceCallback> mDeviceCallbacks = new ArrayList();
|
||||||
|
|
||||||
@@ -48,10 +58,12 @@ public class ShadowAudioManager extends org.robolectric.shadows.ShadowAudioManag
|
|||||||
mRingerMode = mode;
|
mRingerMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
public void registerAudioDeviceCallback(AudioDeviceCallback callback, Handler handler) {
|
public void registerAudioDeviceCallback(AudioDeviceCallback callback, Handler handler) {
|
||||||
mDeviceCallbacks.add(callback);
|
mDeviceCallbacks.add(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
public void unregisterAudioDeviceCallback(AudioDeviceCallback callback) {
|
public void unregisterAudioDeviceCallback(AudioDeviceCallback callback) {
|
||||||
if (mDeviceCallbacks.contains(callback)) {
|
if (mDeviceCallbacks.contains(callback)) {
|
||||||
mDeviceCallbacks.remove(callback);
|
mDeviceCallbacks.remove(callback);
|
||||||
@@ -62,10 +74,32 @@ public class ShadowAudioManager extends org.robolectric.shadows.ShadowAudioManag
|
|||||||
mMusicActiveRemotely = flag;
|
mMusicActiveRemotely = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
public boolean isMusicActiveRemotely() {
|
public boolean isMusicActiveRemotely() {
|
||||||
return mMusicActiveRemotely;
|
return mMusicActiveRemotely;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStream(int stream) {
|
||||||
|
mStream = stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public int getDevicesForStream(int streamType) {
|
||||||
|
switch (streamType) {
|
||||||
|
case STREAM_VOICE_CALL:
|
||||||
|
case STREAM_SYSTEM:
|
||||||
|
case STREAM_RING:
|
||||||
|
case STREAM_MUSIC:
|
||||||
|
case STREAM_ALARM:
|
||||||
|
case STREAM_NOTIFICATION:
|
||||||
|
case STREAM_DTMF:
|
||||||
|
case STREAM_ACCESSIBILITY:
|
||||||
|
return mStream;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Resetter
|
@Resetter
|
||||||
public void reset() {
|
public void reset() {
|
||||||
mDeviceCallbacks.clear();
|
mDeviceCallbacks.clear();
|
||||||
|
Reference in New Issue
Block a user