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

Commit 8f79d8c0 authored by Michal Olech's avatar Michal Olech
Browse files

[CEC] Standby when <Active Source> lost

Add an option to go to standby when <Active Source> received from other device

For better configurability, a "ro.hdmi.cec.source.power_state_change_on_active_source_lost" system property is introduced which controls the new behaviour.

Bug: 156367087
Test: manually tested on a device
Change-Id: I7a068064bb5e867fd364d2b84c7066db06baec3e
parent 42376094
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -70,6 +70,13 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
                    .playback_device_action_on_routing_control()
                    .orElse(HdmiProperties.playback_device_action_on_routing_control_values.NONE);

    // Behaviour of the device when <Active Source> is lost in favor of another device.
    @VisibleForTesting
    protected HdmiProperties.power_state_change_on_active_source_lost_values
            mPowerStateChangeOnActiveSourceLost = HdmiProperties
                    .power_state_change_on_active_source_lost()
                    .orElse(HdmiProperties.power_state_change_on_active_source_lost_values.NONE);

    HdmiCecLocalDevicePlayback(HdmiControlService service) {
        super(service, HdmiDeviceInfo.DEVICE_PLAYBACK);

@@ -239,6 +246,23 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
        return !getWakeLock().isHeld();
    }

    @Override
    @ServiceThreadOnly
    protected boolean handleActiveSource(HdmiCecMessage message) {
        super.handleActiveSource(message);
        if (mIsActiveSource) {
            return true;
        }
        switch (mPowerStateChangeOnActiveSourceLost) {
            case STANDBY_NOW:
                mService.standby();
                return true;
            case NONE:
                return true;
        }
        return true;
    }

    @ServiceThreadOnly
    protected boolean handleUserControlPressed(HdmiCecMessage message) {
        assertRunOnServiceThread();
+52 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class HdmiCecLocalDevicePlaybackTest {
    private ArrayList<HdmiCecLocalDevice> mLocalDevices = new ArrayList<>();
    private int mPlaybackPhysicalAddress;
    private boolean mWokenUp;
    private boolean mStandby;

    @Mock private IPowerManager mIPowerManagerMock;
    @Mock private IThermalService mIThermalServiceMock;
@@ -79,6 +80,11 @@ public class HdmiCecLocalDevicePlaybackTest {
                    mWokenUp = true;
                }

                @Override
                void standby() {
                    mStandby = true;
                }

                @Override
                boolean isControlEnabled() {
                    return true;
@@ -343,6 +349,52 @@ public class HdmiCecLocalDevicePlaybackTest {
        assertThat(mNativeWrapper.getResultMessages()).contains(standbyMessage);
    }

    @Test
    public void handleActiveSource_ActiveSource_None() {
        mHdmiCecLocalDevicePlayback.mPowerStateChangeOnActiveSourceLost =
            HdmiProperties.power_state_change_on_active_source_lost_values.NONE;
        mStandby = false;
        HdmiCecMessage message = HdmiCecMessageBuilder.buildActiveSource(ADDR_PLAYBACK_1,
                                         mPlaybackPhysicalAddress);
        assertThat(mHdmiCecLocalDevicePlayback.handleActiveSource(message)).isTrue();
        mTestLooper.dispatchAll();
        assertThat(mStandby).isFalse();
    }

    @Test
    public void handleActiveSource_notActiveSource_None() {
        mHdmiCecLocalDevicePlayback.mPowerStateChangeOnActiveSourceLost =
            HdmiProperties.power_state_change_on_active_source_lost_values.NONE;
        mStandby = false;
        HdmiCecMessage message = HdmiCecMessageBuilder.buildActiveSource(ADDR_TV, 0x0000);
        assertThat(mHdmiCecLocalDevicePlayback.handleActiveSource(message)).isTrue();
        mTestLooper.dispatchAll();
        assertThat(mStandby).isFalse();
    }

    @Test
    public void handleActiveSource_ActiveSource_StandbyNow() {
        mHdmiCecLocalDevicePlayback.mPowerStateChangeOnActiveSourceLost =
            HdmiProperties.power_state_change_on_active_source_lost_values.STANDBY_NOW;
        mStandby = false;
        HdmiCecMessage message = HdmiCecMessageBuilder.buildActiveSource(ADDR_PLAYBACK_1,
                                         mPlaybackPhysicalAddress);
        assertThat(mHdmiCecLocalDevicePlayback.handleActiveSource(message)).isTrue();
        mTestLooper.dispatchAll();
        assertThat(mStandby).isFalse();
    }

    @Test
    public void handleActiveSource_notActiveSource_StandbyNow() {
        mHdmiCecLocalDevicePlayback.mPowerStateChangeOnActiveSourceLost =
            HdmiProperties.power_state_change_on_active_source_lost_values.STANDBY_NOW;
        mStandby = false;
        HdmiCecMessage message = HdmiCecMessageBuilder.buildActiveSource(ADDR_TV, 0x0000);
        assertThat(mHdmiCecLocalDevicePlayback.handleActiveSource(message)).isTrue();
        mTestLooper.dispatchAll();
        assertThat(mStandby).isTrue();
    }

    @Test
    public void sendVolumeKeyEvent_up_volumeEnabled() {
        mHdmiControlService.setHdmiCecVolumeControlEnabled(true);