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

Commit 72020df9 authored by Seth Shelnutt's avatar Seth Shelnutt Committed by Gerrit Code Review
Browse files

Services.jar: Reworked computeNewHeadsetState function to set state in a

manor used in ics. This allows states such as 129 and 130, which are
used for 35MM_HEADSET to be correctly registered as a new state.

Change-Id: I3bd1ec17d0cd184593edf330f482f09396785e76
parent defbb7ad
Loading
Loading
Loading
Loading
+37 −8
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ class WiredAccessoryObserver extends UEventObserver {
        private final String mDevName;
        private final int mState1Bits;
        private final int mState2Bits;
        private int switchState;

        public UEventInfo(String devName, int state1Bits, int state2Bits) {
            mDevName = devName;
@@ -78,12 +79,40 @@ class WiredAccessoryObserver extends UEventObserver {
            return ((null != f) && f.exists());
        }

        public int computeNewHeadsetState(int headsetState, int switchState) {
            int preserveMask = ~(mState1Bits | mState2Bits);
            int setBits = ((switchState == 1) ? mState1Bits :
                          ((switchState == 2) ? mState2Bits : 0));
        public int computeNewHeadsetState(String name, int state) {

            return ((headsetState & preserveMask) | setBits);
        if (LOG) Slog.v(TAG, "updateState name: " + name + " state " + state);
        if (name.equals("usb_audio")) {
            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")) {
             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)
            // Looking at the other types, maybe the state that emitted should be a 1 and at
            //       /devices/virtual/switch/usb_audio
            //
            // However the we need to deal with changes at
            //       /devices/virtual/switch/dock
            // for the state of 2 - means that we have a USB ANLG headset Car Dock
            // for the state of 1 - means that we have a USB ANLG headset Desk Dock
        } else if (name.equals("hdmi")) {
            switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC|
                                             BIT_USB_HEADSET_DGTL|BIT_USB_HEADSET_ANLG)) |
                           ((state == 1) ? BIT_HDMI_AUDIO : 0));
        } else if (name.equals("Headset")) {
            switchState = ((mHeadsetState & (BIT_HDMI_AUDIO|BIT_USB_HEADSET_ANLG|
                                             BIT_USB_HEADSET_DGTL)) |
                                             (state & (BIT_HEADSET|BIT_HEADSET_NO_MIC)));
        } else {
            switchState = ((mHeadsetState & (BIT_HDMI_AUDIO|BIT_USB_HEADSET_ANLG|
                                             BIT_USB_HEADSET_DGTL)) |
                            ((state == 1) ? BIT_HEADSET :
                                          ((state == 2) ? BIT_HEADSET_NO_MIC : 0)));
        }
        if (LOG) Slog.v(TAG, "updateState switchState: " + switchState);
        return switchState;
       }
    }

@@ -140,7 +169,7 @@ class WiredAccessoryObserver extends UEventObserver {

    private static List<UEventInfo> uEventInfo = makeObservedUEventList();

    private int mHeadsetState;
    private static int mHeadsetState;
    private int mPrevHeadsetState;
    private String mHeadsetName;
    private boolean dockAudioEnabled = false;
@@ -226,7 +255,7 @@ class WiredAccessoryObserver extends UEventObserver {
        for (int i = 0; i < uEventInfo.size(); ++i) {
            UEventInfo uei = uEventInfo.get(i);
            if (devPath.equals(uei.getDevPath())) {
                update(name, uei.computeNewHeadsetState(mHeadsetState, state));
                update(name, uei.computeNewHeadsetState(name, state));
                return;
            }
        }