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

Commit bb0c357d authored by Yan Han's avatar Yan Han
Browse files

Pause media session on TV power toggle

Test: Manual; atest HdmiCecLocalDevicePlaybackTest
Bug: 175095458
Change-Id: I157c1ddf145dc0e94a1076ea83248b8d61f14a73
parent 8b8c4301
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -139,8 +139,12 @@ abstract class HdmiCecLocalDeviceSource extends HdmiCecLocalDevice {
    @ServiceThreadOnly
    void toggleAndFollowTvPower() {
        assertRunOnServiceThread();
        if (mService.getPowerManager().isInteractive()) {
            mService.pauseActiveMediaSessions();
        } else {
            // Wake up Android framework to take over CEC control from the microprocessor.
            mService.wakeUp();
        }
        mService.queryDisplayStatus(new IHdmiControlCallback.Stub() {
            @Override
            public void onComplete(int status) {
+28 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import static com.android.server.hdmi.HdmiControlService.INITIATED_BY_ENABLE_CEC

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.when;

import android.content.Context;
import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiDeviceInfo;
@@ -33,6 +35,7 @@ import android.os.IPowerManager;
import android.os.IThermalService;
import android.os.Looper;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.test.TestLooper;
import android.platform.test.annotations.Presubmit;
import android.sysprop.HdmiProperties;
@@ -1549,6 +1552,31 @@ public class HdmiCecLocalDevicePlaybackTest {
        assertThat(mStandby).isFalse();
    }

    @Test
    public void toggleAndFollowTvPower_isInteractive() throws RemoteException {
        when(mIPowerManagerMock.isInteractive()).thenReturn(true);
        mActiveMediaSessionsPaused = false;
        mWokenUp = false;

        mHdmiControlService.toggleAndFollowTvPower();

        assertThat(mActiveMediaSessionsPaused).isTrue();
        assertThat(mWokenUp).isFalse();
    }

    @Test
    public void toggleAndFollowTvPower_isNotInteractive() throws RemoteException {
        when(mIPowerManagerMock.isInteractive()).thenReturn(false);
        mActiveMediaSessionsPaused = false;
        mWokenUp = false;

        mHdmiControlService.toggleAndFollowTvPower();

        assertThat(mActiveMediaSessionsPaused).isFalse();
        assertThat(mWokenUp).isTrue();
    }


    @Test
    public void shouldHandleTvPowerKey_CecDisabled() {
        mHdmiCecLocalDevicePlayback.mService.getHdmiCecConfig().setIntValue(