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

Commit c068bb5a authored by Jinsuk Kim's avatar Jinsuk Kim
Browse files

Support HdmiControlService.sendKeyEvent for both TV/playback device

Added another parameter deviceType for HdmiControlService to
run the specified local device for sendKeyEvent.

Bug: 15844076
Change-Id: I598ef320ae94bba0ace38701ae0ca12fd0625559
parent 2db72ad4
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -24,6 +24,29 @@ public abstract class HdmiClient {
        mService = service;
    }

    /**
     * Send a key event to other logical device.
     *
     * @param keyCode key code to send. Defined in {@link android.view.KeyEvent}.
     * @param isPressed true if this is key press event
     */
    public void sendKeyEvent(int keyCode, boolean isPressed) {
        try {
            mService.sendKeyEvent(getDeviceType(), keyCode, isPressed);
        } catch (RemoteException e) {
            Log.e(TAG, "queryDisplayStatus threw exception ", e);
        }
    }

    /**
     * Send vendor-specific command.
     *
     * @param targetAddress address of the target device
     * @param params vendor-specific parameter. For <Vendor Command With ID> do not
     *               include the first 3 bytes (vendor ID).
     * @param hasVendorId {@code true} if the command type will be <Vendor Command With ID>.
     *                    {@code false} if the command will be <Vendor Command>
     */
    public void sendVendorCommand(int targetAddress, byte[] params, boolean hasVendorId) {
        try {
            mService.sendVendorCommand(getDeviceType(), targetAddress, params, hasVendorId);
@@ -32,6 +55,11 @@ public abstract class HdmiClient {
        }
    }

    /**
     * Add a listener used to receive incoming vendor-specific command.
     *
     * @param listener listener object
     */
    public void addVendorCommandListener(VendorCommandListener listener) {
        try {
            mService.addVendorCommandListener(getListenerWrapper(listener), getDeviceType());
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ interface IHdmiControlService {
    void addDeviceEventListener(IHdmiDeviceEventListener listener);
    void deviceSelect(int logicalAddress, IHdmiControlCallback callback);
    void portSelect(int portId, IHdmiControlCallback callback);
    void sendKeyEvent(int keyCode, boolean isPressed);
    void sendKeyEvent(int deviceType, int keyCode, boolean isPressed);
    List<HdmiPortInfo> getPortInfo();
    boolean canChangeSystemAudioMode();
    boolean getSystemAudioMode();
+12 −2
Original line number Diff line number Diff line
@@ -581,7 +581,7 @@ abstract class HdmiCecLocalDevice {
     * Called when the system started transition to standby mode.
     *
     * @param initiatedByCec true if this power sequence is initiated
     *         by the reception the CEC messages like <StandBy>
     *         by the reception the CEC messages like &lt;StandBy&gt;
     */
    protected void onTransitionToStandby(boolean initiatedByCec) {
        // If there are no outstanding actions, we'll go to STANDBY state.
@@ -592,7 +592,17 @@ abstract class HdmiCecLocalDevice {
     * Called when the system goes to standby mode.
     *
     * @param initiatedByCec true if this power sequence is initiated
     *         by the reception the CEC messages like <StandBy>
     *         by the reception the CEC messages like &lt;StandBy&gt;
     */
    protected void onStandBy(boolean initiatedByCec) {}

    /**
     * Send a key event to other device.
     *
     * @param keyCode key code defined in {@link android.os.KeyEvent}
     * @param isPressed {@code true} for key down event
     */
    protected void sendKeyEvent(int keyCode, boolean isPressed) {
        Slog.w(TAG, "sendKeyEvent not implemented");
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -226,8 +226,9 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
     * @param keyCode key code to send. Defined in {@link android.view.KeyEvent}.
     * @param isPressed true if this is key press event
     */
    @Override
    @ServiceThreadOnly
    void sendKeyEvent(int keyCode, boolean isPressed) {
    protected void sendKeyEvent(int keyCode, boolean isPressed) {
        assertRunOnServiceThread();
        List<SendKeyAction> action = getActions(SendKeyAction.class);
        if (!action.isEmpty()) {
+5 −7
Original line number Diff line number Diff line
@@ -691,19 +691,17 @@ public final class HdmiControlService extends SystemService {
        }

        @Override
        public void sendKeyEvent(final int keyCode, final boolean isPressed) {
        public void sendKeyEvent(final int deviceType, final int keyCode, final boolean isPressed) {
            enforceAccessPermission();
            runOnServiceThread(new Runnable() {
                @Override
                public void run() {
                    // TODO: sendKeyEvent is for TV device only for now. Allow other
                    //       local devices of different types to use this as well.
                    HdmiCecLocalDeviceTv tv = tv();
                    if (tv == null) {
                        Slog.w(TAG, "Local tv device not available");
                    HdmiCecLocalDevice localDevice = mCecController.getLocalDevice(deviceType);
                    if (localDevice == null) {
                        Slog.w(TAG, "Local device not available");
                        return;
                    }
                    tv.sendKeyEvent(keyCode, isPressed);
                    localDevice.sendKeyEvent(keyCode, isPressed);
                }
            });
        }