diff options
| author | 2022-11-30 08:36:53 +0000 | |
|---|---|---|
| committer | 2022-11-30 08:36:53 +0000 | |
| commit | 7d1d59ac861f86f134f44ac0a4c9c19b5f3944d4 (patch) | |
| tree | d359ef1f160fb6576ddecb93f99e9f82c466f740 | |
| parent | 6d5d54efd057269475a7efc5385e2fed48efead4 (diff) | |
| parent | 6aa23612afbe6750db2d92c349c37180ddbbfe87 (diff) | |
Merge "AudioService: ensure sink role for communication device"
| -rw-r--r-- | media/java/android/media/AudioManager.java | 6 | ||||
| -rw-r--r-- | services/core/java/com/android/server/audio/AudioService.java | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index f3931df03327..9c5313aa3261 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -7670,8 +7670,10 @@ public class AudioManager { * or video calls. This method can be used by voice or video chat applications to select a * different audio device than the one selected by default by the platform. * <p>The device selection is expressed as an {@link AudioDeviceInfo} among devices returned by - * {@link #getAvailableCommunicationDevices()}. - * The selection is active as long as the requesting application process lives, until + * {@link #getAvailableCommunicationDevices()}. Note that only devices in a sink role + * (AKA output devices, see {@link AudioDeviceInfo#isSink()}) can be specified. The matching + * source device is selected automatically by the platform. + * <p>The selection is active as long as the requesting application process lives, until * {@link #clearCommunicationDevice} is called or until the device is disconnected. * It is therefore important for applications to clear the request when a call ends or the * the requesting activity or service is stopped or destroyed. diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index ae929c4dc5a1..2e810672fd64 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -5863,6 +5863,9 @@ public class AudioService extends IAudioService.Stub }; private boolean isValidCommunicationDevice(AudioDeviceInfo device) { + if (!device.isSink()) { + return false; + } for (int type : VALID_COMMUNICATION_DEVICE_TYPES) { if (device.getType() == type) { return true; @@ -5897,7 +5900,11 @@ public class AudioService extends IAudioService.Stub throw new IllegalArgumentException("invalid portID " + portId); } if (!isValidCommunicationDevice(device)) { - throw new IllegalArgumentException("invalid device type " + device.getType()); + if (!device.isSink()) { + throw new IllegalArgumentException("device must have sink role"); + } else { + throw new IllegalArgumentException("invalid device type: " + device.getType()); + } } } final String eventSource = new StringBuilder() |