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

Commit 0b5b94ce authored by Emerson Pinter's avatar Emerson Pinter Committed by Gerrit Code Review
Browse files

Frameworks-base: Fix dock audio when the name it's not "dock"

Adds support for more names in dock switch. This is needed on
devices where the name that came from the kernel it's not "dock".
Without this, the dock is detected as a headset on such devices,
and audio it's not routed correctly.

Change-Id: I26d548e4a8c269419ac012ff85ff61d228dc4127
parent cdbdb8eb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -941,4 +941,9 @@
         applied. -->
    <bool name="config_hasRemovableLid">false</bool>

    <!-- Possible names from /devices/virtual/switch/dock for a dock device.
         Some kernels use names like CAR and DESK. -->
    <string-array translatable="false" name="config_accessoryDockNames">
        <item>"dock"</item>
    </string-array>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -3915,4 +3915,6 @@
  <java-symbol type="string" name="com.amazon.mp3.playstatechanged_album" />
  <java-symbol type="string" name="com.amazon.mp3.playstatechanged_id" />

  <!-- WiredAccessoryObserver -->
  <java-symbol type="array" name="config_accessoryDockNames" />
</resources>
+4 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
@@ -34,6 +35,7 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
@@ -57,6 +59,7 @@ class WiredAccessoryObserver extends UEventObserver {
        private final int mState1Bits;
        private final int mState2Bits;
        private int switchState;
        private String mDockNames[]=Resources.getSystem().getStringArray(com.android.internal.R.array.config_accessoryDockNames);

        public UEventInfo(String devName, int state1Bits, int state2Bits) {
            mDevName = devName;
@@ -86,7 +89,7 @@ class WiredAccessoryObserver extends UEventObserver {
            switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC|BIT_HDMI_AUDIO)) |
                           ((state == 1) ? BIT_USB_HEADSET_ANLG :
                                         ((state == 2) ? BIT_USB_HEADSET_DGTL : 0)));
        } else if (name.equals("dock")) {
        } else if (Arrays.asList(mDockNames).contains(name)) {
             switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC|BIT_HDMI_AUDIO)) |
                           ((state == 2 || state == 1) ? BIT_USB_HEADSET_ANLG : 0));
            // This sets the switchsate to 4 (for USB HEADSET - BIT_USB_HEADSET_ANLG)