From 086b16bc8ca8d084e5860535fefde69e20c47dd2 Mon Sep 17 00:00:00 2001 From: Nathalie Le Clair Date: Thu, 3 Mar 2022 18:15:52 +0100 Subject: [PATCH] Exit dream mode when receiving Bug: 203057988 Test: atest Change-Id: Ifc6b66195f9e797f8a0ece7d370d80450f19a7b6 --- .../server/hdmi/HdmiCecLocalDeviceTv.java | 17 ++++++++------ .../server/hdmi/HdmiCecLocalDeviceTvTest.java | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java index c0950bf13a1c4..d249d578cf67a 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecLocalDeviceTv.java @@ -654,14 +654,17 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice { protected int handleTextViewOn(HdmiCecMessage message) { assertRunOnServiceThread(); - // Note that (and ) command won't be handled here in - // most cases. A dedicated microcontroller should be in charge while Android system - // is in sleep mode, and the command need not be passed up to this service. - // The only situation where the command reaches this handler is that sleep mode is - // 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 + // Note that if the device is in sleep mode, the (and ) + // command won't be handled here in most cases. A dedicated microcontroller should be in + // charge while the Android system is in sleep mode, and the command doesn't need to be + // passed up to this service. + // The only situations where the command reaches this handler are + // 1. if sleep mode is 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 // turning on the display by the invocation of PowerManager.wakeUp(). - if (mService.isPowerStandbyOrTransient() && getAutoWakeup()) { + // 2. if the device is in dream mode, not sleep mode. Then this command leads to + // waking up the device from dream mode by the invocation of PowerManager.wakeUp(). + if (getAutoWakeup()) { mService.wakeUp(); } return Constants.HANDLED; diff --git a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java index a9812ab9bb03a..d104871f488a6 100644 --- a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java +++ b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecLocalDeviceTvTest.java @@ -89,6 +89,7 @@ public class HdmiCecLocalDeviceTvTest { private ArrayList mLocalDevices = new ArrayList<>(); private int mTvPhysicalAddress; private int mTvLogicalAddress; + private boolean mWokenUp; @Mock private AudioManager mAudioManager; @@ -104,6 +105,11 @@ public class HdmiCecLocalDeviceTvTest { new HdmiControlService(InstrumentationRegistry.getTargetContext(), Collections.emptyList()) { @Override + void wakeUp() { + mWokenUp = true; + super.wakeUp(); + } + @Override boolean isControlEnabled() { return true; } @@ -307,6 +313,22 @@ public class HdmiCecLocalDeviceTvTest { assertThat(mPowerManager.isInteractive()).isFalse(); } + @Test + public void handleTextViewOn_Dreaming() { + mHdmiCecLocalDeviceTv.mService.getHdmiCecConfig().setIntValue( + HdmiControlManager.CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY, + HdmiControlManager.TV_WAKE_ON_ONE_TOUCH_PLAY_ENABLED); + mTestLooper.dispatchAll(); + mPowerManager.setInteractive(true); + mWokenUp = false; + HdmiCecMessage textViewOn = HdmiCecMessageBuilder.buildTextViewOn(ADDR_PLAYBACK_1, + mTvLogicalAddress); + assertThat(mHdmiCecLocalDeviceTv.dispatchMessage(textViewOn)).isEqualTo(Constants.HANDLED); + mTestLooper.dispatchAll(); + assertThat(mPowerManager.isInteractive()).isTrue(); + assertThat(mWokenUp).isTrue(); + } + @Test public void tvSendStandbyOnSleep_Enabled() { mHdmiCecLocalDeviceTv.mService.getHdmiCecConfig().setIntValue(