From 96fbf175893c5ebba1b66b458c3521bfb4123a24 Mon Sep 17 00:00:00 2001 From: jiabin Date: Fri, 23 Jun 2023 05:06:10 +0000 Subject: Fix USB power regression when connecting USB headset during phone/voip call. When a bi-direction USB device plugged in, first connect the output device and then the input device. The policy will prefer the paired input and output device. Connecting USB output device first can make the USB input device be used for phone/voip call once it is available. Also cache if the USB device support jack detect to avoid opening mixer when the jack detect is not supported. Bug: 282094846 Test: make Test: repo steps in the bug Change-Id: I7cc10b63c887493da284c8fad4384ee68bfd9337 --- services/usb/java/com/android/server/usb/UsbAlsaDevice.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/usb/java/com/android/server/usb/UsbAlsaDevice.java b/services/usb/java/com/android/server/usb/UsbAlsaDevice.java index 7fe8582f96de..c508fa968b14 100644 --- a/services/usb/java/com/android/server/usb/UsbAlsaDevice.java +++ b/services/usb/java/com/android/server/usb/UsbAlsaDevice.java @@ -59,6 +59,8 @@ public final class UsbAlsaDevice { private String mDeviceName = ""; private String mDeviceDescription = ""; + private boolean mHasJackDetect = true; + public UsbAlsaDevice(IAudioService audioService, int card, int device, String deviceAddress, boolean hasOutput, boolean hasInput, boolean isInputHeadset, boolean isOutputHeadset, boolean isDock) { @@ -168,8 +170,14 @@ public final class UsbAlsaDevice { if (mJackDetector != null) { return; } + if (!mHasJackDetect) { + return; + } // If no jack detect capabilities exist, mJackDetector will be null. mJackDetector = UsbAlsaJackDetector.startJackDetect(this); + if (mJackDetector == null) { + mHasJackDetect = false; + } } /** Stops a jack-detection thread. */ @@ -182,8 +190,8 @@ public final class UsbAlsaDevice { /** Start using this device as the selected USB Audio Device. */ public synchronized void start() { - startInput(); startOutput(); + startInput(); } /** Start using this device as the selected USB input device. */ @@ -208,8 +216,8 @@ public final class UsbAlsaDevice { /** Stop using this device as the selected USB Audio Device. */ public synchronized void stop() { - stopInput(); stopOutput(); + stopInput(); } /** Stop using this device as the selected USB input device. */ -- cgit v1.2.3-59-g8ed1b