Commit d6010a57 authored by Jiewei Qian's avatar Jiewei Qian Committed by Commit Bot

Revert "ambient: handle suspend case better"

This reverts commit 29736b94.

Reason for revert: Tests are failing consistently in linux-chromeos-rel

Sample failing jobs:
[1] https://ci.chromium.org/p/chromium/builders/ci/linux-chromeos-rel/41574
[2] https://ci.chromium.org/p/chromium/builders/ci/linux-chromeos-rel/41572

Tried to reproduce locally, HasMaskLayerWithLongText fails 9 out of 10 times.

Error message: 
../../ash/ambient/ui/media_string_view_unittest.cc:285: Failure
Value of: GetMediaStringViewTextContainer()->layer()->layer_mask_layer()
  Actual: false
Expected: true

Original change's description:
> ambient: handle suspend case better
>
> Previously ambient mode will trigger lockscreen on screen dimm and then
> rely on lock screen idle to show screen saver. This works in some cases,
> but in suspend case the time between screen dim and cpu suspend is too
> short. Screen saver was not able to enguage. The reason we have the set
> up is because the screen saver was sharing the same window constainer as
> the lock screen, it cannot show before lock screen is ready.
>
> Now screen saver has its own window container, we changed the flow to
> show ambient mode immediately when idle. This will prevent cpu suspend
> because screen saver will take a wake lock if charging. Screen saver
> will still lock the screen in the back if user reference indicated
> lockscreen after wake.
>
> Bug: b:169442907
> Test: unitests and manual tests
> Change-Id: I1a5df2c58c976bba492c709e0a61dd5a6314d084
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435334
> Reviewed-by: Tao Wu <wutao@chromium.org>
> Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#812397}

TBR=xiaohuic@chromium.org,wutao@chromium.org,cowmoo@chromium.org

