Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3f43b564 authored by Terry Cheong's avatar Terry Cheong
Browse files

Treat SND_JACK_AVOUT as HDMI audio jack

Add detection logic for jacks that emit SND_JACK_AVOUT and treat that as
HDMI audio. Separate the logic from headphone, lineout and microphone to
avoid conflict and allow the use case for switching between HDMI audio
and headphones.

For Android desktop devices the HDMI audio jack is defined to emit
SND_JACK_AVOUT.

Bug: 411037918
Test: Plug in HDMI and 3.5mm headphone and verify both audio devices exist
Flag: EXEMPT Change for desktop audio support
Change-Id: If7ac3aeb7017dd690735e8b4077d63cceb6886c3
parent c018324a
Loading
Loading
Loading
Loading
+60 −38
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import static com.android.server.input.InputManagerService.SW_HEADPHONE_INSERT;
import static com.android.server.input.InputManagerService.SW_HEADPHONE_INSERT_BIT;
import static com.android.server.input.InputManagerService.SW_LINEOUT_INSERT;
import static com.android.server.input.InputManagerService.SW_LINEOUT_INSERT_BIT;
import static com.android.server.input.InputManagerService.SW_VIDEOOUT_INSERT;
import static com.android.server.input.InputManagerService.SW_VIDEOOUT_INSERT_BIT;
import static com.android.server.input.InputManagerService.SW_MICROPHONE_INSERT;
import static com.android.server.input.InputManagerService.SW_MICROPHONE_INSERT_BIT;

@@ -66,6 +68,9 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
    private static final int SUPPORTED_HEADSETS = (BIT_HEADSET | BIT_HEADSET_NO_MIC |
            BIT_USB_HEADSET_ANLG | BIT_USB_HEADSET_DGTL |
            BIT_HDMI_AUDIO | BIT_LINEOUT);
    private static final int SW_HEADSET_INSERT_BITS =
            SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT;
    private static final int SW_AVOUT_INSERT_BITS = SW_LINEOUT_INSERT_BIT | SW_VIDEOOUT_INSERT_BIT;

    private static final String NAME_H2W = "h2w";
    private static final String NAME_USB_AUDIO = "usb_audio";
