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

Commit 160a6e5b authored by Jinsuk Kim's avatar Jinsuk Kim
Browse files

Add setOption for HdmiControlService

Bug: 15845304
Change-Id: I96b285ae3938aeecdd44b2c08a178def33bd2bf2
parent 8b4c1e95
Loading
Loading
Loading
Loading
+49 −1
Original line number Diff line number Diff line
@@ -104,7 +104,6 @@ public final class HdmiCec {
    /** Logical address used to indicate the source comes from internal device. */
    public static final int ADDR_INTERNAL = 0xFFFF;

    // TODO: Complete the list of CEC messages definition.
    public static final int MESSAGE_FEATURE_ABORT = 0x00;
    public static final int MESSAGE_IMAGE_VIEW_ON = 0x04;
    public static final int MESSAGE_TUNER_STEP_INCREMENT = 0x05;
@@ -190,6 +189,55 @@ public final class HdmiCec {
    public static final int RESULT_EXCEPTION = 5;
    public static final int RESULT_INCORRECT_MODE = 6;

    // Definitions used for setOption(). These should be in sync with the definition
    // in hardware/libhardware/include/hardware/{hdmi_cec.h,mhl.h}.

    /**
     * TV gets turned on by incoming <Text/Image View On>. {@code ENABLED} by default.
     * If set to {@code DISABLED}, TV won't turn on automatically.
     */
    public static final int OPTION_CEC_AUTO_WAKEUP = 1;

    /**
     * If set to {@code DISABLED}, all CEC commands are discarded.
     *
     * <p> This option is for internal use only, not supposed to be used by other components.
     * @hide
     */
    public static final int OPTION_CEC_ENABLE = 2;

    /**
     * If set to {@code DISABLED}, system service yields control of CEC to sub-microcontroller.
     * If {@code ENABLED}, it take the control back.
     *
     * <p> This option is for internal use only, not supposed to be used by other components.
     * @hide
     */
    public static final int OPTION_CEC_SERVICE_CONTROL = 3;

    /**
     * Put other devices to standby when TV goes to standby. {@code ENABLED} by default.
     * If set to {@code DISABLED}, TV doesn't send &lt;Standby&gt; to other devices.
     */
    public static final int OPTION_CEC_AUTO_DEVICE_OFF = 4;

    /** If set to {@code DISABLED}, TV does not switch ports when mobile device is connected. */
    public static final int OPTION_MHL_INPUT_SWITCHING = 101;

    /** If set to {@code ENABLED}, TV disables power charging for mobile device. */
    public static final int OPTION_MHL_POWER_CHARGE = 102;

    /**
     * If set to {@code DISABLED}, all MHL commands are discarded.
     *
     * <p> This option is for internal use only, not supposed to be used by other components.
     * @hide
     */
    public static final int OPTION_MHL_ENABLE = 103;

    public static final int DISABLED = 0;
    public static final int ENABLED = 1;

    private static final int[] ADDRESS_TO_TYPE = {
        DEVICE_TV,  // ADDR_TV
        DEVICE_RECORDER,  // ADDR_RECORDER_1
+1 −0
Original line number Diff line number Diff line
@@ -50,4 +50,5 @@ interface IHdmiControlService {
    void removeSystemAudioModeChangeListener(IHdmiSystemAudioModeChangeListener listener);
    void setControlEnabled(boolean enabled);
    void setArcMode(boolean enabled);
    void setOption(int option, int value);
}
+3 −3
Original line number Diff line number Diff line
@@ -318,9 +318,9 @@ final class HdmiCecController {
     *
     * @param flag a key of option. For more details, look at
     *        {@link HdmiConstants#FLAG_HDMI_OPTION_WAKEUP} to
     *        {@link HdmiConstants#FLAG_HDMI_OPTION_SYSTEM_CEC_CONTROL}
     * @param value a value of option. Actual value varies flag. For more
     *        details, look at description of flags
     *        {@link HdmiConstants#FLAG_HDMI_OPTION_SYSTEM_CEC_CONTROL}.
     * @param value a value of option. Actual value varies from flag to flag. For more
     *        details, look at description of flags.
     */
    @ServiceThreadOnly
    void setOption(int flag, int value) {
+9 −0
Original line number Diff line number Diff line
@@ -78,6 +78,9 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    // This is not thread-safe. For external purpose use mSafeDeviceInfos.
    private final SparseArray<HdmiCecDeviceInfo> mDeviceInfos = new SparseArray<>();

    // If true, TV going to standby mode puts other devices also to standby.
    private boolean mAutoDeviceOff;

    HdmiCecLocalDeviceTv(HdmiControlService service) {
        super(service, HdmiCec.DEVICE_TV);
        mPrevPortId = HdmiConstants.INVALID_PORT_ID;
@@ -976,4 +979,10 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
            hotplugActions.get(0).pollAllDevicesNow();
        }
    }

    @ServiceThreadOnly
    void setAutoDeviceOff(boolean enabled) {
        assertRunOnServiceThread();
        mAutoDeviceOff = enabled;
    }
}
+32 −1
Original line number Diff line number Diff line
@@ -724,7 +724,7 @@ public final class HdmiControlService extends SystemService {
        }

        @Override
        public void setControlEnabled(boolean enabled) {
        public void setControlEnabled(final boolean enabled) {
            enforceAccessPermission();
            synchronized (mLock) {
                mHdmiControlEnabled = enabled;
@@ -741,6 +741,11 @@ public final class HdmiControlService extends SystemService {
                    if (tv == null) {
                        return;
                    }
                    int value = enabled ? HdmiCec.ENABLED : HdmiCec.DISABLED;
                    mCecController.setOption(HdmiCec.OPTION_CEC_ENABLE, value);
                    if (mMhlController != null) {
                        mMhlController.setOption(HdmiCec.OPTION_MHL_ENABLE, value);
                    }
                    tv.routingAtEnableTime();
                }
            });
@@ -760,6 +765,32 @@ public final class HdmiControlService extends SystemService {
                }
            });
        }

        @Override
        public void setOption(final int key, final int value) {
            if (!isTvDevice()) {
                return;
            }
            switch (key) {
                case HdmiCec.OPTION_CEC_AUTO_WAKEUP:
                    mCecController.setOption(key, value);
                    break;
                case HdmiCec.OPTION_CEC_AUTO_DEVICE_OFF:
                    // No need to pass this option to HAL.
                    tv().setAutoDeviceOff(value == HdmiCec.ENABLED);
                    break;
                case HdmiCec.OPTION_MHL_INPUT_SWITCHING:  // Fall through
                case HdmiCec.OPTION_MHL_POWER_CHARGE:
                    if (mMhlController != null) {
                        mMhlController.setOption(key, value);
                    }
                    break;
            }
        }

        private boolean isTvDevice() {
            return tv() != null;
        }
    }

    @ServiceThreadOnly