Change-Id: I307c11aed04801e6705be083dcaabfa2c5099802
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: b:169442907
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2440326Reviewed-by: default avatarJiewei Qian  <qjw@chromium.org>
Commit-Queue: Jiewei Qian  <qjw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812549}
parent 6ab0b809
...@@ -28,9 +28,6 @@ constexpr base::TimeDelta kPhotoRefreshInterval = ...@@ -28,9 +28,6 @@ constexpr base::TimeDelta kPhotoRefreshInterval =
constexpr base::TimeDelta kWeatherRefreshInterval = constexpr base::TimeDelta kWeatherRefreshInterval =
base::TimeDelta::FromMinutes(5); base::TimeDelta::FromMinutes(5);
// The delay between ambient mode starts and enabling lock screen.
constexpr base::TimeDelta kLockScreenDelay = base::TimeDelta::FromSeconds(5);
// The batch size of topics to fetch in one request. // The batch size of topics to fetch in one request.
// Magic number 2 is based on experiments that no curation on Google Photos. // Magic number 2 is based on experiments that no curation on Google Photos.
constexpr int kTopicsBatchSize = 2; constexpr int kTopicsBatchSize = 2;
......
...@@ -96,6 +96,10 @@ bool IsUiHidden(AmbientUiVisibility visibility) { ...@@ -96,6 +96,10 @@ bool IsUiHidden(AmbientUiVisibility visibility) {
return visibility == AmbientUiVisibility::kHidden; return visibility == AmbientUiVisibility::kHidden;
} }
bool IsLockScreenUi(AmbientUiMode mode) {
return mode == AmbientUiMode::kLockScreenUi;
}
bool IsAmbientModeEnabled() { bool IsAmbientModeEnabled() {
if (!AmbientClient::Get()->IsAmbientModeAllowed()) if (!AmbientClient::Get()->IsAmbientModeAllowed())
return false; return false;
...@@ -200,8 +204,7 @@ void AmbientController::OnAmbientUiVisibilityChanged( ...@@ -200,8 +204,7 @@ void AmbientController::OnAmbientUiVisibilityChanged(
// Record metrics on ambient mode usage. // Record metrics on ambient mode usage.
ambient::RecordAmbientModeActivation( ambient::RecordAmbientModeActivation(
/*ui_mode=*/LockScreen::HasInstance() ? AmbientUiMode::kLockScreenUi /*ui_mode=*/ambient_ui_model_.ui_mode(),
: AmbientUiMode::kInSessionUi,
/*tablet_mode=*/Shell::Get()->IsInTabletMode()); /*tablet_mode=*/Shell::Get()->IsInTabletMode());
DCHECK(!start_time_); DCHECK(!start_time_);
...@@ -316,11 +319,7 @@ void AmbientController::OnLockStateChanged(bool locked) { ...@@ -316,11 +319,7 @@ void AmbientController::OnLockStateChanged(bool locked) {
// wait. // wait.
RequestAccessToken(base::DoNothing(), /*may_refresh_token_on_lock=*/true); RequestAccessToken(base::DoNothing(), /*may_refresh_token_on_lock=*/true);
if (!IsShown()) { ShowUi(AmbientUiMode::kLockScreenUi);
// When lock screen starts, we don't immediately show the UI. The Ui is
// hidden and will show after a delay.
ShowHiddenUi();
}
} else { } else {
// Ambient screen will be destroyed along with the lock screen when user // Ambient screen will be destroyed along with the lock screen when user
// logs in. // logs in.
...@@ -375,7 +374,7 @@ void AmbientController::ScreenBrightnessChanged( ...@@ -375,7 +374,7 @@ void AmbientController::ScreenBrightnessChanged(
is_screen_off_ = false; is_screen_off_ = false;
// If screen is back on, turn on ambient mode for lock screen. // If screen is back on, turn on ambient mode for lock screen.
if (LockScreen::HasInstance()) if (LockScreen::HasInstance())
ShowHiddenUi(); ShowUi(AmbientUiMode::kLockScreenUi);
} }
void AmbientController::ScreenIdleStateChanged( void AmbientController::ScreenIdleStateChanged(
...@@ -393,7 +392,16 @@ void AmbientController::ScreenIdleStateChanged( ...@@ -393,7 +392,16 @@ void AmbientController::ScreenIdleStateChanged(
if (!idle_state.dimmed()) if (!idle_state.dimmed())
return; return;
ShowUi(); auto* session_controller = Shell::Get()->session_controller();
if (session_controller->CanLockScreen() &&
session_controller->ShouldLockScreenAutomatically()) {
if (!session_controller->IsScreenLocked()) {
// TODO(b/161469136): revise this behavior after further discussion.
Shell::Get()->session_controller()->LockScreen();
}
} else {
ShowUi(AmbientUiMode::kInSessionUi);
}
} }
void AmbientController::AddAmbientViewDelegateObserver( void AmbientController::AddAmbientViewDelegateObserver(
...@@ -406,8 +414,8 @@ void AmbientController::RemoveAmbientViewDelegateObserver( ...@@ -406,8 +414,8 @@ void AmbientController::RemoveAmbientViewDelegateObserver(
delegate_.RemoveObserver(observer); delegate_.RemoveObserver(observer);
} }
void AmbientController::ShowUi() { void AmbientController::ShowUi(AmbientUiMode mode) {
DVLOG(1) << __func__; DVLOG(1) << "ShowUi: " << mode;
// TODO(meilinw): move the eligibility check to the idle entry point once // TODO(meilinw): move the eligibility check to the idle entry point once
// implemented: b/149246117. // implemented: b/149246117.
...@@ -416,24 +424,30 @@ void AmbientController::ShowUi() { ...@@ -416,24 +424,30 @@ void AmbientController::ShowUi() {
return; return;
} }
ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kShown); ambient_ui_model_.SetUiMode(mode);
switch (mode) {
case AmbientUiMode::kInSessionUi:
ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kShown);
break;
case AmbientUiMode::kLockScreenUi:
ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kHidden);
break;
}
} }
void AmbientController::ShowHiddenUi() { void AmbientController::CloseUi() {
DVLOG(1) << __func__; ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kClosed);
ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kHidden);
} }
void AmbientController::CloseUi() { void AmbientController::HideLockScreenUi() {
DVLOG(1) << __func__; DCHECK(IsLockScreenUi(ambient_ui_model_.ui_mode()));
ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kClosed); ambient_ui_model_.SetUiVisibility(AmbientUiVisibility::kHidden);
} }
void AmbientController::ToggleInSessionUi() { void AmbientController::ToggleInSessionUi() {
if (ambient_ui_model_.ui_visibility() == AmbientUiVisibility::kClosed) if (!container_view_)
ShowUi(); ShowUi(AmbientUiMode::kInSessionUi);
else else
CloseUi(); CloseUi();
} }
...@@ -444,12 +458,16 @@ bool AmbientController::IsShown() const { ...@@ -444,12 +458,16 @@ bool AmbientController::IsShown() const {
void AmbientController::OnBackgroundPhotoEvents() { void AmbientController::OnBackgroundPhotoEvents() {
// Dismisses the ambient screen when user interacts with the background photo. // Dismisses the ambient screen when user interacts with the background photo.
if (LockScreen::HasInstance()) if (IsLockScreenUi(ambient_ui_model_.ui_mode()))
ShowHiddenUi(); HideLockScreenUi();
else else
CloseUi(); CloseUi();
} }
void AmbientController::UpdateUiMode(AmbientUiMode ui_mode) {
ambient_ui_model_.SetUiMode(ui_mode);
}
void AmbientController::AcquireWakeLock() { void AmbientController::AcquireWakeLock() {
if (!wake_lock_) { if (!wake_lock_) {
mojo::Remote<device::mojom::WakeLockProvider> provider; mojo::Remote<device::mojom::WakeLockProvider> provider;
...@@ -464,17 +482,6 @@ void AmbientController::AcquireWakeLock() { ...@@ -464,17 +482,6 @@ void AmbientController::AcquireWakeLock() {
DCHECK(wake_lock_); DCHECK(wake_lock_);
wake_lock_->RequestWakeLock(); wake_lock_->RequestWakeLock();
VLOG(1) << "Acquired wake lock"; VLOG(1) << "Acquired wake lock";
auto* session_controller = Shell::Get()->session_controller();
if (session_controller->CanLockScreen() &&
session_controller->ShouldLockScreenAutomatically()) {
if (!session_controller->IsScreenLocked()) {
delayed_lock_timer_.Start(
FROM_HERE, kLockScreenDelay, base::BindOnce([]() {
Shell::Get()->session_controller()->LockScreen();
}));
}
}
} }
void AmbientController::ReleaseWakeLock() { void AmbientController::ReleaseWakeLock() {
...@@ -483,8 +490,6 @@ void AmbientController::ReleaseWakeLock() { ...@@ -483,8 +490,6 @@ void AmbientController::ReleaseWakeLock() {
wake_lock_->CancelWakeLock(); wake_lock_->CancelWakeLock();
VLOG(1) << "Released wake lock"; VLOG(1) << "Released wake lock";
delayed_lock_timer_.Stop();
} }
void AmbientController::CloseWidget(bool immediately) { void AmbientController::CloseWidget(bool immediately) {
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/timer/timer.h"
#include "chromeos/dbus/power/power_manager_client.h" #include "chromeos/dbus/power/power_manager_client.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
...@@ -75,12 +74,12 @@ class ASH_EXPORT AmbientController ...@@ -75,12 +74,12 @@ class ASH_EXPORT AmbientController
void AddAmbientViewDelegateObserver(AmbientViewDelegateObserver* observer); void AddAmbientViewDelegateObserver(AmbientViewDelegateObserver* observer);
void RemoveAmbientViewDelegateObserver(AmbientViewDelegateObserver* observer); void RemoveAmbientViewDelegateObserver(AmbientViewDelegateObserver* observer);
void ShowUi(); // Invoked to show/close ambient UI in |mode|.
// Ui will be enabled but not shown immediately. If there is no user activity void ShowUi(AmbientUiMode mode);
// Ui will be shown after a short delay.
void ShowHiddenUi();
void CloseUi(); void CloseUi();
void HideLockScreenUi();
void ToggleInSessionUi(); void ToggleInSessionUi();
// Returns true if the |container_view_| is currently visible. // Returns true if the |container_view_| is currently visible.
...@@ -89,6 +88,8 @@ class ASH_EXPORT AmbientController ...@@ -89,6 +88,8 @@ class ASH_EXPORT AmbientController
// Handles events on the background photo. // Handles events on the background photo.
void OnBackgroundPhotoEvents(); void OnBackgroundPhotoEvents();
void UpdateUiMode(AmbientUiMode ui_mode);
void RequestAccessToken( void RequestAccessToken(
AmbientAccessTokenController::AccessTokenCallback callback, AmbientAccessTokenController::AccessTokenCallback callback,
bool may_refresh_token_on_lock = false); bool may_refresh_token_on_lock = false);
...@@ -189,8 +190,6 @@ class ASH_EXPORT AmbientController ...@@ -189,8 +190,6 @@ class ASH_EXPORT AmbientController
// Used to record Ambient mode engagement metrics. // Used to record Ambient mode engagement metrics.
base::Optional<base::Time> start_time_ = base::nullopt; base::Optional<base::Time> start_time_ = base::nullopt;
base::OneShotTimer delayed_lock_timer_;
base::WeakPtrFactory<AmbientController> weak_ptr_factory_{this}; base::WeakPtrFactory<AmbientController> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(AmbientController); DISALLOW_COPY_AND_ASSIGN(AmbientController);
}; };
......
This diff is collapsed.
...@@ -35,9 +35,6 @@ ...@@ -35,9 +35,6 @@
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
namespace ash { namespace ash {
namespace {
constexpr float kFastForwardFactor = 1.0001;
} // namespace
class TestAmbientURLLoaderImpl : public AmbientURLLoader { class TestAmbientURLLoaderImpl : public AmbientURLLoader {
public: public:
...@@ -144,7 +141,7 @@ void AmbientAshTestBase::SetAmbientModeEnabled(bool enabled) { ...@@ -144,7 +141,7 @@ void AmbientAshTestBase::SetAmbientModeEnabled(bool enabled) {
void AmbientAshTestBase::ShowAmbientScreen() { void AmbientAshTestBase::ShowAmbientScreen() {
// The widget will be destroyed in |AshTestBase::TearDown()|. // The widget will be destroyed in |AshTestBase::TearDown()|.
ambient_controller()->ShowUi(); ambient_controller()->ShowUi(AmbientUiMode::kInSessionUi);
// The UI only shows when images are downloaded to avoid showing blank screen. // The UI only shows when images are downloaded to avoid showing blank screen.
FastForwardToNextImage(); FastForwardToNextImage();
// Flush the message loop to finish all async calls. // Flush the message loop to finish all async calls.
...@@ -152,11 +149,12 @@ void AmbientAshTestBase::ShowAmbientScreen() { ...@@ -152,11 +149,12 @@ void AmbientAshTestBase::ShowAmbientScreen() {
} }
void AmbientAshTestBase::HideAmbientScreen() { void AmbientAshTestBase::HideAmbientScreen() {
ambient_controller()->ShowHiddenUi(); ambient_controller()->HideLockScreenUi();
} }
void AmbientAshTestBase::CloseAmbientScreen() { void AmbientAshTestBase::CloseAmbientScreen() {
ambient_controller()->CloseUi(); ambient_controller()->ambient_ui_model()->SetUiVisibility(
AmbientUiVisibility::kClosed);
} }
void AmbientAshTestBase::LockScreen() { void AmbientAshTestBase::LockScreen() {
...@@ -244,51 +242,11 @@ MediaStringView* AmbientAshTestBase::GetMediaStringView() { ...@@ -244,51 +242,11 @@ MediaStringView* AmbientAshTestBase::GetMediaStringView() {
void AmbientAshTestBase::FastForwardToInactivity() { void AmbientAshTestBase::FastForwardToInactivity() {
task_environment()->FastForwardBy( task_environment()->FastForwardBy(
kFastForwardFactor * AmbientController::kAutoShowWaitTimeInterval); 2 * AmbientController::kAutoShowWaitTimeInterval);
} }
void AmbientAshTestBase::FastForwardToNextImage() { void AmbientAshTestBase::FastForwardToNextImage() {
task_environment()->FastForwardBy(kFastForwardFactor * kPhotoRefreshInterval); task_environment()->FastForwardBy(1.2 * kPhotoRefreshInterval);
}
void AmbientAshTestBase::FastForwardTiny() {
// `TestAmbientURLLoaderImpl` has a small delay (1ms) to fake download delay,
// here we fake plenty of time to download the image.
task_environment()->FastForwardBy(base::TimeDelta::FromMilliseconds(10));
}
void AmbientAshTestBase::FastForwardToLockScreen() {
task_environment()->FastForwardBy(kFastForwardFactor * kLockScreenDelay);
}
void AmbientAshTestBase::SetPowerStateCharging() {
power_manager::PowerSupplyProperties proto;
proto.set_battery_state(
power_manager::PowerSupplyProperties_BatteryState_CHARGING);
proto.set_external_power(
power_manager::PowerSupplyProperties_ExternalPower_AC);
PowerStatus::Get()->SetProtoForTesting(proto);
ambient_controller()->OnPowerStatusChanged();
}
void AmbientAshTestBase::SetPowerStateDischarging() {
power_manager::PowerSupplyProperties proto;
proto.set_battery_state(
power_manager::PowerSupplyProperties_BatteryState_DISCHARGING);
proto.set_external_power(
power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED);
PowerStatus::Get()->SetProtoForTesting(proto);
ambient_controller()->OnPowerStatusChanged();
}
void AmbientAshTestBase::SetPowerStateFull() {
power_manager::PowerSupplyProperties proto;
proto.set_battery_state(
power_manager::PowerSupplyProperties_BatteryState_FULL);
proto.set_external_power(
power_manager::PowerSupplyProperties_ExternalPower_AC);
PowerStatus::Get()->SetProtoForTesting(proto);
ambient_controller()->OnPowerStatusChanged();
} }
void AmbientAshTestBase::FastForwardToRefreshWeather() { void AmbientAshTestBase::FastForwardToRefreshWeather() {
......
...@@ -96,20 +96,9 @@ class AmbientAshTestBase : public AshTestBase { ...@@ -96,20 +96,9 @@ class AmbientAshTestBase : public AshTestBase {
// Advance the task environment timer to load the next photo. // Advance the task environment timer to load the next photo.
void FastForwardToNextImage(); void FastForwardToNextImage();
// Advance the task environment timer a tiny amount. This is intended to
// trigger any pending async operations.
void FastForwardTiny();
// Advance the task environment timer to load the weather info. // Advance the task environment timer to load the weather info.
void FastForwardToRefreshWeather(); void FastForwardToRefreshWeather();
// Advance the task environment timer to ambient mode lock screen delay.
void FastForwardToLockScreen();
void SetPowerStateCharging();
void SetPowerStateDischarging();
void SetPowerStateFull();
// Returns the number of active wake locks of type |type|. // Returns the number of active wake locks of type |type|.
int GetNumOfActiveWakeLocks(device::mojom::WakeLockType type); int GetNumOfActiveWakeLocks(device::mojom::WakeLockType type);
......
...@@ -360,7 +360,6 @@ TEST_F(MediaStringViewTest, DoNotShowOnLockScreenIfPrefIsDisabled) { ...@@ -360,7 +360,6 @@ TEST_F(MediaStringViewTest, DoNotShowOnLockScreenIfPrefIsDisabled) {
// Simulates Ambient Mode shown on lock-screen. // Simulates Ambient Mode shown on lock-screen.
LockScreen(); LockScreen();
FastForwardToInactivity(); FastForwardToInactivity();
FastForwardTiny();
// Simulates active and playing media session. // Simulates active and playing media session.
SimulateMediaPlaybackStateChanged( SimulateMediaPlaybackStateChanged(
......
...@@ -44,6 +44,13 @@ void AmbientUiModel::SetUiVisibility(AmbientUiVisibility visibility) { ...@@ -44,6 +44,13 @@ void AmbientUiModel::SetUiVisibility(AmbientUiVisibility visibility) {
NotifyAmbientUiVisibilityChanged(); NotifyAmbientUiVisibilityChanged();
} }
void AmbientUiModel::SetUiMode(AmbientUiMode ui_mode) {
if (ui_mode_ == ui_mode)
return;
ui_mode_ = ui_mode;
}
void AmbientUiModel::NotifyAmbientUiVisibilityChanged() { void AmbientUiModel::NotifyAmbientUiVisibilityChanged() {
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnAmbientUiVisibilityChanged(ui_visibility_); observer.OnAmbientUiVisibilityChanged(ui_visibility_);
...@@ -61,19 +68,4 @@ std::ostream& operator<<(std::ostream& out, AmbientUiMode mode) { ...@@ -61,19 +68,4 @@ std::ostream& operator<<(std::ostream& out, AmbientUiMode mode) {
return out; return out;
} }
std::ostream& operator<<(std::ostream& out, AmbientUiVisibility visibility) {
switch (visibility) {
case AmbientUiVisibility::kShown:
out << "kShown";
break;
case AmbientUiVisibility::kHidden:
out << "kHidden";
break;
case AmbientUiVisibility::kClosed:
out << "kClosed";
break;
}
return out;
}
} // namespace ash } // namespace ash
...@@ -51,12 +51,18 @@ class ASH_PUBLIC_EXPORT AmbientUiModel { ...@@ -51,12 +51,18 @@ class ASH_PUBLIC_EXPORT AmbientUiModel {
// Updates current UI visibility and notifies all subscribers. // Updates current UI visibility and notifies all subscribers.
void SetUiVisibility(AmbientUiVisibility visibility); void SetUiVisibility(AmbientUiVisibility visibility);
// Updates current UI mode.
void SetUiMode(AmbientUiMode ui_mode);
AmbientUiVisibility ui_visibility() const { return ui_visibility_; } AmbientUiVisibility ui_visibility() const { return ui_visibility_; }
AmbientUiMode ui_mode() const { return ui_mode_; }
private: private:
void NotifyAmbientUiVisibilityChanged(); void NotifyAmbientUiVisibilityChanged();
AmbientUiVisibility ui_visibility_ = AmbientUiVisibility::kClosed; AmbientUiVisibility ui_visibility_ = AmbientUiVisibility::kClosed;
AmbientUiMode ui_mode_ = AmbientUiMode::kLockScreenUi;
base::ObserverList<AmbientUiModelObserver> observers_; base::ObserverList<AmbientUiModelObserver> observers_;
}; };
...@@ -64,9 +70,6 @@ class ASH_PUBLIC_EXPORT AmbientUiModel { ...@@ -64,9 +70,6 @@ class ASH_PUBLIC_EXPORT AmbientUiModel {
ASH_PUBLIC_EXPORT std::ostream& operator<<(std::ostream& out, ASH_PUBLIC_EXPORT std::ostream& operator<<(std::ostream& out,
AmbientUiMode mode); AmbientUiMode mode);
ASH_PUBLIC_EXPORT std::ostream& operator<<(std::ostream& out,
AmbientUiVisibility visibility);
} // namespace ash } // namespace ash
#endif // ASH_PUBLIC_CPP_AMBIENT_AMBIENT_UI_MODEL_H_ #endif // ASH_PUBLIC_CPP_AMBIENT_AMBIENT_UI_MODEL_H_
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