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

Commit 8bafd00e authored by Danny Baumann's avatar Danny Baumann Committed by Gerrit Code Review
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: I74b8091544fef518d142c4f5aea2eea48756f324
parent 3a9cf96d
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -330,7 +330,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);
@@ -353,6 +354,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;
@@ -405,7 +413,7 @@ final class WiredAccessoryManager implements WiredAccessoryCallbacks {
            try {
                String devPath = event.get("DEVPATH");
                String name = event.get("SWITCH_NAME");
                int state = Integer.parseInt(event.get("SWITCH_STATE"));
                int state = validateSwitchState(Integer.parseInt(event.get("SWITCH_STATE")));
                synchronized (mLock) {
                    updateStateLocked(devPath, name, state);
                }