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

Commit 64b1ad5a authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Android Git Automerger
Browse files

am c9cb9138: am 4c963841: am b1dca162: Merge "Maintain display power status...

am c9cb9138: am 4c963841: am b1dca162: Merge "Maintain display power status for playback device" into klp-modular-dev

* commit 'c9cb9138':
  Maintain display power status for playback device
parents 4a700092 c9cb9138
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