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

Commit 4e90fcd1 authored by Jinsuk Kim's avatar Jinsuk Kim
Browse files

Maintain display power status for playback device

With this CL, the power status of TV/display is keep tracked of
by hdmi cec server part, specfically HdmiCecDevicePlayback.
Turned the HdmiCecDevice to abstract class from which classes of
concrete device type(HdmiCecDevicePlayback, HdmiCecDeviceTV) are
inherited. The display power status code is put in HdmiCecDevicePlayback
only. HdmiCecDeviceTv will have its own logic that manages power status of
devices connected to it. For now it only has a bare minimum code.
Will be worked on in follow up CLs.

Other changes:

    - Replaced sendGiveDevicePowerStatus() with isTvOn() so that the status
      can be queried by clients.

    - Defensively check the availability of HdmiCecService so that
      HdmiCecManager.getClient() returns null in case the service couldn't
      be initialized. This ensures clients of the service gets the nulled-out
      HdmiCecClient when called in the state/configuration where the service
      is not available, thus proceed accordingly.

Change-Id: Idaf69e73cfbd639c0b40b1bd4b6146f011246180
parent 40a00a34
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -160,6 +160,12 @@ public final class HdmiCec {
    public static final int MESSAGE_SET_EXTERNAL_TIMER = 0xA2;
    public static final int MESSAGE_ABORT = 0xFF;

    public static final int POWER_STATUS_UNKNOWN = -1;
    public static final int POWER_STATUS_ON = 0;
    public static final int POWER_STATUS_STANDBY = 1;
    public static final int POWER_TRANSIENT_TO_ON = 2;
    public static final int POWER_TRANSIENT_TO_STANDBY = 3;

    private static final int[] ADDRESS_TO_TYPE = {
        DEVICE_TV,  // ADDR_TV
        DEVICE_RECORDER,  // ADDR_RECORDER_1
+10 −6
Original line number Diff line number Diff line
@@ -110,16 +110,20 @@ public final class HdmiCecClient {
    }

    /**
     * Send <GiveDevicePowerStatus> message.
     * Returns true if the TV or attached display is powered on.
     * <p>
     * The result of this method is only meaningful on playback devices (where the device
     * type is {@link HdmiCec#DEVICE_PLAYBACK}).
     * </p>
     *
     * @param address logical address of the device to send the message to, such as
     *        {@link HdmiCec#ADDR_TV}.
     * @return true if TV is on; otherwise false.
     */
    public void sendGiveDevicePowerStatus(int address) {
    public boolean isTvOn() {
        try {
            mService.sendGiveDevicePowerStatus(mBinder, address);
            return mService.isTvOn(mBinder);
        } catch (RemoteException e) {
            Log.e(TAG, "sendGiveDevicePowerStatus threw exception ", e);
            Log.e(TAG, "isTvOn threw exception ", e);
        }
        return false;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ public final class HdmiCecManager {
     * @return {@link HdmiCecClient} instance. {@code null} on failure.
     */
    public HdmiCecClient getClient(int type, HdmiCecClient.Listener listener) {
        if (mService == null) {
            return null;
        }
        try {
            IBinder b = mService.allocateLogicalDevice(type, getListenerWrapper(listener));
            return HdmiCecClient.create(mService, b);
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ interface IHdmiCecService {
    void sendInactiveSource(IBinder b);
    void sendImageViewOn(IBinder b);
    void sendTextViewOn(IBinder b);
    void sendGiveDevicePowerStatus(IBinder b, int address);
    boolean isTvOn(IBinder b);
    void sendMessage(IBinder b, in HdmiCecMessage message);
}
+45 −4
Original line number Diff line number Diff line
@@ -27,8 +27,12 @@ import java.util.ArrayList;
import java.util.List;

/**
 * CecDevice class represents a CEC logical device characterized
 * by its device type. A physical device can contain the functions of
 * HdmiCecDevice class represents a CEC logical device characterized
 * by its device type. It is a superclass of those serving concrete device type.
 * Currently we're interested in playback(one of sources), display(sink) device type
 * only. The support for the other types like recorder, audio system will come later.
 *
 * <p>A physical device can contain the functions of
 * more than one logical device, in which case it should create
 * as many logical devices as necessary.
 *
@@ -41,7 +45,7 @@ import java.util.List;
 *
 * <p>Declared as package-private, accessed by HdmiCecService only.
 */
final class HdmiCecDevice {
abstract class HdmiCecDevice {
    private static final String TAG = "HdmiCecDevice";

    private final int mType;
@@ -49,18 +53,38 @@ final class HdmiCecDevice {
    // List of listeners to the message/event coming to the device.
    private final List<IHdmiCecListener> mListeners = new ArrayList<IHdmiCecListener>();
    private final Binder mBinder = new Binder();
    private final HdmiCecService mService;

    private String mName;
    private boolean mIsActiveSource;

    /**
     * Factory method that creates HdmiCecDevice instance to the device type.
     */
    public static HdmiCecDevice create(HdmiCecService service, int type) {
        if (type == HdmiCec.DEVICE_PLAYBACK) {
            return new HdmiCecDevicePlayback(service, type);
        } else if (type == HdmiCec.DEVICE_TV) {
            return new HdmiCecDeviceTv(service, type);
        }
        return null;
    }

    /**
     * Constructor.
     */
    public HdmiCecDevice(int type) {
    public HdmiCecDevice(HdmiCecService service, int type) {
        mService = service;
        mType = type;
        mIsActiveSource = false;
    }

    /**
     * Called right after the class is instantiated. This method can be used to
     * implement any initialization tasks for the instance.
     */
    abstract public void initialize();

    /**
     * Return the binder token that identifies this instance.
     */
@@ -68,6 +92,13 @@ final class HdmiCecDevice {
        return mBinder;
    }

    /**
     * Return the service instance.
     */
    public HdmiCecService getService() {
        return mService;
    }

    /**
     * Return the type of this device.
     */
@@ -128,6 +159,7 @@ final class HdmiCecDevice {
        if (opcode == HdmiCec.MESSAGE_ACTIVE_SOURCE) {
            mIsActiveSource = false;
        }

        if (mListeners.size() == 0) {
            return;
        }
@@ -167,4 +199,13 @@ final class HdmiCecDevice {
    public void setIsActiveSource(boolean state) {
        mIsActiveSource = state;
    }

    /**
     * Check if the connected sink device is in powered-on state. The default implementation
     * simply returns false. Should be overriden by subclass to report the correct state.
     */
    public boolean isSinkDeviceOn() {
        Log.w(TAG, "Not valid for the device type: " + mType);
        return false;
    }
}
Loading