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

Commit 9c6582f2 authored by Yan Han's avatar Yan Han Committed by Automerger Merge Worker
Browse files

Merge "Pause media session on TV power toggle" into sc-dev am: 3f3fbe71

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13583068

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I36c2b2880cfd6ac312a52900e4a4d4c0a9e57c04
parents ec1038a7 3f3fbe71
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
@@ -24,6 +24,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;
@@ -34,6 +36,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;
@@ -1551,6 +1554,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(