* commit 'eb6724d530160e802c0209b2f0bcfafa540d294e': Support parameterized keycode in cec.
This commit is contained in:
@@ -18,6 +18,10 @@ package com.android.server.hdmi;
|
|||||||
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
import libcore.util.EmptyArray;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to translate android keycode to hdmi cec keycode and vice versa.
|
* Helper class to translate android keycode to hdmi cec keycode and vice versa.
|
||||||
*/
|
*/
|
||||||
@@ -173,29 +177,40 @@ final class HdmiCecKeycode {
|
|||||||
*/
|
*/
|
||||||
private static class KeycodeEntry {
|
private static class KeycodeEntry {
|
||||||
private final int mAndroidKeycode;
|
private final int mAndroidKeycode;
|
||||||
private final int mCecKeycode;
|
|
||||||
private final boolean mIsRepeatable;
|
private final boolean mIsRepeatable;
|
||||||
|
private final byte[] mCecKeycodeAndParams;
|
||||||
|
|
||||||
|
private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable,
|
||||||
|
byte[] cecParams) {
|
||||||
|
mAndroidKeycode = androidKeycode;
|
||||||
|
mIsRepeatable = isRepeatable;
|
||||||
|
mCecKeycodeAndParams = new byte[cecParams.length + 1];
|
||||||
|
System.arraycopy(cecParams, 0, mCecKeycodeAndParams, 1, cecParams.length);
|
||||||
|
mCecKeycodeAndParams[0] = (byte) (cecKeycode & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable) {
|
private KeycodeEntry(int androidKeycode, int cecKeycode, boolean isRepeatable) {
|
||||||
mAndroidKeycode = androidKeycode;
|
this(androidKeycode, cecKeycode, isRepeatable, EmptyArray.BYTE);
|
||||||
mCecKeycode = cecKeycode;
|
}
|
||||||
mIsRepeatable = isRepeatable;
|
|
||||||
|
private KeycodeEntry(int androidKeycode, int cecKeycode, byte[] cecParams) {
|
||||||
|
this(androidKeycode, cecKeycode, true, cecParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
private KeycodeEntry(int androidKeycode, int cecKeycode) {
|
private KeycodeEntry(int androidKeycode, int cecKeycode) {
|
||||||
this(androidKeycode, cecKeycode, true);
|
this(androidKeycode, cecKeycode, true, EmptyArray.BYTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int toCecKeycodeIfMatched(int androidKeycode) {
|
private byte[] toCecKeycodeAndParamIfMatched(int androidKeycode) {
|
||||||
if (mAndroidKeycode == androidKeycode) {
|
if (mAndroidKeycode == androidKeycode) {
|
||||||
return mCecKeycode;
|
return mCecKeycodeAndParams;
|
||||||
} else {
|
} else {
|
||||||
return UNSUPPORTED_KEYCODE;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int toAndroidKeycodeIfMatched(int cecKeycode) {
|
private int toAndroidKeycodeIfMatched(byte[] cecKeycodeAndParams) {
|
||||||
if (cecKeycode == mCecKeycode) {
|
if (Arrays.equals(mCecKeycodeAndParams, cecKeycodeAndParams)) {
|
||||||
return mAndroidKeycode;
|
return mAndroidKeycode;
|
||||||
} else {
|
} else {
|
||||||
return UNSUPPORTED_KEYCODE;
|
return UNSUPPORTED_KEYCODE;
|
||||||
@@ -347,31 +362,31 @@ final class HdmiCecKeycode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate Android keycode to Hdmi Cec keycode.
|
* Translate Android keycode to Hdmi Cec keycode and params.
|
||||||
*
|
*
|
||||||
* @param keycode Android keycode. For details, refer {@link KeyEvent}
|
* @param keycode Android keycode. For details, refer {@link KeyEvent}
|
||||||
* @return single byte CEC keycode if matched.
|
* @return byte array of CEC keycode and params if matched. Otherwise, return null.
|
||||||
*/
|
*/
|
||||||
static int androidKeyToCecKey(int keycode) {
|
static byte[] androidKeyToCecKey(int keycode) {
|
||||||
for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) {
|
for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) {
|
||||||
int cecKeycode = KEYCODE_ENTRIES[i].toCecKeycodeIfMatched(keycode);
|
byte[] cecKeycodeAndParams = KEYCODE_ENTRIES[i].toCecKeycodeAndParamIfMatched(keycode);
|
||||||
if (cecKeycode != UNSUPPORTED_KEYCODE) {
|
if (cecKeycodeAndParams != null) {
|
||||||
return cecKeycode;
|
return cecKeycodeAndParams;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return UNSUPPORTED_KEYCODE;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate Hdmi CEC keycode to Android keycode.
|
* Translate Hdmi CEC keycode with params to Android keycode.
|
||||||
*
|
*
|
||||||
* @param keycode CEC keycode
|
* @param cecKeycodeAndParams CEC keycode and params
|
||||||
* @return cec keycode corresponding to the given android keycode.
|
* @return cec keycode corresponding to the given android keycode.
|
||||||
* If finds no matched keycode, return {@link #UNSUPPORTED_KEYCODE}
|
* If finds no matched keycode, return {@link #UNSUPPORTED_KEYCODE}
|
||||||
*/
|
*/
|
||||||
static int cecKeyToAndroidKey(int keycode) {
|
static int cecKeycodeAndParamsToAndroidKey(byte[] cecKeycodeAndParams) {
|
||||||
for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) {
|
for (int i = 0; i < KEYCODE_ENTRIES.length; ++i) {
|
||||||
int androidKey = KEYCODE_ENTRIES[i].toAndroidKeycodeIfMatched(keycode);
|
int androidKey = KEYCODE_ENTRIES[i].toAndroidKeycodeIfMatched(cecKeycodeAndParams);
|
||||||
if (androidKey != UNSUPPORTED_KEYCODE) {
|
if (androidKey != UNSUPPORTED_KEYCODE) {
|
||||||
return androidKey;
|
return androidKey;
|
||||||
}
|
}
|
||||||
@@ -399,7 +414,6 @@ final class HdmiCecKeycode {
|
|||||||
* Returns {@code true} if given Android keycode is supported, otherwise {@code false}.
|
* Returns {@code true} if given Android keycode is supported, otherwise {@code false}.
|
||||||
*/
|
*/
|
||||||
static boolean isSupportedKeycode(int androidKeycode) {
|
static boolean isSupportedKeycode(int androidKeycode) {
|
||||||
return HdmiCecKeycode.androidKeyToCecKey(androidKeycode)
|
return HdmiCecKeycode.androidKeyToCecKey(androidKeycode) != null;
|
||||||
!= HdmiCecKeycode.UNSUPPORTED_KEYCODE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -426,9 +426,7 @@ abstract class HdmiCecLocalDevice {
|
|||||||
|
|
||||||
final long downTime = SystemClock.uptimeMillis();
|
final long downTime = SystemClock.uptimeMillis();
|
||||||
final byte[] params = message.getParams();
|
final byte[] params = message.getParams();
|
||||||
// Note that we don't support parameterized keycode now.
|
final int keycode = HdmiCecKeycode.cecKeycodeAndParamsToAndroidKey(params);
|
||||||
// TODO: translate parameterized keycode as well.
|
|
||||||
final int keycode = HdmiCecKeycode.cecKeyToAndroidKey(params[0]);
|
|
||||||
int keyRepeatCount = 0;
|
int keyRepeatCount = 0;
|
||||||
if (mLastKeycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) {
|
if (mLastKeycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) {
|
||||||
if (keycode == mLastKeycode) {
|
if (keycode == mLastKeycode) {
|
||||||
|
|||||||
@@ -109,12 +109,12 @@ final class SendKeyAction extends HdmiCecFeatureAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendKeyDown(int keycode) {
|
private void sendKeyDown(int keycode) {
|
||||||
int cecKeycode = HdmiCecKeycode.androidKeyToCecKey(keycode);
|
byte[] cecKeycodeAndParams = HdmiCecKeycode.androidKeyToCecKey(keycode);
|
||||||
if (cecKeycode == HdmiCecKeycode.UNSUPPORTED_KEYCODE) {
|
if (cecKeycodeAndParams == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendCommand(HdmiCecMessageBuilder.buildUserControlPressed(getSourceAddress(),
|
sendCommand(HdmiCecMessageBuilder.buildUserControlPressed(getSourceAddress(),
|
||||||
mTargetAddress, new byte[] { (byte) (cecKeycode & 0xFF) }));
|
mTargetAddress, cecKeycodeAndParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendKeyUp() {
|
private void sendKeyUp() {
|
||||||
|
|||||||
Reference in New Issue
Block a user