summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorejcaruso <ejcaruso@chromium.org>2015-12-04 08:44:21 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-04 16:45:49 +0000
commit8b2f573f0a506765a54b5d648ac2e8da7ad1266c (patch)
tree5d33262ca317237de3364add102064bdd0d430fa /chromeos
parentf22656aca1120584c3fb96580def7833c3cdd170 (diff)
downloadchromium_src-8b2f573f0a506765a54b5d648ac2e8da7ad1266c.zip
chromium_src-8b2f573f0a506765a54b5d648ac2e8da7ad1266c.tar.gz
chromium_src-8b2f573f0a506765a54b5d648ac2e8da7ad1266c.tar.bz2
power: Add dim wake locks
ARC uses dim wake locks to prevent the screen from turning off but not from dimming, so we should support those in the PowerPolicyController to prepare for removal of this functionality from powerd. BUG=b:24671115 TEST=use dim wake lock, check powerd logs for updated policy, new unittests Review URL: https://codereview.chromium.org/1500853002 Cr-Commit-Position: refs/heads/master@{#363230}
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/dbus/power_policy_controller.cc18
-rw-r--r--chromeos/dbus/power_policy_controller.h19
-rw-r--r--chromeos/dbus/power_policy_controller_unittest.cc112
3 files changed, 119 insertions, 30 deletions
diff --git a/chromeos/dbus/power_policy_controller.cc b/chromeos/dbus/power_policy_controller.cc
index e934275..336b72e 100644
--- a/chromeos/dbus/power_policy_controller.cc
+++ b/chromeos/dbus/power_policy_controller.cc
@@ -246,6 +246,11 @@ int PowerPolicyController::AddScreenWakeLock(WakeLockReason reason,
return AddWakeLockInternal(WakeLock::TYPE_SCREEN, reason, description);
}
+int PowerPolicyController::AddDimWakeLock(WakeLockReason reason,
+ const std::string& description) {
+ return AddWakeLockInternal(WakeLock::TYPE_DIM, reason, description);
+}
+
int PowerPolicyController::AddSystemWakeLock(WakeLockReason reason,
const std::string& description) {
return AddWakeLockInternal(WakeLock::TYPE_SYSTEM, reason, description);
@@ -301,6 +306,7 @@ void PowerPolicyController::SendCurrentPolicy() {
causes = kPrefsReason;
bool have_screen_wake_locks = false;
+ bool have_dim_wake_locks = false;
bool have_system_wake_locks = false;
for (const auto& it : wake_locks_) {
// Skip audio and video locks that should be ignored due to policy.
@@ -312,6 +318,9 @@ void PowerPolicyController::SendCurrentPolicy() {
case WakeLock::TYPE_SCREEN:
have_screen_wake_locks = true;
break;
+ case WakeLock::TYPE_DIM:
+ have_dim_wake_locks = true;
+ break;
case WakeLock::TYPE_SYSTEM:
have_system_wake_locks = true;
break;
@@ -328,7 +337,14 @@ void PowerPolicyController::SendCurrentPolicy() {
policy.mutable_battery_delays()->set_screen_lock_ms(0);
}
- if (have_screen_wake_locks || have_system_wake_locks) {
+ if (honor_screen_wake_locks_ && have_dim_wake_locks) {
+ policy.mutable_ac_delays()->set_screen_off_ms(0);
+ policy.mutable_ac_delays()->set_screen_lock_ms(0);
+ policy.mutable_battery_delays()->set_screen_off_ms(0);
+ policy.mutable_battery_delays()->set_screen_lock_ms(0);
+ }
+
+ if (have_screen_wake_locks || have_dim_wake_locks || have_system_wake_locks) {
if (!policy.has_ac_idle_action() || policy.ac_idle_action() ==
power_manager::PowerManagementPolicy_Action_SUSPEND) {
policy.set_ac_idle_action(
diff --git a/chromeos/dbus/power_policy_controller.h b/chromeos/dbus/power_policy_controller.h
index 5437cd4..ec0ae2e 100644
--- a/chromeos/dbus/power_policy_controller.h
+++ b/chromeos/dbus/power_policy_controller.h
@@ -98,11 +98,13 @@ class CHROMEOS_EXPORT PowerPolicyController
// and sends an updated policy. |description| is a human-readable description
// of the reason the lock was created. Returns a unique ID that can be passed
// to RemoveWakeLock() later.
+ // See the comment above WakeLock::Type for descriptions of the lock types.
int AddScreenWakeLock(WakeLockReason reason, const std::string& description);
+ int AddDimWakeLock(WakeLockReason reason, const std::string& description);
int AddSystemWakeLock(WakeLockReason reason, const std::string& description);
- // Unregisters a request previously created via AddScreenWakeLock() or
- // AddSystemWakeLock() and sends an updated policy.
+ // Unregisters a request previously created via an Add*WakeLock() call
+ // and sends an updated policy.
void RemoveWakeLock(int id);
// PowerManagerClient::Observer implementation:
@@ -114,11 +116,14 @@ class CHROMEOS_EXPORT PowerPolicyController
friend class PowerPrefsTest;
- // Details about a wake lock added via AddScreenWakeLock() or
- // AddSystemWakeLock().
+ // Details about a wake lock added via Add*WakeLock().
+ // SCREEN and DIM will keep the screen on and prevent it from locking.
+ // SCREEN will also prevent it from dimming. SYSTEM will prevent idle
+ // suspends, but the screen will turn off and lock normally.
struct WakeLock {
enum Type {
TYPE_SCREEN,
+ TYPE_DIM,
TYPE_SYSTEM,
};
@@ -153,11 +158,11 @@ class CHROMEOS_EXPORT PowerPolicyController
// to details about the request.
WakeLockMap wake_locks_;
- // Should TYPE_SCREEN entries in |wake_locks_| be honored? If false, screen
- // wake locks are just treated as TYPE_SYSTEM instead.
+ // Should TYPE_SCREEN or TYPE_DIM entries in |wake_locks_| be honored?
+ // If false, screen wake locks are just treated as TYPE_SYSTEM instead.
bool honor_screen_wake_locks_;
- // Next ID to be used by AddScreenWakeLock() or AddSystemWakeLock().
+ // Next ID to be used by an Add*WakeLock() request.
int next_wake_lock_id_;
DISALLOW_COPY_AND_ASSIGN(PowerPolicyController);
diff --git a/chromeos/dbus/power_policy_controller_unittest.cc b/chromeos/dbus/power_policy_controller_unittest.cc
index 3352f21..7c6de2e 100644
--- a/chromeos/dbus/power_policy_controller_unittest.cc
+++ b/chromeos/dbus/power_policy_controller_unittest.cc
@@ -163,43 +163,111 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
}
TEST_F(PowerPolicyControllerTest, WakeLocks) {
+ // If our highest lock type is system, we only worry about
+ // the idle action.
const char kSystemWakeLockReason[] = "system";
- const int system_id = policy_controller_->AddSystemWakeLock(
- PowerPolicyController::REASON_OTHER, kSystemWakeLockReason);
- power_manager::PowerManagementPolicy expected_policy;
- expected_policy.set_ac_idle_action(
+ power_manager::PowerManagementPolicy expected_policy_system;
+ expected_policy_system.set_ac_idle_action(
power_manager::PowerManagementPolicy_Action_DO_NOTHING);
- expected_policy.set_battery_idle_action(
+ expected_policy_system.set_battery_idle_action(
power_manager::PowerManagementPolicy_Action_DO_NOTHING);
- expected_policy.set_reason(kSystemWakeLockReason);
- EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
+
+ // The dim lock type prevents the screen from turning off or
+ // locking, and we won't have an idle action.
+ const char kDimWakeLockReason[] = "dim";
+ power_manager::PowerManagementPolicy expected_policy_dim;
+ expected_policy_dim.set_ac_idle_action(
+ power_manager::PowerManagementPolicy_Action_DO_NOTHING);
+ expected_policy_dim.set_battery_idle_action(
+ power_manager::PowerManagementPolicy_Action_DO_NOTHING);
+ expected_policy_dim.mutable_ac_delays()->set_screen_off_ms(0);
+ expected_policy_dim.mutable_ac_delays()->set_screen_lock_ms(0);
+ expected_policy_dim.mutable_battery_delays()->set_screen_off_ms(0);
+ expected_policy_dim.mutable_battery_delays()->set_screen_lock_ms(0);
+
+ // The screen lock keeps the screen bright. We won't turn off,
+ // lock the screen or do anything for idle.
+ const char kScreenWakeLockReason[] = "screen";
+ power_manager::PowerManagementPolicy expected_policy_screen;
+ expected_policy_screen.set_ac_idle_action(
+ power_manager::PowerManagementPolicy_Action_DO_NOTHING);
+ expected_policy_screen.set_battery_idle_action(
+ power_manager::PowerManagementPolicy_Action_DO_NOTHING);
+ expected_policy_screen.mutable_ac_delays()->set_screen_dim_ms(0);
+ expected_policy_screen.mutable_ac_delays()->set_screen_off_ms(0);
+ expected_policy_screen.mutable_ac_delays()->set_screen_lock_ms(0);
+ expected_policy_screen.mutable_battery_delays()->set_screen_dim_ms(0);
+ expected_policy_screen.mutable_battery_delays()->set_screen_off_ms(0);
+ expected_policy_screen.mutable_battery_delays()->set_screen_lock_ms(0);
+
+ // With no locks our policy should be the default.
+ power_manager::PowerManagementPolicy expected_policy_none;
+
+ // There are eight different possibilities for combinations of
+ // different locks, as there are three types. We will go through
+ // each possibility by adding or removing one lock.
+
+ // System lock only.
+ const int system_id = policy_controller_->AddSystemWakeLock(
+ PowerPolicyController::REASON_OTHER, kSystemWakeLockReason);
+ expected_policy_system.set_reason(kSystemWakeLockReason);
+ EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy_system),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->policy()));
- const char kScreenWakeLockReason[] = "screen";
+ // System and dim locks.
+ const int dim_id = policy_controller_->AddDimWakeLock(
+ PowerPolicyController::REASON_OTHER, kDimWakeLockReason);
+ expected_policy_dim.set_reason(std::string(kSystemWakeLockReason) + ", " +
+ kDimWakeLockReason);
+ EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy_dim),
+ PowerPolicyController::GetPolicyDebugString(
+ fake_power_client_->policy()));
+
+ // Dim lock only.
+ policy_controller_->RemoveWakeLock(system_id);
+ expected_policy_dim.set_reason(kDimWakeLockReason);
+ EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy_dim),
+ PowerPolicyController::GetPolicyDebugString(
+ fake_power_client_->policy()));
+
+ // Dim and screen locks.
const int screen_id = policy_controller_->AddScreenWakeLock(
PowerPolicyController::REASON_OTHER, kScreenWakeLockReason);
- expected_policy.mutable_ac_delays()->set_screen_dim_ms(0);
- expected_policy.mutable_ac_delays()->set_screen_off_ms(0);
- expected_policy.mutable_ac_delays()->set_screen_lock_ms(0);
- expected_policy.mutable_battery_delays()->set_screen_dim_ms(0);
- expected_policy.mutable_battery_delays()->set_screen_off_ms(0);
- expected_policy.mutable_battery_delays()->set_screen_lock_ms(0);
- expected_policy.set_reason(std::string(kSystemWakeLockReason) + ", " +
- kScreenWakeLockReason);
- EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
+ expected_policy_screen.set_reason(std::string(kDimWakeLockReason) + ", " +
+ kScreenWakeLockReason);
+ EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy_screen),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->policy()));
- policy_controller_->RemoveWakeLock(system_id);
- expected_policy.set_reason(kScreenWakeLockReason);
- EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
+ // System, dim and screen locks.
+ const int system_id_2 = policy_controller_->AddSystemWakeLock(
+ PowerPolicyController::REASON_OTHER, kSystemWakeLockReason);
+ expected_policy_screen.set_reason(std::string(kDimWakeLockReason) + ", " +
+ std::string(kScreenWakeLockReason) + ", " +
+ kSystemWakeLockReason);
+ EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy_screen),
+ PowerPolicyController::GetPolicyDebugString(
+ fake_power_client_->policy()));
+
+ // System and screen locks.
+ policy_controller_->RemoveWakeLock(dim_id);
+ expected_policy_screen.set_reason(std::string(kScreenWakeLockReason) + ", " +
+ kSystemWakeLockReason);
+ EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy_screen),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->policy()));
+ // Screen lock only.
+ policy_controller_->RemoveWakeLock(system_id_2);
+ expected_policy_screen.set_reason(kScreenWakeLockReason);
+ EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy_screen),
+ PowerPolicyController::GetPolicyDebugString(
+ fake_power_client_->policy()));
+
+ // No locks.
policy_controller_->RemoveWakeLock(screen_id);
- expected_policy.Clear();
- EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
+ EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy_none),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->policy()));
}