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

Commit e656e5cb authored by Michal Olech's avatar Michal Olech
Browse files

[CEC Configuration] Add 'tv_wake_on_one_touch_play' option

This ports the Settings.Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED to
HdmiCecConfig.

Bug: 166433775
Test: atest HdmiCecLocalDeviceTvTest
Change-Id: I63c7cf35b9769da193e950f362f51a0f79898a5f
parent f7e2d64c
Loading
Loading
Loading
Loading
+75 −2
Original line number Diff line number Diff line
@@ -480,6 +480,28 @@ public final class HdmiControlManager {
    @Retention(RetentionPolicy.SOURCE)
    public @interface VolumeControl {}

    // -- Whether TV Wake on One Touch Play is enabled or disabled.
    /**
     * TV Wake on One Touch Play enabled.
     *
     * @hide
     */
    public static final int TV_WAKE_ON_ONE_TOUCH_PLAY_ENABLED = 1;
    /**
     * TV Wake on One Touch Play disabled.
     *
     * @hide
     */
    public static final int TV_WAKE_ON_ONE_TOUCH_PLAY_DISABLED = 0;
    /**
     * @hide
     */
    @IntDef(prefix = { "TV_WAKE_ON_ONE_TOUCH_PLAY_" }, value = {
            TV_WAKE_ON_ONE_TOUCH_PLAY_ENABLED,
            TV_WAKE_ON_ONE_TOUCH_PLAY_DISABLED
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface TvWakeOnOneTouchPlay {}

    // -- Settings available in the CEC Configuration.
    /**
@@ -519,7 +541,6 @@ public final class HdmiControlManager {
    @SystemApi
    public static final String CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING =
            "system_audio_mode_muting";

    /**
     * Controls whether volume control commands via HDMI CEC are enabled.
     *
@@ -555,7 +576,14 @@ public final class HdmiControlManager {
     */
    public static final String CEC_SETTING_NAME_VOLUME_CONTROL_MODE =
            "volume_control_enabled";

    /**
     * Name of a setting deciding whether the TV will automatically turn on upon reception
     * of the CEC command <Text View On> or <Image View On>.
     *
     * @hide
     */
    public static final String CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY =
            "tv_wake_on_one_touch_play";
    /**
     * @hide
     */
@@ -566,6 +594,7 @@ public final class HdmiControlManager {
        CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
        CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING,
        CEC_SETTING_NAME_VOLUME_CONTROL_MODE,
        CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY,
    })
    public @interface CecSettingName {}

@@ -1869,4 +1898,48 @@ public final class HdmiControlManager {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Set the current status of TV Wake on One Touch Play.
     *
     * <p>Sets whether the TV should wake up upon reception of &lt;Text View On&gt;
     * or &lt;Image View On&gt;.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.HDMI_CEC)
    public void setTvWakeOnOneTouchPlay(@NonNull @TvWakeOnOneTouchPlay int value) {
        if (mService == null) {
            Log.e(TAG, "HdmiControlService is not available");
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            mService.setCecSettingIntValue(CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY, value);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Get the current status of TV Wake on One Touch Play.
     *
     * <p>Reflects whether the TV should wake up upon reception of &lt;Text View On&gt;
     * or &lt;Image View On&gt;.
     *
     * @hide
     */
    @NonNull
    @TvWakeOnOneTouchPlay
    @RequiresPermission(android.Manifest.permission.HDMI_CEC)
    public int getTvWakeOnOneTouchPlay() {
        if (mService == null) {
            Log.e(TAG, "HdmiControlService is not available");
            throw new RuntimeException("HdmiControlService is not available");
        }
        try {
            return mService.getCecSettingIntValue(CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -297,6 +297,8 @@ public class HdmiCecConfig {
                return STORAGE_SHARED_PREFS;
            case HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING:
                return STORAGE_SHARED_PREFS;
            case HdmiControlManager.CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY:
                return STORAGE_GLOBAL_SETTINGS;
            default:
                throw new RuntimeException("Invalid CEC setting '" + setting.getName()
                        + "' storage.");
@@ -317,6 +319,8 @@ public class HdmiCecConfig {
                return setting.getName();
            case HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING:
                return setting.getName();
            case HdmiControlManager.CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY:
                return Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED;
            default:
                throw new RuntimeException("Invalid CEC setting '" + setting.getName()
                    + "' storage key.");
+4 −13
Original line number Diff line number Diff line
@@ -94,9 +94,6 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    // If true, TV going to standby mode puts other devices also to standby.
    private boolean mAutoDeviceOff;

    // If true, TV wakes itself up when receiving <Text/Image View On>.
    private boolean mAutoWakeup;

    private final HdmiCecStandbyModeHandler mStandbyHandler;

    // If true, do not do routing control/send active source for internal source.
@@ -163,7 +160,6 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        mPrevPortId = Constants.INVALID_PORT_ID;
        mAutoDeviceOff = mService.readBooleanSetting(Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
                true);
        mAutoWakeup = mService.readBooleanSetting(Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED, true);
        mSystemAudioControlFeatureEnabled =
                mService.readBooleanSetting(Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED, true);
        mStandbyHandler = new HdmiCecStandbyModeHandler(service, this);
@@ -641,7 +637,7 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        // implemented in such a way that Android system is not really put to standby mode
        // but only the display is set to blank. Then the command leads to the effect of
        // turning on the display by the invocation of PowerManager.wakeUp().
        if (mService.isPowerStandbyOrTransient() && mAutoWakeup) {
        if (mService.isPowerStandbyOrTransient() && getAutoWakeup()) {
            mService.wakeUp();
        }
        return true;
@@ -1215,16 +1211,12 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        mAutoDeviceOff = enabled;
    }

    @ServiceThreadOnly
    void setAutoWakeup(boolean enabled) {
        assertRunOnServiceThread();
        mAutoWakeup = enabled;
    }

    @ServiceThreadOnly
    boolean getAutoWakeup() {
        assertRunOnServiceThread();
        return mAutoWakeup;
        return mService.getHdmiCecConfig().getIntValue(
                  HdmiControlManager.CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY)
                    == HdmiControlManager.TV_WAKE_ON_ONE_TOUCH_PLAY_ENABLED;
    }

    @Override
@@ -1552,7 +1544,6 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        pw.println("mSystemAudioMute: " + mSystemAudioMute);
        pw.println("mSystemAudioControlFeatureEnabled: " + mSystemAudioControlFeatureEnabled);
        pw.println("mAutoDeviceOff: " + mAutoDeviceOff);
        pw.println("mAutoWakeup: " + mAutoWakeup);
        pw.println("mSkipRoutingControl: " + mSkipRoutingControl);
        pw.println("mPrevPortId: " + mPrevPortId);
    }
+10 −7
Original line number Diff line number Diff line
@@ -526,6 +526,16 @@ public class HdmiControlService extends SystemService {
                        initializeCec(INITIATED_BY_ENABLE_CEC);
                    }
                });
        mHdmiCecConfig.registerChangeListener(
                HdmiControlManager.CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY,
                new HdmiCecConfig.SettingChangeListener() {
                    @Override
                    public void onChange(String setting) {
                        if (isTvDeviceEnabled()) {
                            setCecOption(OptionKey.WAKEUP, tv().getAutoWakeup());
                        }
                    }
                });
    }

    private void bootCompleted() {
@@ -651,7 +661,6 @@ public class HdmiControlService extends SystemService {
        ContentResolver resolver = getContext().getContentResolver();
        String[] settings = new String[] {
                Global.HDMI_CONTROL_VOLUME_CONTROL_ENABLED,
                Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED,
                Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
                Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED,
                Global.MHL_INPUT_SWITCHING_ENABLED,
@@ -680,12 +689,6 @@ public class HdmiControlService extends SystemService {
                    setHdmiCecVolumeControlEnabledInternal(getHdmiCecConfig().getIntValue(
                            HdmiControlManager.CEC_SETTING_NAME_VOLUME_CONTROL_MODE));
                    break;
                case Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED:
                    if (isTvDeviceEnabled()) {
                        tv().setAutoWakeup(enabled);
                    }
                    setCecOption(OptionKey.WAKEUP, enabled);
                    break;
                case Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED:
                    for (int type : mLocalDevices) {
                        HdmiCecLocalDevice localDevice = mHdmiCecNetwork.getLocalDevice(type);
+9 −0
Original line number Diff line number Diff line
@@ -55,4 +55,13 @@
    </allowed-values>
    <default-value int-value="1" />
  </setting>
  <setting name="tv_wake_on_one_touch_play"
      value-type="int"
      user-configurable="true">
    <allowed-values>
      <value int-value="0" />
      <value int-value="1" />
    </allowed-values>
    <default-value int-value="1" />
  </setting>
</cec-settings>
Loading