summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java33
-rw-r--r--services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java5
-rw-r--r--services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java34
3 files changed, 37 insertions, 35 deletions
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java
index 44aafa8a33d8..e5f4282eefe0 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevice.java
@@ -888,13 +888,42 @@ abstract class HdmiCecLocalDevice {
}
/**
- * Send a key event to other device.
+ * Send a key event to other CEC device. The logical address of target device will be given by
+ * {@link #findKeyReceiverAddress}.
*
* @param keyCode key code defined in {@link android.view.KeyEvent}
* @param isPressed {@code true} for key down event
+ * @see #findKeyReceiverAddress()
*/
+ @ServiceThreadOnly
protected void sendKeyEvent(int keyCode, boolean isPressed) {
- Slog.w(TAG, "sendKeyEvent not implemented");
+ assertRunOnServiceThread();
+ if (!HdmiCecKeycode.isSupportedKeycode(keyCode)) {
+ Slog.w(TAG, "Unsupported key: " + keyCode);
+ return;
+ }
+ List<SendKeyAction> action = getActions(SendKeyAction.class);
+ int logicalAddress = findKeyReceiverAddress();
+ if (logicalAddress == Constants.ADDR_INVALID || logicalAddress == mAddress) {
+ // Don't send key event to invalid device or itself.
+ Slog.w(TAG, "Discard key event: " + keyCode + ", pressed:" + isPressed
+ + ", receiverAddr=" + logicalAddress);
+ } else if (!action.isEmpty()) {
+ action.get(0).processKeyEvent(keyCode, isPressed);
+ } else if (isPressed) {
+ addAndStartAction(new SendKeyAction(this, logicalAddress, keyCode));
+ }
+ }
+
+ /**
+ * Returns the logical address of the device which will receive key events via
+ * {@link #sendKeyEvent}.
+ *
+ * @see #sendKeyEvent(int, boolean)
+ */
+ protected int findKeyReceiverAddress() {
+ Slog.w(TAG, "findKeyReceiverAddress is not implemented");
+ return Constants.ADDR_INVALID;
}
void sendUserControlPressedAndReleased(int targetAddress, int cecKeycode) {
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java
index 69c012e3893d..d45b00bd904b 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDevicePlayback.java
@@ -355,6 +355,11 @@ final class HdmiCecLocalDevicePlayback extends HdmiCecLocalDevice {
}
@Override
+ protected int findKeyReceiverAddress() {
+ return Constants.ADDR_TV;
+ }
+
+ @Override
@ServiceThreadOnly
protected void sendStandby(int deviceId) {
assertRunOnServiceThread();
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java
index c85d97962a22..4526ab74387b 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java
@@ -432,40 +432,8 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
return mService.getPowerStatus();
}
- /**
- * Sends key to a target CEC device.
- *
- * @param keyCode key code to send. Defined in {@link android.view.KeyEvent}.
- * @param isPressed true if this is key press event
- */
@Override
- @ServiceThreadOnly
- protected void sendKeyEvent(int keyCode, boolean isPressed) {
- assertRunOnServiceThread();
- if (!HdmiCecKeycode.isSupportedKeycode(keyCode)) {
- Slog.w(TAG, "Unsupported key: " + keyCode);
- return;
- }
- List<SendKeyAction> action = getActions(SendKeyAction.class);
- int logicalAddress = findKeyReceiverAddress();
- if (logicalAddress == mAddress) {
- Slog.w(TAG, "Discard key event to itself :" + keyCode + " pressed:" + isPressed);
- return;
- }
- if (!action.isEmpty()) {
- action.get(0).processKeyEvent(keyCode, isPressed);
- } else {
- if (isPressed) {
- if (logicalAddress != Constants.ADDR_INVALID) {
- addAndStartAction(new SendKeyAction(this, logicalAddress, keyCode));
- return;
- }
- }
- Slog.w(TAG, "Discard key event: " + keyCode + " pressed:" + isPressed);
- }
- }
-
- private int findKeyReceiverAddress() {
+ protected int findKeyReceiverAddress() {
if (getActiveSource().isValid()) {
return getActiveSource().logicalAddress;
}