Commit e3e264e1 authored by Abhishek Bhardwaj's avatar Abhishek Bhardwaj Committed by Commit Bot

DeviceScheduledUpdateChecker: Fix bug in wake lock request

This change fixes a bug in ScopedWakeLock that didn't actually make the
call to acquire a wake lock when constructed. Also adds a test to catch
this case.

BUG=924762
TEST=Unit tests.

Change-Id: Ife26d3b9ae88f399adc21cd8cb62ba628929094b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1757461
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691034}
parent f96048c9
...@@ -597,15 +597,14 @@ class DeviceScheduledUpdateCheckerTest : public testing::Test { ...@@ -597,15 +597,14 @@ class DeviceScheduledUpdateCheckerTest : public testing::Test {
chromeos::ScopedTestingCrosSettings cros_settings_; chromeos::ScopedTestingCrosSettings cros_settings_;
chromeos::FakeUpdateEngineClient* fake_update_engine_client_; chromeos::FakeUpdateEngineClient* fake_update_engine_client_;
std::unique_ptr<chromeos::NetworkStateTestHelper> network_state_test_helper_; std::unique_ptr<chromeos::NetworkStateTestHelper> network_state_test_helper_;
service_manager::TestConnectorFactory connector_factory_;
device::TestWakeLockProvider wake_lock_provider_;
private: private:
chromeos::ScopedStubInstallAttributes test_install_attributes_{ chromeos::ScopedStubInstallAttributes test_install_attributes_{
chromeos::StubInstallAttributes::CreateCloudManaged("fake-domain", chromeos::StubInstallAttributes::CreateCloudManaged("fake-domain",
"fake-id")}; "fake-id")};
service_manager::TestConnectorFactory connector_factory_;
device::TestWakeLockProvider wake_lock_provider_;
DISALLOW_COPY_AND_ASSIGN(DeviceScheduledUpdateCheckerTest); DISALLOW_COPY_AND_ASSIGN(DeviceScheduledUpdateCheckerTest);
}; };
...@@ -1179,4 +1178,44 @@ TEST_F(DeviceScheduledUpdateCheckerTest, CheckNoNetworkDelayScenario) { ...@@ -1179,4 +1178,44 @@ TEST_F(DeviceScheduledUpdateCheckerTest, CheckNoNetworkDelayScenario) {
expected_update_check_completions)); expected_update_check_completions));
} }
// Checks if only one wake lock is acquired when the update check timer fires
// and released when an update check and policy refresh is completed.
TEST_F(DeviceScheduledUpdateCheckerTest, CheckWakeLockAcquireAndRelease) {
base::TimeDelta delay_from_now = base::TimeDelta::FromHours(1);
auto policy_and_next_update_check_time = CreatePolicy(
delay_from_now, DeviceScheduledUpdateChecker::Frequency::kDaily);
// Fast forward to update check timer expiration. This should result in a wake
// lock being acquired.
cros_settings_.device_settings()->Set(
chromeos::kDeviceScheduledUpdateCheck,
std::move(policy_and_next_update_check_time.first));
task_environment_.FastForwardBy(delay_from_now);
base::Optional<int> active_wake_locks_before_update_check;
wake_lock_provider_.GetActiveWakeLocksForTests(
device::mojom::WakeLockType::kPreventAppSuspension,
base::BindOnce([](base::Optional<int>* result,
int32_t wake_lock_count) { *result = wake_lock_count; },
&active_wake_locks_before_update_check));
EXPECT_TRUE(active_wake_locks_before_update_check);
EXPECT_EQ(active_wake_locks_before_update_check.value(), 1);
// Run until idle to run the wake lock count callback.
task_environment_.RunUntilIdle();
// Simulate update check succeeding.
NotifyUpdateCheckStatus(chromeos::UpdateEngineClient::UpdateStatusOperation::
UPDATE_STATUS_UPDATED_NEED_REBOOT);
base::Optional<int> active_wake_locks_after_update_check;
wake_lock_provider_.GetActiveWakeLocksForTests(
device::mojom::WakeLockType::kPreventAppSuspension,
base::BindOnce([](base::Optional<int>* result,
int32_t wake_lock_count) { *result = wake_lock_count; },
&active_wake_locks_after_update_check));
// After all steps are completed the wake lock should be released.
EXPECT_TRUE(active_wake_locks_after_update_check);
EXPECT_EQ(active_wake_locks_after_update_check.value(), 0);
}
} // namespace policy } // namespace policy
...@@ -21,6 +21,7 @@ ScopedWakeLock::ScopedWakeLock(service_manager::Connector* connector, ...@@ -21,6 +21,7 @@ ScopedWakeLock::ScopedWakeLock(service_manager::Connector* connector,
reason, mojo::MakeRequest(&wake_lock_)); reason, mojo::MakeRequest(&wake_lock_));
// This would violate |GetWakeLockWithoutContext|'s API contract. // This would violate |GetWakeLockWithoutContext|'s API contract.
DCHECK(wake_lock_); DCHECK(wake_lock_);
wake_lock_->RequestWakeLock();
} }
ScopedWakeLock::~ScopedWakeLock() { ScopedWakeLock::~ScopedWakeLock() {
......
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