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

Commit 7609bc32 authored by Donghyun Cho's avatar Donghyun Cho
Browse files

Enable sendKeyEvent() for all types of devices

Previously there was only sendKeyEvent() implementation for TV and the
method was no-op for other devices. This change moves the event handling
logic into HdmiCecLocalDevice so as to make this method work on the
playback device.

Bug: 33285033
Test: Sent key event from playback device, and it worked.
Change-Id: I937502ab87ce823630b0f9a933355d5a4cc5e96a
parent 11ab16f6
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -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) {
+5 −0
Original line number Diff line number Diff line
@@ -354,6 +354,11 @@ final class HdmiCecLocalDevicePlayback extends HdmiCecLocalDevice {
        }
    }

    @Override
    protected int findKeyReceiverAddress() {
        return Constants.ADDR_TV;
    }

    @Override
    @ServiceThreadOnly
    protected void sendStandby(int deviceId) {
+1 −33
Original line number Diff line number Diff line
@@ -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;
        }