Skip to content

Commit bf75a05

Browse files
flammeAndroid Build Coastguard Worker
authored andcommitted
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
1 parent 15c5788 commit bf75a05

1 file changed

Lines changed: 34 additions & 8 deletions

File tree

services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,15 +584,34 @@ public boolean hasAudioInterface() {
584584
}
585585

586586
/**
587+
* Returns true only if there is a terminal whose subtype and terminal type are the same as
588+
* the given values.
587589
* @hide
588590
*/
589-
public boolean hasAudioTerminal(int subType) {
591+
public boolean hasAudioTerminal(int subType, int terminalType) {
590592
for (UsbDescriptor descriptor : mDescriptors) {
591-
if (descriptor instanceof UsbACInterface) {
592-
if (((UsbACInterface) descriptor).getSubclass()
593-
== UsbDescriptor.AUDIO_AUDIOCONTROL
594-
&& ((UsbACInterface) descriptor).getSubtype()
595-
== subType) {
593+
if (descriptor instanceof UsbACTerminal) {
594+
if (((UsbACTerminal) descriptor).getSubclass() == UsbDescriptor.AUDIO_AUDIOCONTROL
595+
&& ((UsbACTerminal) descriptor).getSubtype() == subType
596+
&& ((UsbACTerminal) descriptor).getTerminalType() == terminalType) {
597+
return true;
598+
}
599+
}
600+
}
601+
return false;
602+
}
603+
604+
/**
605+
* Returns true only if there is an interface whose subtype is the same as the given one and
606+
* terminal type is different from the given one.
607+
* @hide
608+
*/
609+
public boolean hasAudioTerminalExcludeType(int subType, int excludedTerminalType) {
610+
for (UsbDescriptor descriptor : mDescriptors) {
611+
if (descriptor instanceof UsbACTerminal) {
612+
if (((UsbACTerminal) descriptor).getSubclass() == UsbDescriptor.AUDIO_AUDIOCONTROL
613+
&& ((UsbACTerminal) descriptor).getSubtype() == subType
614+
&& ((UsbACTerminal) descriptor).getTerminalType() != excludedTerminalType) {
596615
return true;
597616
}
598617
}
@@ -604,14 +623,21 @@ public boolean hasAudioTerminal(int subType) {
604623
* @hide
605624
*/
606625
public boolean hasAudioPlayback() {
607-
return hasAudioTerminal(UsbACInterface.ACI_OUTPUT_TERMINAL);
626+
return hasAudioTerminalExcludeType(
627+
UsbACInterface.ACI_OUTPUT_TERMINAL, UsbTerminalTypes.TERMINAL_USB_STREAMING)
628+
&& hasAudioTerminal(
629+
UsbACInterface.ACI_INPUT_TERMINAL, UsbTerminalTypes.TERMINAL_USB_STREAMING);
608630
}
609631

610632
/**
611633
* @hide
612634
*/
613635
public boolean hasAudioCapture() {
614-
return hasAudioTerminal(UsbACInterface.ACI_INPUT_TERMINAL);
636+
return hasAudioTerminalExcludeType(
637+
UsbACInterface.ACI_INPUT_TERMINAL, UsbTerminalTypes.TERMINAL_USB_STREAMING)
638+
&& hasAudioTerminal(
639+
UsbACInterface.ACI_OUTPUT_TERMINAL,
640+
UsbTerminalTypes.TERMINAL_USB_STREAMING);
615641
}
616642

617643
/**

0 commit comments

Comments
 (0)