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

Commit 9486fd07 authored by Paul Colta's avatar Paul Colta Committed by Android (Google) Code Review
Browse files

Merge "HDMI: In offline mode, allow users to keep CEC enabled" into main

parents c9678e15 7e5e6dd2
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -524,6 +524,13 @@ final class Constants {
    static final String PROPERTY_DISABLE_CEC_ON_STANDBY_IN_LOW_ENERGY_MODE =
            "persist.sys.hdmi.property_disable_cec_on_standby_in_low_energy_mode";

    /**
     * Property that checks if CEC was manually enabled by the user in offline mode. With the help
     * of this property we avoid turning off CEC when the device goes to sleep and if the device
     * is in low energy mode.
     */
    static final String PROPERTY_USER_ACTION_KEEP_CEC_ENABLED_IN_OFFLINE_MODE =
            "persist.sys.hdmi.property_user_action_keep_cec_enabled_in_offline_mode";
    static final int RECORDING_TYPE_DIGITAL_RF = 1;
    static final int RECORDING_TYPE_ANALOGUE_RF = 2;
    static final int RECORDING_TYPE_EXTERNAL_PHYSICAL_ADDRESS = 3;
+12 −1
Original line number Diff line number Diff line
@@ -4027,7 +4027,8 @@ public class HdmiControlService extends SystemService {
                    return;
                }
                if (isTvDevice() && getDisableCecOnStandbyByLowEnergyMode()
                        && mPowerManager.isLowPowerStandbyEnabled()) {
                        && mPowerManager.isLowPowerStandbyEnabled()
                        && !userEnabledCecInOfflineMode()) {
                    Slog.w(TAG, "Disable CEC on standby due to low power energy mode.");
                    setWasCecDisabledOnStandbyByLowEnergyMode(true);
                    getHdmiCecConfig().setIntValue(
@@ -5225,4 +5226,14 @@ public class HdmiControlService extends SystemService {
                Constants.PROPERTY_WAS_CEC_DISABLED_ON_STANDBY_BY_LOW_ENERGY_MODE,
                String.valueOf(value));
    }

    /**
     * Reads the property that checks if CEC was enabled by the user while in offline mode such that
     * it won't be disabled when going to sleep by low energy mode.
     */
    @VisibleForTesting
    protected boolean userEnabledCecInOfflineMode() {
        return SystemProperties.getBoolean(
                Constants.PROPERTY_USER_ACTION_KEEP_CEC_ENABLED_IN_OFFLINE_MODE, false);
    }
}
+33 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ public class HdmiCecLocalDeviceTvTest {
    private boolean mDisableCecOnStandbyByLowEnergyMode;
    private boolean mWasCecDisabledOnStandbyByLowEnergyMode;
    private boolean mUseHdmiCecPowerStatusController;
    private boolean mUserEnabledCecInOfflineMode;

    private class DeviceEventListener {
        private HdmiDeviceInfo mDevice;
@@ -250,6 +251,11 @@ public class HdmiCecLocalDeviceTvTest {
                    protected void setWasCecDisabledOnStandbyByLowEnergyMode(boolean value) {
                        mWasCecDisabledOnStandbyByLowEnergyMode = value;
                    }

                    @Override
                    protected boolean userEnabledCecInOfflineMode() {
                        return mUserEnabledCecInOfflineMode;
                    }
                };

        mHdmiControlService.setIoLooper(mMyLooper);
@@ -298,6 +304,7 @@ public class HdmiCecLocalDeviceTvTest {
        mWasCecDisabledOnStandbyByLowEnergyMode = false;
        mDisableCecOnStandbyByLowEnergyMode = false;
        mUseHdmiCecPowerStatusController = false;
        mUserEnabledCecInOfflineMode = false;
        mNativeWrapper.clearResultMessages();
    }

@@ -2400,6 +2407,32 @@ public class HdmiCecLocalDeviceTvTest {
        assertTrue(mVendorCommandListeners.contains(vendorCommandListenerInvocationSettingChange));
    }

    @Test
    public void lowEnergyMode_userEnabledCecInOfflineMode_onStandby_cecStaysEnabled() {
        mDisableCecOnStandbyByLowEnergyMode = true;
        mUseHdmiCecPowerStatusController = true;
        mUserEnabledCecInOfflineMode = true;
        mPowerManager.setIsLowPowerStandbyEnabled(true);

        assertEquals(mHdmiCecLocalDeviceTv.mService.getHdmiCecConfig().getIntValue(
                        HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED),
                HdmiControlManager.HDMI_CEC_CONTROL_ENABLED);
        mHdmiControlService.onStandby(STANDBY_SCREEN_OFF);
        mTestLooper.dispatchAll();

        assertEquals(mHdmiCecLocalDeviceTv.mService.getHdmiCecConfig().getIntValue(
                        HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED),
                HdmiControlManager.HDMI_CEC_CONTROL_ENABLED);
        assertFalse(mWasCecDisabledOnStandbyByLowEnergyMode);
        mHdmiControlService.onWakeUp(WAKE_UP_SCREEN_ON);
        mTestLooper.dispatchAll();

        assertEquals(mHdmiCecLocalDeviceTv.mService.getHdmiCecConfig().getIntValue(
                        HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED),
                HdmiControlManager.HDMI_CEC_CONTROL_ENABLED);
        assertFalse(mWasCecDisabledOnStandbyByLowEnergyMode);
    }

    protected static class MockTvDevice extends HdmiCecLocalDeviceTv {
        MockTvDevice(HdmiControlService service) {
            super(service);