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

Unverified Commit 7e8b4865 authored by StevenHarperUK's avatar StevenHarperUK Committed by Michael Bestas
Browse files

Add Dock USB Audio Support for Samsung Car / Desk Docks

Ported from CM10, original patch: http://review.cyanogenmod.com/20586

Also includes patches:
DockAudio: Always route audio back to normal on undock.
http://review.cyanogenmod.org/24830

Bugfix: Dock events can have state greater than 1
http://review.cyanogenmod.org/24995

WiredAccessoryManager: remove warning about Samsung dock support
http://review.cyanogenmod.org/#/c/127558/

------------------------------------------------------

Samsung docks have a non-sensing USB adio port.
Samsung get around this by having a separate Setting to route the Audio
The Changes made will only add the extra Observer if the Kernel supports the endpoint

  /sys/class/switch/dock/state

Change-Id: I8e8f5001d5c651b07bb6af496bbf806732be21fa

audio: Add overlay to fix analog docks.

Of particular interest to devices using libhardware_legacy and
affected by commit 5a484b753cc72d6a50c1dd3bbf68b3403c741a3a: http://goo.gl/rVR1Z
which restricted the routing of AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET
to docks using FORCE_ANALOG_DOCK cases. The EXTRA_DOCK_STATE_CAR case is
returning FORCE_BT_CAR_DOCK, preventing the dock audio from routing properly.

Add an overlay option for overriding to FORCE_ANALOG_DOCK.

Change-Id: Ib7d70c242aa6f537ea5d65098ceb2c591662d8bb
parent e8d57210
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -75,4 +75,8 @@
    <java-symbol type="string" name="global_action_current_user" />
    <java-symbol type="dimen" name="global_actions_avatar_size" />

    <!-- Support Samsung docks -->
    <java-symbol type="bool" name="config_forceAnalogCarDock" />
    <java-symbol type="bool" name="config_forceAnalogDeskDock" />

</resources>
+8 −0
Original line number Diff line number Diff line
@@ -719,6 +719,10 @@
         we rely on gravity to determine the effective orientation. -->
    <bool name="config_deskDockEnablesAccelerometer">true</bool>

    <!-- Control whether a desk dock event should override the default bluetooth
         audio routing, FORCE_BT_DESK_DOCK, with an analog dock, FORCE_ANALOG_DOCK. -->
    <bool name="config_forceAnalogDeskDock">false</bool>

    <!-- Car dock behavior -->

    <!-- The number of degrees to rotate the display when the device is in a car dock.
@@ -744,6 +748,10 @@
          case, this can be disabled (set to false). -->
    <bool name="config_enableCarDockHomeLaunch">true</bool>

    <!-- Control whether a car dock event should override the default bluetooth
         audio routing, FORCE_BT_CAR_DOCK, with an analog dock, FORCE_ANALOG_DOCK. -->
    <bool name="config_forceAnalogCarDock">false</bool>

    <!-- HDMI behavior -->

    <!-- The number of degrees to rotate the display when the device has HDMI connected
+12 −2
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {

    private static final String NAME_H2W = "h2w";
    private static final String NAME_USB_AUDIO = "usb_audio";
    private static final String NAME_SAMSUNG_USB_AUDIO = "dock";
    private static final String NAME_HDMI_AUDIO = "hdmi_audio";
    private static final String NAME_HDMI = "hdmi";

@@ -345,8 +346,10 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
            }

            // At any given time accessories could be inserted
            // one on the board, one on the dock and one on HDMI:
            // observe three UEVENTs
            // one on the board, one on the dock, one on the
            // samsung dock and one on HDMI:
            // observe all UEVENTs that have valid switch supported
            // by the Kernel
            for (int i = 0; i < mUEventInfo.size(); ++i) {
                UEventInfo uei = mUEventInfo.get(i);
                startObserving("DEVPATH="+uei.getDevPath());
@@ -375,6 +378,13 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
                Slog.w(TAG, "This kernel does not have usb audio support");
            }

            // Monitor Samsung USB audio
            uei = new UEventInfo(NAME_SAMSUNG_USB_AUDIO, BIT_USB_HEADSET_DGTL,
                                 BIT_USB_HEADSET_ANLG, 0);
            if (uei.checkSwitchExists()) {
                retVal.add(uei);
            }

            // Monitor HDMI
            //
            // If the kernel has support for the "hdmi_audio" switch, use that.  It will be
+12 −2
Original line number Diff line number Diff line
@@ -574,6 +574,9 @@ public class AudioService extends IAudioService.Stub {

    private boolean mDockAudioMediaEnabled = true;

    private boolean mForceAnalogDeskDock;
    private boolean mForceAnalogCarDock;

    private int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;

    // Used when safe volume warning message display is requested by setStreamVolume(). In this
@@ -708,6 +711,11 @@ public class AudioService extends IAudioService.Stub {
        mLinkNotificationWithVolume = Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.VOLUME_LINK_NOTIFICATION, 1) == 1;

        mForceAnalogDeskDock = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_forceAnalogDeskDock);
        mForceAnalogCarDock = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_forceAnalogCarDock);

        // must be called before readPersistedSettings() which needs a valid mStreamVolumeAlias[]
        // array initialized by updateStreamVolumeAlias()
        updateStreamVolumeAlias(false /*updateVolumes*/, TAG);
@@ -5514,10 +5522,12 @@ public class AudioService extends IAudioService.Stub {
                int config;
                switch (dockState) {
                    case Intent.EXTRA_DOCK_STATE_DESK:
                        config = AudioSystem.FORCE_BT_DESK_DOCK;
                        config = mForceAnalogDeskDock ? AudioSystem.FORCE_ANALOG_DOCK :
                                                        AudioSystem.FORCE_BT_DESK_DOCK;
                        break;
                    case Intent.EXTRA_DOCK_STATE_CAR:
                        config = AudioSystem.FORCE_BT_CAR_DOCK;
                        config = mForceAnalogCarDock ? AudioSystem.FORCE_ANALOG_DOCK :
                                                       AudioSystem.FORCE_BT_CAR_DOCK;
                        break;
                    case Intent.EXTRA_DOCK_STATE_LE_DESK:
                        config = AudioSystem.FORCE_ANALOG_DOCK;