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

Commit 6ffb0381 authored by Jinsuk Kim's avatar Jinsuk Kim
Browse files

Plumbing for HdmiTvClient and HdmiControlService

Added a few more methods in HdmiTvClient to use the API provided
by HdmiControlService

Change-Id: Ib506699b9661b99cefc837b96ac64347a4e9420c
parent fc44e4e0
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
package android.hardware.hdmi;

import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.hardware.hdmi.HdmiControlManager.VendorCommandListener;
import android.hardware.hdmi.IHdmiVendorCommandListener;
@@ -24,6 +25,21 @@ public abstract class HdmiClient {
        mService = service;
    }

    /**
     * Returns the active source information.
     *
     * @return {@link HdmiCecDeviceInfo} object that describes the active source
     *         or active routing path
     */
    public HdmiCecDeviceInfo getActiveSource() {
        try {
            return mService.getActiveSource();
        } catch (RemoteException e) {
            Log.e(TAG, "getActiveSource threw exception ", e);
        }
        return null;
    }

    /**
     * Send a key event to other logical device.
     *
@@ -60,7 +76,10 @@ public abstract class HdmiClient {
     *
     * @param listener listener object
     */
    public void addVendorCommandListener(VendorCommandListener listener) {
    public void addVendorCommandListener(@NonNull VendorCommandListener listener) {
        if (listener == null) {
            throw new IllegalArgumentException("listener cannot be null");
        }
        try {
            mService.addVendorCommandListener(getListenerWrapper(listener), getDeviceType());
        } catch (RemoteException e) {
+27 −10
Original line number Diff line number Diff line
@@ -245,7 +245,30 @@ public final class HdmiControlManager {
    }

    /**
     * Gets an object that represents a HDMI-CEC logical device of type playback on the system.
     * Gets an object that represents an HDMI-CEC logical device of a specified type.
     *
     * @param type CEC device type
     * @return {@link HdmiClient} instance. {@code null} on failure.
     * @see {@link HdmiCecDeviceInfo#DEVICE_PLAYBACK}
     * @see {@link HdmiCecDeviceInfo#DEVICE_TV}
     */
    @Nullable
    public HdmiClient getClient(int type) {
        if (mService == null) {
            return null;
        }
        switch (type) {
            case HdmiCecDeviceInfo.DEVICE_TV:
                return mHasTvDevice ? new HdmiTvClient(mService) : null;
            case HdmiCecDeviceInfo.DEVICE_PLAYBACK:
                return mHasPlaybackDevice ? new HdmiPlaybackClient(mService) : null;
            default:
                return null;
        }
    }

    /**
     * Gets an object that represents an HDMI-CEC logical device of type playback on the system.
     *
     * <p>Used to send HDMI control messages to other devices like TV or audio amplifier through
     * HDMI bus. It is also possible to communicate with other logical devices hosted in the same
@@ -255,14 +278,11 @@ public final class HdmiControlManager {
     */
    @Nullable
    public HdmiPlaybackClient getPlaybackClient() {
        if (mService == null || !mHasPlaybackDevice) {
            return null;
        }
        return new HdmiPlaybackClient(mService);
        return (HdmiPlaybackClient) getClient(HdmiCecDeviceInfo.DEVICE_PLAYBACK);
    }

    /**
     * Gets an object that represents a HDMI-CEC logical device of type TV on the system.
     * Gets an object that represents an HDMI-CEC logical device of type TV on the system.
     *
     * <p>Used to send HDMI control messages to other devices and manage them through
     * HDMI bus. It is also possible to communicate with other logical devices hosted in the same
@@ -272,10 +292,7 @@ public final class HdmiControlManager {
     */
    @Nullable
    public HdmiTvClient getTvClient() {
        if (mService == null || !mHasTvDevice) {
                return null;
        }
        return new HdmiTvClient(mService);
        return (HdmiTvClient) getClient(HdmiCecDeviceInfo.DEVICE_TV);
    }

    /**
+21 −4
Original line number Diff line number Diff line
@@ -114,15 +114,14 @@ public final class HdmiTvClient extends HdmiClient {
    /**
     * Select a CEC logical device to be a new active source.
     *
     * @param logicalAddress
     * @param callback
     * @param logicalAddress logical address of the device to select
     * @param callback callback to get the result with
     * @throws {@link IllegalArgumentException} if the {@code callback} is null
     */
    public void deviceSelect(int logicalAddress, @NonNull SelectCallback callback) {
        if (callback == null) {
            throw new IllegalArgumentException("callback must not be null.");
        }

        // TODO: Replace SelectCallback with PartialResult.
        try {
            mService.deviceSelect(logicalAddress, getCallbackWrapper(callback));
        } catch (RemoteException e) {
@@ -130,6 +129,24 @@ public final class HdmiTvClient extends HdmiClient {
        }
    }

    /**
     * Select a HDMI port to be a new route path.
     *
     * @param portId HDMI port to select
     * @param callback callback to get the result with
     * @throws {@link IllegalArgumentException} if the {@code callback} is null
     */
    public void portSelect(int portId, @NonNull SelectCallback callback) {
        if (callback == null) {
            throw new IllegalArgumentException("Callback must not be null");
        }
        try {
            mService.portSelect(portId, getCallbackWrapper(callback));
        } catch (RemoteException e) {
            Log.e(TAG, "failed to select port: ", e);
        }
    }

    /**
     * Set system audio volume
     *