From 588d1031a55229c28e49945f97fb6d7d6e0573c8 Mon Sep 17 00:00:00 2001 From: Caitlin Cassidy Date: Mon, 1 Aug 2022 19:13:23 +0000 Subject: [PATCH] [Media TTT] Don't wake the screen if the screen is already in dream state. Fixes: 239426653 Test: manual: verified chip displays on top of dream instead of fully waking the device Test: MediaTttChipControllerCommonTest Change-Id: Ieef1681cfcd2cf46ed5b6faaa1f692c768ae4427 --- .../common/MediaTttChipControllerCommon.kt | 16 ++++++++++------ .../MediaTttChipControllerCommonTest.kt | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt index 79e1fb9a60f63..a86421158eb2b 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommon.kt @@ -112,12 +112,16 @@ abstract class MediaTttChipControllerCommon( // The chip is new, so set up all our callbacks and inflate the view configurationController.addCallback(displayScaleListener) tapGestureDetector.addOnGestureDetectedCallback(TAG, this::onScreenTapped) - // Wake the screen so the user will see the chip - powerManager.wakeUp( - SystemClock.uptimeMillis(), - PowerManager.WAKE_REASON_APPLICATION, - "com.android.systemui:media_tap_to_transfer_activated" - ) + // Wake the screen if necessary so the user will see the chip. (Per b/239426653, we want + // the chip to show over the dream state, so we should only wake up if the screen is + // completely off.) + if (!powerManager.isScreenOn) { + powerManager.wakeUp( + SystemClock.uptimeMillis(), + PowerManager.WAKE_REASON_APPLICATION, + "com.android.systemui:media_tap_to_transfer_activated" + ) + } inflateAndUpdateChip(newChipInfo) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt index 55397868125bb..7337764b9ec25 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/taptotransfer/common/MediaTttChipControllerCommonTest.kt @@ -115,14 +115,31 @@ class MediaTttChipControllerCommonTest : SysuiTestCase() { } @Test - fun displayChip_chipAddedAndGestureDetectionStartedAndScreenOn() { + fun displayChip_chipAddedAndGestureDetectionStarted() { controllerCommon.displayChip(getState()) verify(windowManager).addView(any(), any()) verify(tapGestureDetector).addOnGestureDetectedCallback(any(), any()) + } + + @Test + fun displayChip_screenOff_screenWakes() { + whenever(powerManager.isScreenOn).thenReturn(false) + + controllerCommon.displayChip(getState()) + verify(powerManager).wakeUp(any(), any(), any()) } + @Test + fun displayChip_screenAlreadyOn_screenNotWoken() { + whenever(powerManager.isScreenOn).thenReturn(true) + + controllerCommon.displayChip(getState()) + + verify(powerManager, never()).wakeUp(any(), any(), any()) + } + @Test fun displayChip_twice_chipAndGestureDetectionNotAddedTwice() { controllerCommon.displayChip(getState())