Find active device for add hearing aids device into audio switcher.
- Find active device accroding to different stream type and output device. - update isStreamFromOutputDevice() to identify general case like DEVICE_OUT_BLUETOOTH_A2DP is subset of DEVICE_OUT_ALL_A2DP. - add test case for these methods. Bug: 78142719 Test: make RunSettingsRoboTests ROBOTEST_FILTER="AudioOutputSwitchPreferenceControllerTest" -j28 Change-Id: I381135c120dbf051679bff7626d47e41f8d589da
This commit is contained in:
@@ -203,7 +203,7 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
|
||||
}
|
||||
|
||||
protected boolean isStreamFromOutputDevice(int streamType, int device) {
|
||||
return mAudioManager.getDevicesForStream(streamType) == device;
|
||||
return (device & mAudioManager.getDevicesForStream(streamType)) != 0;
|
||||
}
|
||||
|
||||
protected boolean isOngoingCallStatus() {
|
||||
@@ -272,6 +272,40 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
|
||||
return connectedDevices;
|
||||
}
|
||||
|
||||
/**
|
||||
* According to different stream and output device, find the active device from
|
||||
* the corresponding profile. Hearing aid device could stream both STREAM_MUSIC
|
||||
* and STREAM_VOICE_CALL.
|
||||
*
|
||||
* @param streamType the type of audio streams.
|
||||
* @return the active device. Return null if the active device is current device
|
||||
* or streamType is not STREAM_MUSIC or STREAM_VOICE_CALL.
|
||||
*/
|
||||
protected BluetoothDevice findActiveDevice(int streamType) {
|
||||
if (streamType != STREAM_MUSIC && streamType != STREAM_VOICE_CALL) {
|
||||
return null;
|
||||
}
|
||||
if (isStreamFromOutputDevice(STREAM_MUSIC, DEVICE_OUT_ALL_A2DP)) {
|
||||
return mProfileManager.getA2dpProfile().getActiveDevice();
|
||||
} else if (isStreamFromOutputDevice(STREAM_VOICE_CALL, DEVICE_OUT_ALL_SCO)) {
|
||||
return mProfileManager.getHeadsetProfile().getActiveDevice();
|
||||
} else if (isStreamFromOutputDevice(streamType, DEVICE_OUT_HEARING_AID)) {
|
||||
// The first element is the left active device; the second element is
|
||||
// the right active device. And they will have same hiSyncId. If either
|
||||
// or both side is not active, it will be null on that position.
|
||||
List<BluetoothDevice> activeDevices =
|
||||
mProfileManager.getHearingAidProfile().getActiveDevices();
|
||||
for (BluetoothDevice btDevice : activeDevices) {
|
||||
if (btDevice != null && mConnectedDevices.contains(btDevice)) {
|
||||
// also need to check mConnectedDevices, because one of
|
||||
// the device(same hiSyncId) might not be shown in the UI.
|
||||
return btDevice;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
int getDefaultDeviceIndex() {
|
||||
// Default device is after all connected devices.
|
||||
return ArrayUtils.size(mConnectedDevices);
|
||||
|
Reference in New Issue
Block a user