diff options
author | jiabin <jiabin@google.com> | 2023-04-25 17:39:04 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-05-31 13:33:32 +0000 |
commit | bf75a05886e1234ce5edfcf4fc0f53abe95d1087 (patch) | |
tree | c51af5fffb2425e483d21b31f25572173be82acc | |
parent | 15c57882875d46eca14959eb31e97711a2d76e49 (diff) | |
download | base-bf75a05886e1234ce5edfcf4fc0f53abe95d1087.tar.gz |
USB: update logic for reporting playback and capture capability of USB devices.
Report USB devices support audio capture when there is a terminal whose
subtype is ACI_OUTPUT_TERMINAL and terminal type is USB streaming and
there is another terminal whose subtype is ACI_INPUT_TERMINAL and
terminal type is not USB streaming.
Report USB devices support audio playback when there is a terminal whose
subtype is ACI_INPUT_TERMINAL and terminal type is USB streaming and
there is another terminal whose subtype is ACI_OUTPUT_TERMINAL and
terminal type is not USB streaming.
Bug: 279151646
Bug: 278603582
Test: connect usb headset, dumpsys audio policy
(cherry picked from commit 9a5cab13b4b31ba9bf66e90ef07312959aa391d3)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e8e0134c04822f8f08a6dfad1a0cb9441c95c361)
Merged-In: If1c14cc0a4e3fbdfbed2c105d37ece9a866f18ed
Change-Id: If1c14cc0a4e3fbdfbed2c105d37ece9a866f18ed
-rw-r--r-- | services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java index 626ce8927158..55419a80b604 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java @@ -584,15 +584,34 @@ public final class UsbDescriptorParser { } /** + * Returns true only if there is a terminal whose subtype and terminal type are the same as + * the given values. * @hide */ - public boolean hasAudioTerminal(int subType) { + public boolean hasAudioTerminal(int subType, int terminalType) { for (UsbDescriptor descriptor : mDescriptors) { - if (descriptor instanceof UsbACInterface) { - if (((UsbACInterface) descriptor).getSubclass() - == UsbDescriptor.AUDIO_AUDIOCONTROL - && ((UsbACInterface) descriptor).getSubtype() - == subType) { + if (descriptor instanceof UsbACTerminal) { + if (((UsbACTerminal) descriptor).getSubclass() == UsbDescriptor.AUDIO_AUDIOCONTROL + && ((UsbACTerminal) descriptor).getSubtype() == subType + && ((UsbACTerminal) descriptor).getTerminalType() == terminalType) { + return true; + } + } + } + return false; + } + + /** + * Returns true only if there is an interface whose subtype is the same as the given one and + * terminal type is different from the given one. + * @hide + */ + public boolean hasAudioTerminalExcludeType(int subType, int excludedTerminalType) { + for (UsbDescriptor descriptor : mDescriptors) { + if (descriptor instanceof UsbACTerminal) { + if (((UsbACTerminal) descriptor).getSubclass() == UsbDescriptor.AUDIO_AUDIOCONTROL + && ((UsbACTerminal) descriptor).getSubtype() == subType + && ((UsbACTerminal) descriptor).getTerminalType() != excludedTerminalType) { return true; } } @@ -604,14 +623,21 @@ public final class UsbDescriptorParser { * @hide */ public boolean hasAudioPlayback() { - return hasAudioTerminal(UsbACInterface.ACI_OUTPUT_TERMINAL); + return hasAudioTerminalExcludeType( + UsbACInterface.ACI_OUTPUT_TERMINAL, UsbTerminalTypes.TERMINAL_USB_STREAMING) + && hasAudioTerminal( + UsbACInterface.ACI_INPUT_TERMINAL, UsbTerminalTypes.TERMINAL_USB_STREAMING); } /** * @hide */ public boolean hasAudioCapture() { - return hasAudioTerminal(UsbACInterface.ACI_INPUT_TERMINAL); + return hasAudioTerminalExcludeType( + UsbACInterface.ACI_INPUT_TERMINAL, UsbTerminalTypes.TERMINAL_USB_STREAMING) + && hasAudioTerminal( + UsbACInterface.ACI_OUTPUT_TERMINAL, + UsbTerminalTypes.TERMINAL_USB_STREAMING); } /** |