Commit c874c018 authored by Saurabh Nijhara's avatar Saurabh Nijhara Committed by Commit Bot

Use BuildState::UpdateType instead of installed_version

BuildState::installed_version() returns the platform version instead of
the browser version number. So, using BuildState::UpdateType to make
sure that the current update is not a rollback.

Bug: 1048607
Change-Id: I726548db6df944f5176b766dacd65fba33a5f1af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2237889Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Saurabh Nijhara <snijhara@google.com>
Cr-Commit-Position: refs/heads/master@{#778999}
parent a965ea59
...@@ -63,6 +63,10 @@ std::string GetEnterpriseDomainName() { ...@@ -63,6 +63,10 @@ std::string GetEnterpriseDomainName() {
->GetEnterpriseDisplayDomain(); ->GetEnterpriseDisplayDomain();
} }
BuildState* GetBuildState() {
return g_browser_process->GetBuildState();
}
} // namespace } // namespace
const char MinimumVersionPolicyHandler::kChromeVersion[] = "chrome_version"; const char MinimumVersionPolicyHandler::kChromeVersion[] = "chrome_version";
...@@ -125,7 +129,7 @@ MinimumVersionPolicyHandler::MinimumVersionPolicyHandler( ...@@ -125,7 +129,7 @@ MinimumVersionPolicyHandler::MinimumVersionPolicyHandler(
} }
MinimumVersionPolicyHandler::~MinimumVersionPolicyHandler() { MinimumVersionPolicyHandler::~MinimumVersionPolicyHandler() {
g_browser_process->GetBuildState()->RemoveObserver(this); GetBuildState()->RemoveObserver(this);
StopObservingNetwork(); StopObservingNetwork();
} }
...@@ -216,9 +220,11 @@ void MinimumVersionPolicyHandler::OnPolicyChanged() { ...@@ -216,9 +220,11 @@ void MinimumVersionPolicyHandler::OnPolicyChanged() {
requirements_met_ = false; requirements_met_ = false;
FetchEolInfo(); FetchEolInfo();
} }
} else if (state_) { } else {
// Update is not required as the requirements of all of the configs in the // Update is not required as the requirements of all of the configs in the
// policy are satisfied by the current chrome version. // policy are satisfied by the current chrome version. We could also reach
// here at the time of login if the device was rebooted to apply the
// downloaded update, in which case it is needed to reset the local state.
HandleUpdateNotRequired(); HandleUpdateNotRequired();
} }
} }
...@@ -239,7 +245,7 @@ void MinimumVersionPolicyHandler::Reset() { ...@@ -239,7 +245,7 @@ void MinimumVersionPolicyHandler::Reset() {
eol_reached_ = false; eol_reached_ = false;
update_required_deadline_timer_.Stop(); update_required_deadline_timer_.Stop();
notification_timer_.Stop(); notification_timer_.Stop();
g_browser_process->GetBuildState()->RemoveObserver(this); GetBuildState()->RemoveObserver(this);
state_.reset(); state_.reset();
HideNotification(); HideNotification();
notification_handler_.reset(); notification_handler_.reset();
...@@ -247,6 +253,14 @@ void MinimumVersionPolicyHandler::Reset() { ...@@ -247,6 +253,14 @@ void MinimumVersionPolicyHandler::Reset() {
StopObservingNetwork(); StopObservingNetwork();
} }
void MinimumVersionPolicyHandler::ResetOnUpdateCompleted() {
update_required_deadline_timer_.Stop();
notification_timer_.Stop();
GetBuildState()->RemoveObserver(this);
HideNotification();
notification_handler_.reset();
}
void MinimumVersionPolicyHandler::FetchEolInfo() { void MinimumVersionPolicyHandler::FetchEolInfo() {
// Return if update required state is null meaning all requirements are // Return if update required state is null meaning all requirements are
// satisfied. // satisfied.
...@@ -329,6 +343,14 @@ void MinimumVersionPolicyHandler::HandleUpdateRequired( ...@@ -329,6 +343,14 @@ void MinimumVersionPolicyHandler::HandleUpdateRequired(
if (deadline > previous_deadline) if (deadline > previous_deadline)
UpdateLocalState(warning_time); UpdateLocalState(warning_time);
// The device has already downloaded the update in-session and waiting for
// reboot to apply it.
if (GetBuildState()->update_type() == BuildState::UpdateType::kNormalUpdate) {
// TODO(https://crbug.com/1048607): May be adjust relaunch notification
// timer as per new deadline.
return;
}
StartDeadlineTimer(deadline); StartDeadlineTimer(deadline);
if (!eol_reached_) if (!eol_reached_)
StartObservingUpdate(); StartObservingUpdate();
...@@ -363,7 +385,7 @@ void MinimumVersionPolicyHandler::StartDeadlineTimer(base::Time deadline) { ...@@ -363,7 +385,7 @@ void MinimumVersionPolicyHandler::StartDeadlineTimer(base::Time deadline) {
} }
void MinimumVersionPolicyHandler::StartObservingUpdate() { void MinimumVersionPolicyHandler::StartObservingUpdate() {
auto* build_state = g_browser_process->GetBuildState(); auto* build_state = GetBuildState();
if (!build_state->HasObserver(this)) if (!build_state->HasObserver(this))
build_state->AddObserver(this); build_state->AddObserver(this);
} }
...@@ -432,10 +454,10 @@ void MinimumVersionPolicyHandler::ShowAndScheduleNotification( ...@@ -432,10 +454,10 @@ void MinimumVersionPolicyHandler::ShowAndScheduleNotification(
} }
void MinimumVersionPolicyHandler::OnUpdate(const BuildState* build_state) { void MinimumVersionPolicyHandler::OnUpdate(const BuildState* build_state) {
// Reset the state if new version is greater or equal the required version. // If the device has been successfully updated, the relaunch notifications
// Hide update required screen if it is shown. // will reboot it for applying the updates.
if (build_state->installed_version()->CompareTo(state_->version()) >= 0) if (build_state->update_type() == BuildState::UpdateType::kNormalUpdate)
HandleUpdateNotRequired(); ResetOnUpdateCompleted();
} }
void MinimumVersionPolicyHandler::HideNotification() const { void MinimumVersionPolicyHandler::HideNotification() const {
...@@ -453,6 +475,8 @@ void MinimumVersionPolicyHandler::DefaultNetworkChanged( ...@@ -453,6 +475,8 @@ void MinimumVersionPolicyHandler::DefaultNetworkChanged(
} }
void MinimumVersionPolicyHandler::StopObservingNetwork() { void MinimumVersionPolicyHandler::StopObservingNetwork() {
if (!chromeos::NetworkHandler::IsInitialized())
return;
chromeos::NetworkStateHandler* network_state_handler = chromeos::NetworkStateHandler* network_state_handler =
chromeos::NetworkHandler::Get()->network_state_handler(); chromeos::NetworkHandler::Get()->network_state_handler();
network_state_handler->RemoveObserver(this, FROM_HERE); network_state_handler->RemoveObserver(this, FROM_HERE);
......
...@@ -160,6 +160,10 @@ class MinimumVersionPolicyHandler ...@@ -160,6 +160,10 @@ class MinimumVersionPolicyHandler
bool IsPolicyApplicable(); bool IsPolicyApplicable();
void Reset(); void Reset();
// Handles post update completed actions like reset timers, hide update
// required notification and stop observing build state.
void ResetOnUpdateCompleted();
// Handles the state when update is required as per the policy. If on the // Handles the state when update is required as per the policy. If on the
// login screen, update required screen is shown, else the user is logged out // login screen, update required screen is shown, else the user is logged out
// if the device is not updated within the given |warning_time|. The // if the device is not updated within the given |warning_time|. The
......
...@@ -57,10 +57,13 @@ const char kNewVersion[] = "99999.4.2"; ...@@ -57,10 +57,13 @@ const char kNewVersion[] = "99999.4.2";
const int kNoWarning = 0; const int kNoWarning = 0;
const int kShortWarningInDays = 2; const int kShortWarningInDays = 2;
const int kLongWarningInDays = 10; const int kLongWarningInDays = 10;
const int kVeryLongWarningInDays = 100;
constexpr base::TimeDelta kShortWarning = constexpr base::TimeDelta kShortWarning =
base::TimeDelta::FromDays(kShortWarningInDays); base::TimeDelta::FromDays(kShortWarningInDays);
constexpr base::TimeDelta kLongWarning = constexpr base::TimeDelta kLongWarning =
base::TimeDelta::FromDays(kLongWarningInDays); base::TimeDelta::FromDays(kLongWarningInDays);
constexpr base::TimeDelta kVeryLongWarning =
base::TimeDelta::FromDays(kVeryLongWarningInDays);
const char kPublicSessionId[] = "demo@example.com"; const char kPublicSessionId[] = "demo@example.com";
const char kUpdateRequiredNotificationId[] = "policy.update_required"; const char kUpdateRequiredNotificationId[] = "policy.update_required";
const char kWifiServicePath[] = "/service/wifi2"; const char kWifiServicePath[] = "/service/wifi2";
...@@ -263,7 +266,7 @@ IN_PROC_BROWSER_TEST_F(MinimumVersionPolicyTest, CriticalUpdateInSession) { ...@@ -263,7 +266,7 @@ IN_PROC_BROWSER_TEST_F(MinimumVersionPolicyTest, CriticalUpdateInSession) {
} }
IN_PROC_BROWSER_TEST_F(MinimumVersionPolicyTest, NonCriticalUpdateGoodNetwork) { IN_PROC_BROWSER_TEST_F(MinimumVersionPolicyTest, NonCriticalUpdateGoodNetwork) {
// Login the user into the session and mark as managed. // Login the user into the session.
Login(); Login();
// Check deadline timer is not running and local state is not set. // Check deadline timer is not running and local state is not set.
...@@ -323,17 +326,81 @@ IN_PROC_BROWSER_TEST_F(MinimumVersionPolicyTest, NonCriticalUpdateGoodNetwork) { ...@@ -323,17 +326,81 @@ IN_PROC_BROWSER_TEST_F(MinimumVersionPolicyTest, NonCriticalUpdateGoodNetwork) {
EXPECT_TRUE(GetMinimumVersionPolicyHandler()->GetState()); EXPECT_TRUE(GetMinimumVersionPolicyHandler()->GetState());
// Simulate update installed from update_engine_client and check that timer // Simulate update installed from update_engine_client and check that timer
// and the local state is reset. // is reset but local state is not.
update_engine::StatusResult status; update_engine::StatusResult status;
status.set_current_operation(update_engine::Operation::UPDATED_NEED_REBOOT); status.set_current_operation(update_engine::Operation::UPDATED_NEED_REBOOT);
status.set_new_version("99999.9"); status.set_new_version("99999.9");
fake_update_engine_client_->set_default_status(status); fake_update_engine_client_->set_default_status(status);
fake_update_engine_client_->NotifyObserversThatStatusChanged(status); fake_update_engine_client_->NotifyObserversThatStatusChanged(status);
EXPECT_FALSE(
GetMinimumVersionPolicyHandler()->IsDeadlineTimerRunningForTesting());
EXPECT_TRUE(GetMinimumVersionPolicyHandler()->GetState());
EXPECT_FALSE(prefs->GetTime(prefs::kUpdateRequiredTimerStartTime).is_null());
// New policy after update is downloaded does not restart the timer but just
// updates the local state with longer warning period.
base::Value requirement_very_long_warning(base::Value::Type::LIST);
requirement_very_long_warning.Append(
CreateRequirement(kNewVersion, kVeryLongWarningInDays, kNoWarning));
SetDevicePolicyAndWaitForSettingChange(requirement_very_long_warning);
EXPECT_EQ(prefs->GetTime(prefs::kUpdateRequiredTimerStartTime),
timer_start_time);
EXPECT_EQ(prefs->GetTimeDelta(prefs::kUpdateRequiredWarningPeriod),
kVeryLongWarning);
EXPECT_FALSE(
GetMinimumVersionPolicyHandler()->IsDeadlineTimerRunningForTesting());
EXPECT_TRUE(GetMinimumVersionPolicyHandler()->GetState());
}
IN_PROC_BROWSER_TEST_F(MinimumVersionPolicyTest, DeviceUpdateStatusChange) {
// Login the user into the session.
Login();
// Create and set policy value with warning time.
base::Value requirement_short_warning(base::Value::Type::LIST);
requirement_short_warning.Append(
CreateRequirement(kNewVersion, kShortWarningInDays, kShortWarningInDays));
SetDevicePolicyAndWaitForSettingChange(requirement_short_warning);
// Policy handler starts the deadline timer.
EXPECT_TRUE(
GetMinimumVersionPolicyHandler()->IsDeadlineTimerRunningForTesting());
EXPECT_TRUE(GetMinimumVersionPolicyHandler()->GetState());
// Simulate channel switch rollback from update_engine_client and check that
// timer is not reset.
update_engine::StatusResult rollback_status;
rollback_status.set_current_operation(
update_engine::Operation::UPDATED_NEED_REBOOT);
rollback_status.set_will_powerwash_after_reboot(true);
fake_update_engine_client_->set_default_status(rollback_status);
fake_update_engine_client_->NotifyObserversThatStatusChanged(rollback_status);
EXPECT_TRUE(
GetMinimumVersionPolicyHandler()->IsDeadlineTimerRunningForTesting());
EXPECT_TRUE(GetMinimumVersionPolicyHandler()->GetState());
// Simulate enterprise rollback from update_engine_client and check that timer
// is not reset.
rollback_status.set_is_enterprise_rollback(true);
fake_update_engine_client_->set_default_status(rollback_status);
fake_update_engine_client_->NotifyObserversThatStatusChanged(rollback_status);
EXPECT_TRUE(
GetMinimumVersionPolicyHandler()->IsDeadlineTimerRunningForTesting());
EXPECT_TRUE(GetMinimumVersionPolicyHandler()->GetState());
// Simulate update installed from update_engine_client and check that timer is
// reset.
update_engine::StatusResult update_status;
update_status.set_current_operation(
update_engine::Operation::UPDATED_NEED_REBOOT);
fake_update_engine_client_->set_default_status(update_status);
fake_update_engine_client_->NotifyObserversThatStatusChanged(update_status);
EXPECT_FALSE( EXPECT_FALSE(
GetMinimumVersionPolicyHandler()->IsDeadlineTimerRunningForTesting()); GetMinimumVersionPolicyHandler()->IsDeadlineTimerRunningForTesting());
EXPECT_FALSE(GetMinimumVersionPolicyHandler()->GetState()); EXPECT_TRUE(GetMinimumVersionPolicyHandler()->GetState());
EXPECT_TRUE(prefs->GetTime(prefs::kUpdateRequiredTimerStartTime).is_null());
} }
IN_PROC_BROWSER_TEST_F(MinimumVersionPolicyTest, IN_PROC_BROWSER_TEST_F(MinimumVersionPolicyTest,
......
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