Commit a2420700 authored by wutao's avatar wutao Committed by Commit Bot

ambient: Close UI when unlock screen

When the secondary user logs in, the OnLockStateChanged() was returned
due to the Ambient mode is not allowed, therefore the ambient UI is not
closed. This patch moves the close ui logic before the ambient enabled
check.

Bug: 1136302
Test: Added new unittest
Change-Id: I2d9c93087b8e8139936271db2a797f6322bb55ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462246Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815463}
parent fbfc9e4a
...@@ -285,41 +285,42 @@ void AmbientController::OnAutoShowTimeOut() { ...@@ -285,41 +285,42 @@ void AmbientController::OnAutoShowTimeOut() {
} }
void AmbientController::OnLockStateChanged(bool locked) { void AmbientController::OnLockStateChanged(bool locked) {
if (!locked) {
// Ambient screen will be destroyed along with the lock screen when user
// logs in.
CloseUi();
return;
}
if (!IsAmbientModeEnabled()) { if (!IsAmbientModeEnabled()) {
VLOG(1) << "Ambient mode is not allowed."; VLOG(1) << "Ambient mode is not allowed.";
return; return;
} }
if (locked) { // We have 3 options to manage the token for lock screen. Here use option 1.
// We have 3 options to manage the token for lock screen. Here use option 1. // 1. Request only one time after entering lock screen. We will use it once
// 1. Request only one time after entering lock screen. We will use it once // to request all the image links and no more requests.
// to request all the image links and no more requests. // 2. Request one time before entering lock screen. This will introduce
// 2. Request one time before entering lock screen. This will introduce // extra latency.
// extra latency. // 3. Request and refresh the token in the background (even the ambient mode
// 3. Request and refresh the token in the background (even the ambient mode // is not started) with extra buffer time to use. When entering
// is not started) with extra buffer time to use. When entering // lock screen, it will be most likely to have the token already and
// lock screen, it will be most likely to have the token already and // enough time to use. More specifically,
// enough time to use. More specifically, // 3a. We will leave enough buffer time (e.g. 10 mins before expire) to
// 3a. We will leave enough buffer time (e.g. 10 mins before expire) to // start to refresh the token.
// start to refresh the token. // 3b. When lock screen is triggered, most likely we will have >10 mins
// 3b. When lock screen is triggered, most likely we will have >10 mins // of token which can be used on lock screen.
// of token which can be used on lock screen. // 3c. There is a corner case that we may not have the token fetched when
// 3c. There is a corner case that we may not have the token fetched when // locking screen, we probably can use PrepareForLock(callback) when
// locking screen, we probably can use PrepareForLock(callback) when // locking screen. We can add the refresh token into it. If the token
// locking screen. We can add the refresh token into it. If the token // has already been fetched, then there is not additional time to
// has already been fetched, then there is not additional time to // wait.
// wait. RequestAccessToken(base::DoNothing(), /*may_refresh_token_on_lock=*/true);
RequestAccessToken(base::DoNothing(), /*may_refresh_token_on_lock=*/true);
if (!IsShown()) {
if (!IsShown()) { // When lock screen starts, we don't immediately show the UI. The Ui is
// When lock screen starts, we don't immediately show the UI. The Ui is // hidden and will show after a delay.
// hidden and will show after a delay. ShowHiddenUi();
ShowHiddenUi();
}
} else {
// Ambient screen will be destroyed along with the lock screen when user
// logs in.
CloseUi();
} }
} }
......
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
namespace ash { namespace ash {
constexpr char kUser1[] = "user1@gmail.com";
constexpr char kUser2[] = "user2@gmail.com";
class AmbientControllerTest : public AmbientAshTestBase { class AmbientControllerTest : public AmbientAshTestBase {
public: public:
AmbientControllerTest() : AmbientAshTestBase() {} AmbientControllerTest() : AmbientAshTestBase() {}
...@@ -117,6 +120,70 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlock) { ...@@ -117,6 +120,70 @@ TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlock) {
EXPECT_FALSE(container_view()); EXPECT_FALSE(container_view());
} }
TEST_F(AmbientControllerTest, CloseAmbientScreenUponUnlockSecondaryUser) {
// Simulate the login screen.
ClearLogin();
SimulateUserLogin(kUser1);
SetAmbientModeEnabled(true);
LockScreen();
FastForwardToInactivity();
FastForwardTiny();
EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown());
SimulateUserLogin(kUser2);
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget.
EXPECT_FALSE(container_view());
FastForwardToInactivity();
FastForwardTiny();
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget.
EXPECT_FALSE(container_view());
}
TEST_F(AmbientControllerTest, NotShowAmbientWhenLockSecondaryUser) {
// Simulate the login screen.
ClearLogin();
SimulateUserLogin(kUser1);
SetAmbientModeEnabled(true);
LockScreen();
FastForwardToInactivity();
FastForwardTiny();
EXPECT_TRUE(container_view());
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kShown);
EXPECT_TRUE(ambient_controller()->IsShown());
SimulateUserLogin(kUser2);
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget.
EXPECT_FALSE(container_view());
LockScreen();
FastForwardToInactivity();
FastForwardTiny();
EXPECT_EQ(AmbientUiModel::Get()->ui_visibility(),
AmbientUiVisibility::kClosed);
EXPECT_FALSE(ambient_controller()->IsShown());
// The view should be destroyed along the widget.
EXPECT_FALSE(container_view());
}
TEST_F(AmbientControllerTest, ShouldRequestAccessTokenWhenLockingScreen) { TEST_F(AmbientControllerTest, ShouldRequestAccessTokenWhenLockingScreen) {
EXPECT_FALSE(IsAccessTokenRequestPending()); EXPECT_FALSE(IsAccessTokenRequestPending());
......
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