Commit e339860a authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

Pass UsbPowerShare prefs to ChromeOS

Subscribe on UsbPowerShare local state prefs and pass it to ChromeOS side.

BUG=b:130014793
TEST=chromeos_unittests && ash_unittests

Change-Id: I6cf3f65923693206b3c004078e7ada74153a27fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1569015
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653251}
parent 50b6342d
...@@ -361,15 +361,18 @@ const char kAssistantNumWarmerWelcomeTriggered[] = ...@@ -361,15 +361,18 @@ const char kAssistantNumWarmerWelcomeTriggered[] =
const char kVpnConfigAllowed[] = "vpn_config_allowed"; const char kVpnConfigAllowed[] = "vpn_config_allowed";
// A boolean pref that indicates whether power peak shift is enabled. // A boolean pref that indicates whether power peak shift is enabled.
// Ignored unless powerd is configured to honor charging-related prefs.
const char kPowerPeakShiftEnabled[] = "ash.power.peak_shift_enabled"; const char kPowerPeakShiftEnabled[] = "ash.power.peak_shift_enabled";
// An integer pref that specifies the power peak shift battery threshold in // An integer pref that specifies the power peak shift battery threshold in
// percent. // percent.
// Ignored unless powerd is configured to honor charging-related prefs.
const char kPowerPeakShiftBatteryThreshold[] = const char kPowerPeakShiftBatteryThreshold[] =
"ash.power.peak_shift_battery_threshold"; "ash.power.peak_shift_battery_threshold";
// A dictionary pref that specifies the power peak shift day configs. // A dictionary pref that specifies the power peak shift day configs.
// For details see "DevicePowerPeakShiftDayConfig" in policy_templates.json. // For details see "DevicePowerPeakShiftDayConfig" in policy_templates.json.
// Ignored unless powerd is configured to honor charging-related prefs.
const char kPowerPeakShiftDayConfig[] = "ash.power.peak_shift_day_config"; const char kPowerPeakShiftDayConfig[] = "ash.power.peak_shift_day_config";
// A boolean pref that indicates whether boot on AC is enabled. // A boolean pref that indicates whether boot on AC is enabled.
...@@ -377,23 +380,27 @@ const char kBootOnAcEnabled[] = "ash.power.boot_on_ac_enabled"; ...@@ -377,23 +380,27 @@ const char kBootOnAcEnabled[] = "ash.power.boot_on_ac_enabled";
// A boolean pref that indicates whether advanced battery charge mode is // A boolean pref that indicates whether advanced battery charge mode is
// enabled. // enabled.
// Ignored unless powerd is configured to honor charging-related prefs.
const char kAdvancedBatteryChargeModeEnabled[] = const char kAdvancedBatteryChargeModeEnabled[] =
"ash.power.advanced_battery_charge_mode_enabled"; "ash.power.advanced_battery_charge_mode_enabled";
// A dictionary pref that specifies the advanced battery charge mode day config. // A dictionary pref that specifies the advanced battery charge mode day config.
// For details see "DeviceAdvancedBatteryChargeModeDayConfig" in // For details see "DeviceAdvancedBatteryChargeModeDayConfig" in
// policy_templates.json. // policy_templates.json.
// Ignored unless powerd is configured to honor charging-related prefs.
const char kAdvancedBatteryChargeModeDayConfig[] = const char kAdvancedBatteryChargeModeDayConfig[] =
"ash.power.advanced_battery_charge_mode_day_config"; "ash.power.advanced_battery_charge_mode_day_config";
// An integer pref that specifies the battery charge mode. // An integer pref that specifies the battery charge mode.
// For details see "DeviceBatteryChargeMode" in policy_templates.json. // For details see "DeviceBatteryChargeMode" in policy_templates.json.
// Ignored unless powerd is configured to honor charging-related prefs.
const char kBatteryChargeMode[] = "ash.power.battery_charge_mode"; const char kBatteryChargeMode[] = "ash.power.battery_charge_mode";
// An integer pref that specifies the battery charge custom start charging in // An integer pref that specifies the battery charge custom start charging in
// percent. // percent.
// For details see "DeviceBatteryChargeCustomStartCharging" in // For details see "DeviceBatteryChargeCustomStartCharging" in
// policy_templates.json. // policy_templates.json.
// Ignored unless powerd is configured to honor charging-related prefs.
const char kBatteryChargeCustomStartCharging[] = const char kBatteryChargeCustomStartCharging[] =
"ash.power.battery_charge_custom_start_charging"; "ash.power.battery_charge_custom_start_charging";
...@@ -401,11 +408,13 @@ const char kBatteryChargeCustomStartCharging[] = ...@@ -401,11 +408,13 @@ const char kBatteryChargeCustomStartCharging[] =
// percent. // percent.
// For details see "DeviceBatteryChargeCustomStopCharging" in // For details see "DeviceBatteryChargeCustomStopCharging" in
// policy_templates.json. // policy_templates.json.
// Ignored unless powerd is configured to honor charging-related prefs.
const char kBatteryChargeCustomStopCharging[] = const char kBatteryChargeCustomStopCharging[] =
"ash.power.battery_charge_custom_stop_charging"; "ash.power.battery_charge_custom_stop_charging";
// A boolean pref that indicates whether USB power share is enabled. // A boolean pref that indicates whether USB power share is enabled.
// For details see "DeviceUsbPowerShareEnabled" in policy_templates.json. // For details see "DeviceUsbPowerShareEnabled" in policy_templates.json.
// Ignored unless powerd is configured to honor charging-related prefs.
const char kUsbPowerShareEnabled[] = "ash.power.usb_power_share_enabled"; const char kUsbPowerShareEnabled[] = "ash.power.usb_power_share_enabled";
// NOTE: New prefs should start with the "ash." prefix. Existing prefs moved // NOTE: New prefs should start with the "ash." prefix. Existing prefs moved
......
...@@ -435,6 +435,11 @@ void PowerPrefs::UpdatePowerPolicyFromPrefs() { ...@@ -435,6 +435,11 @@ void PowerPrefs::UpdatePowerPolicyFromPrefs() {
values.boot_on_ac = local_state_->GetBoolean(prefs::kBootOnAcEnabled); values.boot_on_ac = local_state_->GetBoolean(prefs::kBootOnAcEnabled);
} }
if (local_state_->IsManagedPreference(prefs::kUsbPowerShareEnabled)) {
values.usb_power_share =
local_state_->GetBoolean(prefs::kUsbPowerShareEnabled);
}
power_policy_controller_->ApplyPrefs(values); power_policy_controller_->ApplyPrefs(values);
} }
...@@ -503,6 +508,8 @@ void PowerPrefs::ObserveLocalStatePrefs(PrefService* prefs) { ...@@ -503,6 +508,8 @@ void PowerPrefs::ObserveLocalStatePrefs(PrefService* prefs) {
local_state_registrar_->Add(prefs::kBootOnAcEnabled, update_callback); local_state_registrar_->Add(prefs::kBootOnAcEnabled, update_callback);
local_state_registrar_->Add(prefs::kUsbPowerShareEnabled, update_callback);
UpdatePowerPolicyFromPrefs(); UpdatePowerPolicyFromPrefs();
} }
......
...@@ -113,7 +113,11 @@ std::string GetExpectedPowerPolicyForPrefs(PrefService* prefs, ...@@ -113,7 +113,11 @@ std::string GetExpectedPowerPolicyForPrefs(PrefService* prefs,
prefs->GetBoolean(prefs::kPowerWaitForInitialUserActivity)); prefs->GetBoolean(prefs::kPowerWaitForInitialUserActivity));
expected_policy.set_force_nonzero_brightness_for_user_activity( expected_policy.set_force_nonzero_brightness_for_user_activity(
prefs->GetBoolean(prefs::kPowerForceNonzeroBrightnessForUserActivity)); prefs->GetBoolean(prefs::kPowerForceNonzeroBrightnessForUserActivity));
// Device-level prefs do not exist in the user-level |prefs|.
expected_policy.set_boot_on_ac(false); expected_policy.set_boot_on_ac(false);
expected_policy.set_usb_power_share(true);
expected_policy.set_reason("Prefs"); expected_policy.set_reason("Prefs");
return chromeos::PowerPolicyController::GetPolicyDebugString(expected_policy); return chromeos::PowerPolicyController::GetPolicyDebugString(expected_policy);
} }
...@@ -420,4 +424,12 @@ TEST_F(PowerPrefsTest, BootOnAc) { ...@@ -420,4 +424,12 @@ TEST_F(PowerPrefsTest, BootOnAc) {
EXPECT_FALSE(power_manager_client()->policy().boot_on_ac()); EXPECT_FALSE(power_manager_client()->policy().boot_on_ac());
} }
TEST_F(PowerPrefsTest, UsbPowerShare) {
managed_pref_store_->SetBoolean(prefs::kUsbPowerShareEnabled, true);
EXPECT_TRUE(power_manager_client()->policy().usb_power_share());
managed_pref_store_->SetBoolean(prefs::kUsbPowerShareEnabled, false);
EXPECT_FALSE(power_manager_client()->policy().usb_power_share());
}
} // namespace ash } // namespace ash
...@@ -198,6 +198,10 @@ std::string PowerPolicyController::GetPolicyDebugString( ...@@ -198,6 +198,10 @@ std::string PowerPolicyController::GetPolicyDebugString(
StringAppendF(&str, "boot_on_ac=%d ", policy.boot_on_ac()); StringAppendF(&str, "boot_on_ac=%d ", policy.boot_on_ac());
} }
if (policy.has_usb_power_share()) {
StringAppendF(&str, "usb_power_share=%d ", policy.usb_power_share());
}
if (policy.has_reason()) if (policy.has_reason())
StringAppendF(&str, "reason=\"%s\" ", policy.reason().c_str()); StringAppendF(&str, "reason=\"%s\" ", policy.reason().c_str());
base::TrimWhitespaceASCII(str, base::TRIM_TRAILING, &str); base::TrimWhitespaceASCII(str, base::TRIM_TRAILING, &str);
...@@ -340,6 +344,8 @@ void PowerPolicyController::ApplyPrefs(const PrefValues& values) { ...@@ -340,6 +344,8 @@ void PowerPolicyController::ApplyPrefs(const PrefValues& values) {
prefs_policy_.set_boot_on_ac(values.boot_on_ac); prefs_policy_.set_boot_on_ac(values.boot_on_ac);
prefs_policy_.set_usb_power_share(values.usb_power_share);
prefs_were_set_ = true; prefs_were_set_ = true;
SendCurrentPolicy(); SendCurrentPolicy();
} }
......
...@@ -113,6 +113,7 @@ class COMPONENT_EXPORT(DBUS_POWER) PowerPolicyController ...@@ -113,6 +113,7 @@ class COMPONENT_EXPORT(DBUS_POWER) PowerPolicyController
int peak_shift_battery_threshold = -1; int peak_shift_battery_threshold = -1;
std::vector<PeakShiftDayConfiguration> peak_shift_day_configurations; std::vector<PeakShiftDayConfiguration> peak_shift_day_configurations;
bool boot_on_ac = false; bool boot_on_ac = false;
bool usb_power_share = true;
}; };
// Returns a string describing |policy|. Useful for tests. // Returns a string describing |policy|. Useful for tests.
......
...@@ -65,6 +65,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { ...@@ -65,6 +65,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
prefs.wait_for_initial_user_activity = true; prefs.wait_for_initial_user_activity = true;
prefs.force_nonzero_brightness_for_user_activity = false; prefs.force_nonzero_brightness_for_user_activity = false;
prefs.boot_on_ac = true; prefs.boot_on_ac = true;
prefs.usb_power_share = false;
policy_controller_->ApplyPrefs(prefs); policy_controller_->ApplyPrefs(prefs);
power_manager::PowerManagementPolicy expected_policy; power_manager::PowerManagementPolicy expected_policy;
...@@ -93,6 +94,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { ...@@ -93,6 +94,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.set_wait_for_initial_user_activity(true); expected_policy.set_wait_for_initial_user_activity(true);
expected_policy.set_force_nonzero_brightness_for_user_activity(false); expected_policy.set_force_nonzero_brightness_for_user_activity(false);
expected_policy.set_boot_on_ac(true); expected_policy.set_boot_on_ac(true);
expected_policy.set_usb_power_share(false);
expected_policy.set_reason(PowerPolicyController::kPrefsReason); expected_policy.set_reason(PowerPolicyController::kPrefsReason);
EXPECT_EQ( EXPECT_EQ(
PowerPolicyController::GetPolicyDebugString(expected_policy), PowerPolicyController::GetPolicyDebugString(expected_policy),
......
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