Commit 051b2c52 authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Commit Bot

ambient: avoid restart lock timer if it's running

Bug: b:170509871
Test: unittests and manually on nocturne
Change-Id: Ib59a1c9e00056a5fdd13e5ee94cac51c365cf9b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462025Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816206}
parent fa967c61
...@@ -476,7 +476,8 @@ void AmbientController::AcquireWakeLock() { ...@@ -476,7 +476,8 @@ void AmbientController::AcquireWakeLock() {
auto* session_controller = Shell::Get()->session_controller(); auto* session_controller = Shell::Get()->session_controller();
if (session_controller->CanLockScreen() && if (session_controller->CanLockScreen() &&
session_controller->ShouldLockScreenAutomatically()) { session_controller->ShouldLockScreenAutomatically()) {
if (!session_controller->IsScreenLocked()) { if (!session_controller->IsScreenLocked() &&
!delayed_lock_timer_.IsRunning()) {
delayed_lock_timer_.Start( delayed_lock_timer_.Start(
FROM_HERE, kLockScreenDelay, base::BindOnce([]() { FROM_HERE, kLockScreenDelay, base::BindOnce([]() {
Shell::Get()->session_controller()->LockScreen(); Shell::Get()->session_controller()->LockScreen();
......
...@@ -501,6 +501,35 @@ TEST_F(AmbientControllerTest, ...@@ -501,6 +501,35 @@ TEST_F(AmbientControllerTest,
EXPECT_FALSE(ambient_controller()->IsShown()); EXPECT_FALSE(ambient_controller()->IsShown());
} }
TEST_F(AmbientControllerTest,
ShouldShowAmbientScreenWithLockscreenWithNoisyPowerEvents) {
GetSessionControllerClient()->SetShouldLockScreenAutomatically(true);
SetPowerStateCharging();
EXPECT_FALSE(ambient_controller()->IsShown());
// Should enter ambient mode when the screen is dimmed.
SetScreenIdleStateAndWait(/*dimmed=*/true, /*off=*/false);
EXPECT_FALSE(IsLocked());
EXPECT_FALSE(ambient_controller()->IsShown());
FastForwardTiny();
EXPECT_TRUE(ambient_controller()->IsShown());
FastForwardHalfLockScreenDelay();
SetPowerStateCharging();
FastForwardHalfLockScreenDelay();
SetPowerStateCharging();
EXPECT_TRUE(IsLocked());
// Should not disrupt ongoing ambient mode.
EXPECT_TRUE(ambient_controller()->IsShown());
// Closes ambient for clean-up.
UnlockScreen();
EXPECT_FALSE(ambient_controller()->IsShown());
}
TEST_F(AmbientControllerTest, TEST_F(AmbientControllerTest,
ShouldShowAmbientScreenWithoutLockscreenWhenScreenIsDimmed) { ShouldShowAmbientScreenWithoutLockscreenWhenScreenIsDimmed) {
GetSessionControllerClient()->SetShouldLockScreenAutomatically(true); GetSessionControllerClient()->SetShouldLockScreenAutomatically(true);
......
...@@ -291,6 +291,11 @@ void AmbientAshTestBase::FastForwardToLockScreen() { ...@@ -291,6 +291,11 @@ void AmbientAshTestBase::FastForwardToLockScreen() {
task_environment()->FastForwardBy(kFastForwardFactor * kLockScreenDelay); task_environment()->FastForwardBy(kFastForwardFactor * kLockScreenDelay);
} }
void AmbientAshTestBase::FastForwardHalfLockScreenDelay() {
task_environment()->FastForwardBy(0.5 * kFastForwardFactor *
kLockScreenDelay);
}
void AmbientAshTestBase::SetPowerStateCharging() { void AmbientAshTestBase::SetPowerStateCharging() {
power_manager::PowerSupplyProperties proto; power_manager::PowerSupplyProperties proto;
proto.set_battery_state( proto.set_battery_state(
......
...@@ -105,6 +105,7 @@ class AmbientAshTestBase : public AshTestBase { ...@@ -105,6 +105,7 @@ class AmbientAshTestBase : public AshTestBase {
// Advance the task environment timer to ambient mode lock screen delay. // Advance the task environment timer to ambient mode lock screen delay.
void FastForwardToLockScreen(); void FastForwardToLockScreen();
void FastForwardHalfLockScreenDelay();
void SetPowerStateCharging(); void SetPowerStateCharging();
void SetPowerStateDischarging(); void SetPowerStateDischarging();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment