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

Commit 26e37349 authored by Praveen Bharathi's avatar Praveen Bharathi Committed by Iliyan Malchev
Browse files

frameworks/base: switch audio to hdmi when cable is plugged in



Change-Id: I01c4ee968bc0ffbb6ce75370935571cc1ff6f8c7
Signed-off-by: default avatarIliyan Malchev <malchev@google.com>
parent de04e524
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -1853,7 +1853,22 @@ public class Intent implements Parcelable, Cloneable {
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_USB_DGTL_HEADSET_PLUG =
            "android.intent.action.DOCK_HEADSET_PLUG";
            "android.intent.action.HDMI_AUDIO_PLUG";

    /**
     * Broadcast Action: A HMDI cable was plugged or unplugged
     *
     * <p>The intent will have the following extra values:
     * <ul>
     *   <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
     *   <li><em>name</em> - HDMI cable, human readable string </li>
     * </ul>
     * </ul>
     * @hide
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_HDMI_AUDIO_PLUG =
            "android.intent.action.HDMI_AUDIO_PLUG";

    /**
     * Broadcast Action: An outgoing call is about to be placed.
+3 −1
Original line number Diff line number Diff line
@@ -314,6 +314,7 @@ public class AudioService extends IAudioService.Stub {
        intentFilter.addAction(Intent.ACTION_DOCK_EVENT);
        intentFilter.addAction(Intent.ACTION_USB_ANLG_HEADSET_PLUG);
        intentFilter.addAction(Intent.ACTION_USB_DGTL_HEADSET_PLUG);
        intentFilter.addAction(Intent.ACTION_HDMI_AUDIO_PLUG);
        context.registerReceiver(mReceiver, intentFilter);

        // Register for media button intent broadcasts.
@@ -1949,7 +1950,8 @@ public class AudioService extends IAudioService.Stub {
                                                         AudioSystem.DEVICE_STATE_AVAILABLE, "");
                    mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET), "");
                }
            } else if (action.equals(Intent.ACTION_USB_DGTL_HEADSET_PLUG)) {
            } else if ( (action.equals(Intent.ACTION_USB_DGTL_HEADSET_PLUG)) ||
                        (action.equals(Intent.ACTION_HDMI_AUDIO_PLUG)) ) {
                int state = intent.getIntExtra("state", 0);
                Log.v(TAG, "Broadcast Receiver: Got ACTION_USB_DGTL_HEADSET_PLUG, state = "+state);
                boolean isConnected = mConnectedDevices.containsKey(AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET);
+21 −4
Original line number Diff line number Diff line
@@ -37,20 +37,25 @@ import java.io.FileNotFoundException;
class WiredAccessoryObserver extends UEventObserver {
    private static final String TAG = WiredAccessoryObserver.class.getSimpleName();
    private static final boolean LOG = true;
    private static final int MAX_AUDIO_PORTS = 2; /* h2w & USB Audio */
    private static final int MAX_AUDIO_PORTS = 3; /* h2w, USB Audio & hdmi */
    private static final String uEventInfo[][] = { {"DEVPATH=/devices/virtual/switch/h2w",
                                                    "/sys/class/switch/h2w/state",
                                                    "/sys/class/switch/h2w/name"},
                                                   {"DEVPATH=/devices/virtual/switch/usb_audio",
                                                    "/sys/class/switch/usb_audio/state",
                                                    "/sys/class/switch/usb_audio/name"} };
                                                    "/sys/class/switch/usb_audio/name"},
                                                   {"DEVPATH=/devices/virtual/switch/hdmi",
                                                    "/sys/class/switch/hdmi/state",
                                                    "/sys/class/switch/hdmi/name"} };

    private static final int BIT_HEADSET = (1 << 0);
    private static final int BIT_HEADSET_NO_MIC = (1 << 1);
    private static final int BIT_USB_HEADSET_ANLG = (1 << 2);
    private static final int BIT_USB_HEADSET_DGTL = (1 << 3);
    private static final int BIT_HDMI_AUDIO = (1 << 4);
    private static final int SUPPORTED_HEADSETS = (BIT_HEADSET|BIT_HEADSET_NO_MIC|
                                                   BIT_USB_HEADSET_ANLG|BIT_USB_HEADSET_DGTL);
                                                   BIT_USB_HEADSET_ANLG|BIT_USB_HEADSET_DGTL|
                                                   BIT_HDMI_AUDIO);
    private static final int HEADSETS_WITH_MIC = BIT_HEADSET;

    private int mHeadsetState;
@@ -93,6 +98,11 @@ class WiredAccessoryObserver extends UEventObserver {
                }
                else switchState = (mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC));
            }
            else if ((event.get("SWITCH_NAME")).equals("hdmi")) {
                switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC|
                                                 BIT_USB_HEADSET_DGTL|BIT_USB_HEADSET_ANLG)) |
                               (Integer.parseInt(event.get("SWITCH_STATE")) << 4));
            }
            else {
                switchState = ((mHeadsetState & (BIT_USB_HEADSET_ANLG|BIT_USB_HEADSET_DGTL)) |
                              (Integer.parseInt(event.get("SWITCH_STATE"))));
@@ -204,7 +214,8 @@ class WiredAccessoryObserver extends UEventObserver {
            if ((headsetState & headset) != 0) {
                state = 1;
            }
            if((headset == BIT_USB_HEADSET_ANLG) || (headset == BIT_USB_HEADSET_DGTL)) {
            if((headset == BIT_USB_HEADSET_ANLG) || (headset == BIT_USB_HEADSET_DGTL) ||
               (headset == BIT_HDMI_AUDIO)) {
                Intent intent;

                //  Pack up the values and broadcast them to everyone
@@ -220,6 +231,12 @@ class WiredAccessoryObserver extends UEventObserver {
                    intent.putExtra("state", state);
                    intent.putExtra("name", headsetName);
                    ActivityManagerNative.broadcastStickyIntent(intent, null);
                } else if (headset == BIT_HDMI_AUDIO) {
                    intent = new Intent(Intent.ACTION_HDMI_AUDIO_PLUG);
                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
                    intent.putExtra("state", state);
                    intent.putExtra("name", headsetName);
                    ActivityManagerNative.broadcastStickyIntent(intent, null);
                }

                if (LOG) Slog.v(TAG, "Intent.ACTION_USB_HEADSET_PLUG: state: "+state+" name: "+headsetName);