Loading services/core/java/com/android/server/hdmi/HdmiCecKeycode.java +16 −32 Original line number Diff line number Diff line Loading @@ -155,7 +155,7 @@ final class HdmiCecKeycode { } /** * A mapping between andorid and cec keycode. * A mapping between Android and CEC keycode. * * <p>Normal implementation of this looks like * <pre> Loading @@ -174,43 +174,28 @@ final class HdmiCecKeycode { private static class KeycodeEntry { private final int mAndroidKeycode; private final int mCecKeycode; private final int mParam; private final boolean mIsRepeatable; private KeycodeEntry(int androidKeycode, int cecKeycode, int param, boolean isRepeatable) { private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable) { mAndroidKeycode = androidKeycode; mCecKeycode = cecKeycode; mParam = param; mIsRepeatable = isRepeatable; } private KeycodeEntry(int androidKeycode, int cecKeycode) { this(androidKeycode, cecKeycode, NO_PARAM, true); } private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable) { this(androidKeycode, cecKeycode, NO_PARAM, isRepeatable); this(androidKeycode, cecKeycode, true); } private byte[] toCecKeycodeIfMatched(int androidKeycode) { private int toCecKeycodeIfMatched(int androidKeycode) { if (mAndroidKeycode == androidKeycode) { if (mParam == NO_PARAM) { return new byte[] { (byte) (mCecKeycode & 0xFF) }; } else { return new byte[] { (byte) (mCecKeycode & 0xFF), (byte) (mParam & 0xFF) }; } return mCecKeycode; } else { return null; return UNSUPPORTED_KEYCODE; } } private int toAndroidKeycodeIfMatched(int cecKeycode, int param) { if (cecKeycode == mCecKeycode && mParam == param) { private int toAndroidKeycodeIfMatched(int cecKeycode) { if (cecKeycode == mCecKeycode) { return mAndroidKeycode; } else { return UNSUPPORTED_KEYCODE; Loading Loading @@ -365,29 +350,28 @@ final class HdmiCecKeycode { * Translate Android keycode to Hdmi Cec keycode. * * @param keycode Android keycode. For details, refer {@link KeyEvent} * @return array of byte which contains cec keycode and param if it has; * return null if failed to find matched cec keycode * @return single byte CEC keycode if matched. */ static byte[] androidKeyToCecKey(int keycode) { static int androidKeyToCecKey(int keycode) { for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { byte[] cecKeycode = KEYCODE_ENTRIES[i].toCecKeycodeIfMatched(keycode); if (cecKeycode != null) { int cecKeycode = KEYCODE_ENTRIES[i].toCecKeycodeIfMatched(keycode); if (cecKeycode != UNSUPPORTED_KEYCODE) { return cecKeycode; } } return null; return UNSUPPORTED_KEYCODE; } /** * Translate Hdmi CEC keycode to Android keycode. * * @param keycode Cec keycode. If has no param, put {@link #NO_PARAM} * @param keycode CEC keycode * @return cec keycode corresponding to the given android keycode. * If finds no matched keycode, return {@link #UNSUPPORTED_KEYCODE} */ static int cecKeyToAndroidKey(int keycode, int param) { static int cecKeyToAndroidKey(int keycode) { for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { int androidKey = KEYCODE_ENTRIES[i].toAndroidKeycodeIfMatched(keycode, param); int androidKey = KEYCODE_ENTRIES[i].toAndroidKeycodeIfMatched(keycode); if (androidKey != UNSUPPORTED_KEYCODE) { return androidKey; } Loading services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java +3 −2 Original line number Diff line number Diff line Loading @@ -405,8 +405,9 @@ abstract class HdmiCecLocalDevice { final long downTime = SystemClock.uptimeMillis(); final byte[] params = message.getParams(); final int keycode = HdmiCecKeycode.cecKeyToAndroidKey(params[0], params.length > 1 ? params[1] : HdmiCecKeycode.NO_PARAM); // Note that we don't support parameterized keycode now. // TODO: translate parameterized keycode as well. final int keycode = HdmiCecKeycode.cecKeyToAndroidKey(params[0]); int keyRepeatCount = 0; if (mLastKeycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) { if (keycode == mLastKeycode) { Loading services/core/java/com/android/server/hdmi/HdmiControlService.java +1 −2 Original line number Diff line number Diff line Loading @@ -320,7 +320,6 @@ public final class HdmiControlService extends SystemService { } } private void registerContentObserver() { ContentResolver resolver = getContext().getContentResolver(); String[] settings = new String[] { Loading services/core/java/com/android/server/hdmi/SendKeyAction.java +3 −12 Original line number Diff line number Diff line Loading @@ -109,12 +109,12 @@ final class SendKeyAction extends HdmiCecFeatureAction { } private void sendKeyDown(int keycode) { byte[] keycodeAndParam = getCecKeycodeAndParam(keycode); if (keycodeAndParam == null) { int cecKeycode = HdmiCecKeycode.androidKeyToCecKey(keycode); if (cecKeycode == HdmiCecKeycode.UNSUPPORTED_KEYCODE) { return; } sendCommand(HdmiCecMessageBuilder.buildUserControlPressed(getSourceAddress(), mTargetAddress, keycodeAndParam)); mTargetAddress, new byte[] { (byte) (cecKeycode & 0xFF) })); } private void sendKeyUp() { Loading @@ -141,13 +141,4 @@ final class SendKeyAction extends HdmiCecFeatureAction { sendKeyDown(mLastKeycode); addTimer(mState, IRT_MS); } // Converts the Android key code to corresponding CEC key code definition. Those CEC keys // with additional parameters should be mapped from individual Android key code. 'Select // Broadcast' with the parameter 'cable', for instance, shall have its counterpart such as // KeyEvent.KEYCODE_TV_BROADCAST_CABLE. // The return byte array contains both UI command (keycode) and optional parameter. private byte[] getCecKeycodeAndParam(int keycode) { return HdmiCecKeycode.androidKeyToCecKey(keycode); } } Loading
services/core/java/com/android/server/hdmi/HdmiCecKeycode.java +16 −32 Original line number Diff line number Diff line Loading @@ -155,7 +155,7 @@ final class HdmiCecKeycode { } /** * A mapping between andorid and cec keycode. * A mapping between Android and CEC keycode. * * <p>Normal implementation of this looks like * <pre> Loading @@ -174,43 +174,28 @@ final class HdmiCecKeycode { private static class KeycodeEntry { private final int mAndroidKeycode; private final int mCecKeycode; private final int mParam; private final boolean mIsRepeatable; private KeycodeEntry(int androidKeycode, int cecKeycode, int param, boolean isRepeatable) { private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable) { mAndroidKeycode = androidKeycode; mCecKeycode = cecKeycode; mParam = param; mIsRepeatable = isRepeatable; } private KeycodeEntry(int androidKeycode, int cecKeycode) { this(androidKeycode, cecKeycode, NO_PARAM, true); } private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable) { this(androidKeycode, cecKeycode, NO_PARAM, isRepeatable); this(androidKeycode, cecKeycode, true); } private byte[] toCecKeycodeIfMatched(int androidKeycode) { private int toCecKeycodeIfMatched(int androidKeycode) { if (mAndroidKeycode == androidKeycode) { if (mParam == NO_PARAM) { return new byte[] { (byte) (mCecKeycode & 0xFF) }; } else { return new byte[] { (byte) (mCecKeycode & 0xFF), (byte) (mParam & 0xFF) }; } return mCecKeycode; } else { return null; return UNSUPPORTED_KEYCODE; } } private int toAndroidKeycodeIfMatched(int cecKeycode, int param) { if (cecKeycode == mCecKeycode && mParam == param) { private int toAndroidKeycodeIfMatched(int cecKeycode) { if (cecKeycode == mCecKeycode) { return mAndroidKeycode; } else { return UNSUPPORTED_KEYCODE; Loading Loading @@ -365,29 +350,28 @@ final class HdmiCecKeycode { * Translate Android keycode to Hdmi Cec keycode. * * @param keycode Android keycode. For details, refer {@link KeyEvent} * @return array of byte which contains cec keycode and param if it has; * return null if failed to find matched cec keycode * @return single byte CEC keycode if matched. */ static byte[] androidKeyToCecKey(int keycode) { static int androidKeyToCecKey(int keycode) { for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { byte[] cecKeycode = KEYCODE_ENTRIES[i].toCecKeycodeIfMatched(keycode); if (cecKeycode != null) { int cecKeycode = KEYCODE_ENTRIES[i].toCecKeycodeIfMatched(keycode); if (cecKeycode != UNSUPPORTED_KEYCODE) { return cecKeycode; } } return null; return UNSUPPORTED_KEYCODE; } /** * Translate Hdmi CEC keycode to Android keycode. * * @param keycode Cec keycode. If has no param, put {@link #NO_PARAM} * @param keycode CEC keycode * @return cec keycode corresponding to the given android keycode. * If finds no matched keycode, return {@link #UNSUPPORTED_KEYCODE} */ static int cecKeyToAndroidKey(int keycode, int param) { static int cecKeyToAndroidKey(int keycode) { for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) { int androidKey = KEYCODE_ENTRIES[i].toAndroidKeycodeIfMatched(keycode, param); int androidKey = KEYCODE_ENTRIES[i].toAndroidKeycodeIfMatched(keycode); if (androidKey != UNSUPPORTED_KEYCODE) { return androidKey; } Loading
services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java +3 −2 Original line number Diff line number Diff line Loading @@ -405,8 +405,9 @@ abstract class HdmiCecLocalDevice { final long downTime = SystemClock.uptimeMillis(); final byte[] params = message.getParams(); final int keycode = HdmiCecKeycode.cecKeyToAndroidKey(params[0], params.length > 1 ? params[1] : HdmiCecKeycode.NO_PARAM); // Note that we don't support parameterized keycode now. // TODO: translate parameterized keycode as well. final int keycode = HdmiCecKeycode.cecKeyToAndroidKey(params[0]); int keyRepeatCount = 0; if (mLastKeycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) { if (keycode == mLastKeycode) { Loading
services/core/java/com/android/server/hdmi/HdmiControlService.java +1 −2 Original line number Diff line number Diff line Loading @@ -320,7 +320,6 @@ public final class HdmiControlService extends SystemService { } } private void registerContentObserver() { ContentResolver resolver = getContext().getContentResolver(); String[] settings = new String[] { Loading
services/core/java/com/android/server/hdmi/SendKeyAction.java +3 −12 Original line number Diff line number Diff line Loading @@ -109,12 +109,12 @@ final class SendKeyAction extends HdmiCecFeatureAction { } private void sendKeyDown(int keycode) { byte[] keycodeAndParam = getCecKeycodeAndParam(keycode); if (keycodeAndParam == null) { int cecKeycode = HdmiCecKeycode.androidKeyToCecKey(keycode); if (cecKeycode == HdmiCecKeycode.UNSUPPORTED_KEYCODE) { return; } sendCommand(HdmiCecMessageBuilder.buildUserControlPressed(getSourceAddress(), mTargetAddress, keycodeAndParam)); mTargetAddress, new byte[] { (byte) (cecKeycode & 0xFF) })); } private void sendKeyUp() { Loading @@ -141,13 +141,4 @@ final class SendKeyAction extends HdmiCecFeatureAction { sendKeyDown(mLastKeycode); addTimer(mState, IRT_MS); } // Converts the Android key code to corresponding CEC key code definition. Those CEC keys // with additional parameters should be mapped from individual Android key code. 'Select // Broadcast' with the parameter 'cable', for instance, shall have its counterpart such as // KeyEvent.KEYCODE_TV_BROADCAST_CABLE. // The return byte array contains both UI command (keycode) and optional parameter. private byte[] getCecKeycodeAndParam(int keycode) { return HdmiCecKeycode.androidKeyToCecKey(keycode); } }