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

Commit 685678cd authored by Danny Baumann's avatar Danny Baumann Committed by Ricardo Cerqueira
Browse files

Fix HTC headset handling.

HTC's headset driver adds additional bits to the switch state, which
we're unable to deal with. Fix that by masking out those bits and
keeping only the valid ones.

Change-Id: I29f0de9520ebb56d61acbc9a6dfcfc73e1f297d8
parent ec60591e
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -326,7 +326,8 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
                        FileReader file = new FileReader(uei.getSwitchStatePath());
                        int len = file.read(buffer, 0, 1024);
                        file.close();
                        curState = Integer.valueOf((new String(buffer, 0, len)).trim());
                        curState = validateSwitchState(
                                Integer.valueOf((new String(buffer, 0, len)).trim()));

                        if (curState > 0) {
                            updateStateLocked(uei.getDevPath(), uei.getDevName(), curState);
@@ -351,6 +352,13 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
            }
        }

        private int validateSwitchState(int state) {
            // Some drivers, namely HTC headset ones, add additional bits to
            // the switch state. As we only are able to deal with the states
            // 0, 1 and 2, mask out all the other bits
            return state & 0x3;
        }

        private List<UEventInfo> makeObservedUEventList() {
            List<UEventInfo> retVal = new ArrayList<UEventInfo>();
            UEventInfo uei;
@@ -408,7 +416,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
        public void onUEvent(UEventObserver.UEvent event) {
            if (LOG) Slog.v(TAG, "Headset UEVENT: " + event.toString());

            int state = Integer.parseInt(event.get("SWITCH_STATE"));
            int state = validateSwitchState(Integer.parseInt(event.get("SWITCH_STATE")));
            try {
                String devPath = event.get("DEVPATH");
                String name = event.get("SWITCH_NAME");