@@ -82,8 +87,6 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {

    private int mHeadsetState;

    private int mSwitchValues;

    private final WiredAccessoryObserver mObserver;
    private final WiredAccessoryExtconObserver mExtconObserver;
    private final InputManagerService mInputManager;
@@ -118,13 +121,27 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
            if (mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, SW_LINEOUT_INSERT) == 1) {
                switchValues |= SW_LINEOUT_INSERT_BIT;
            }
            if (mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, SW_VIDEOOUT_INSERT) == 1) {
                switchValues |= SW_VIDEOOUT_INSERT_BIT;
            }
            // Making our best guess here.
            int headphone = switchValues & SW_HEADSET_INSERT_BITS;
            if (headphone != 0) {
                notifyWiredAccessoryChanged(
                            0,
                    switchValues,
                    SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_LINEOUT_INSERT_BIT,
                            headphone,
                            headphone,
                            true /*isSynchronous*/);
            }

            int lineout_or_hdmi = switchValues & SW_AVOUT_INSERT_BITS;
            if (lineout_or_hdmi != 0) {
                notifyWiredAccessoryChanged(
                            0,
                            lineout_or_hdmi,
                            lineout_or_hdmi,
                            true /*isSynchronous*/);
            }
        }

        if (ExtconUEventObserver.extconExists()) {
            if (mUseDevInputEventForAudioJack) {
@@ -152,40 +169,45 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
        }

        synchronized (mLock) {
            int headset;
            mSwitchValues = (mSwitchValues & ~switchMask) | switchValues;
            switch (mSwitchValues &
                    (SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_LINEOUT_INSERT_BIT)) {
                case 0:
                    headset = 0;
                    break;

                case SW_HEADPHONE_INSERT_BIT:
                    headset = BIT_HEADSET_NO_MIC;
                    break;

                case SW_LINEOUT_INSERT_BIT:
                    headset = BIT_LINEOUT;
                    break;
            // Assumptions:
            // 1. Events will only be plug 1 device or unplug 1 device.
            //    It would not have plug and unplug in the same time.
            // 2. events for LINEOUT devices won't have a mask that
            //    is SW_AVOUT_INSERT_BITS
            int newHeadsetState = mHeadsetState;
            if ((switchMask & SW_HEADSET_INSERT_BITS) != 0) {
                int clearMask = BIT_HEADSET | BIT_HEADSET_NO_MIC;

                newHeadsetState = newHeadsetState & ~clearMask;
                int device = switch(switchValues & SW_HEADSET_INSERT_BITS) {
                    case SW_HEADPHONE_INSERT_BIT -> BIT_HEADSET_NO_MIC;
                    case SW_MICROPHONE_INSERT_BIT -> BIT_HEADSET;
                    case SW_HEADSET_INSERT_BITS -> BIT_HEADSET;
                    default -> 0;
                };
                newHeadsetState = newHeadsetState | device;
            }

                case SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT:
                    headset = BIT_HEADSET;
                    break;
            if ((switchMask & SW_AVOUT_INSERT_BITS) != 0) {
                int clearMask = switch(switchMask & SW_AVOUT_INSERT_BITS) {
                    case SW_LINEOUT_INSERT_BIT -> BIT_LINEOUT;
                    case SW_AVOUT_INSERT_BITS -> BIT_HDMI_AUDIO;
                    default -> 0;
                };

                case SW_MICROPHONE_INSERT_BIT:
                    headset = BIT_HEADSET;
                    break;
                newHeadsetState = newHeadsetState & ~clearMask;
                int device = switch(switchValues & SW_AVOUT_INSERT_BITS) {
                    case SW_LINEOUT_INSERT_BIT -> BIT_LINEOUT;
                    case SW_AVOUT_INSERT_BITS -> BIT_HDMI_AUDIO;
                    default -> 0;
                };

                default:
                    headset = 0;
                    break;
                newHeadsetState = newHeadsetState | device;
            }

            updateLocked(
                    NAME_H2W,
                    (mHeadsetState & ~(BIT_HEADSET | BIT_HEADSET_NO_MIC | BIT_LINEOUT)) | headset,
                    isSynchronous);
            updateLocked(NAME_H2W, newHeadsetState, isSynchronous);
        }

    }

    @Override
+7 −2
Original line number Diff line number Diff line
@@ -423,6 +423,9 @@ public class InputManagerService extends IInputManager.Stub
    /** Switch code: Headphone/Microphone Jack.  When set, something is inserted. */
    public static final int SW_JACK_PHYSICAL_INSERT = 0x07;

    /** Switch code: Video Jack.  When set, something is inserted. */
    public static final int SW_VIDEOOUT_INSERT = 0x08;

    /** Switch code: Camera lens cover. When set the lens is covered. */
    public static final int SW_CAMERA_LENS_COVER = 0x09;

@@ -436,8 +439,10 @@ public class InputManagerService extends IInputManager.Stub
    public static final int SW_MICROPHONE_INSERT_BIT = 1 << SW_MICROPHONE_INSERT;
    public static final int SW_LINEOUT_INSERT_BIT = 1 << SW_LINEOUT_INSERT;
    public static final int SW_JACK_PHYSICAL_INSERT_BIT = 1 << SW_JACK_PHYSICAL_INSERT;
    public static final int SW_JACK_BITS =
            SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_JACK_PHYSICAL_INSERT_BIT | SW_LINEOUT_INSERT_BIT;
    public static final int SW_VIDEOOUT_INSERT_BIT = 1 << SW_VIDEOOUT_INSERT;
    public static final int SW_JACK_BITS = SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT
                                           | SW_JACK_PHYSICAL_INSERT_BIT | SW_LINEOUT_INSERT_BIT
                                           | SW_VIDEOOUT_INSERT_BIT;
    public static final int SW_CAMERA_LENS_COVER_BIT = 1 << SW_CAMERA_LENS_COVER;
    public static final int SW_MUTE_DEVICE_BIT = 1 << SW_MUTE_DEVICE;