diff options
author | jennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-15 01:40:18 +0000 |
---|---|---|
committer | jennyz@chromium.org <jennyz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-15 01:40:18 +0000 |
commit | f1db3045ca87123cb08848c712980a36e856b0be (patch) | |
tree | 88bc4700c7c9ab060a16c7f42579f53f7cba216f | |
parent | 9d25dce23d95105048d3869e1d3fca26dbcfcf35 (diff) | |
download | chromium_src-f1db3045ca87123cb08848c712980a36e856b0be.zip chromium_src-f1db3045ca87123cb08848c712980a36e856b0be.tar.gz chromium_src-f1db3045ca87123cb08848c712980a36e856b0be.tar.bz2 |
Show battery notification based on percentage for unreliable charging state. Change PowerManagerClient code to fill either battery_seconds_to_full or battery_seconds_to_empty like the real powerd logic.
BUG=239869
TBR=derat
Review URL: https://chromiumcodereview.appspot.com/14864028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200139 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/system/power/tray_power.cc | 48 | ||||
-rw-r--r-- | ash/system/power/tray_power.h | 3 | ||||
-rw-r--r-- | chromeos/dbus/power_manager_client.cc | 15 |
3 files changed, 58 insertions, 8 deletions
diff --git a/ash/system/power/tray_power.cc b/ash/system/power/tray_power.cc index 4d27337..5ec9e3b 100644 --- a/ash/system/power/tray_power.cc +++ b/ash/system/power/tray_power.cc @@ -58,6 +58,10 @@ const int kLowPowerSeconds = 15 * 60; const int kNoWarningSeconds = 30 * 60; // Minimum battery percentage rendered in UI. const int kMinBatteryPercent = 1; +// Notification in battery percentage. +const double kCriticalPercentage = 5.0; +const double kLowPowerPercentage = 10.0; +const double kNoWarningPercentage = 15.0; base::string16 GetBatteryTimeAccessibilityString(int hour, int min) { DCHECK(hour || min); @@ -391,12 +395,21 @@ void TrayPower::OnPowerStatusChanged(const PowerSupplyStatus& status) { bool TrayPower::UpdateNotificationState(const PowerSupplyStatus& status) { if (!status.battery_is_present || status.is_calculating_battery_time || - status.battery_state != PowerSupplyStatus::DISCHARGING) { + status.battery_state == PowerSupplyStatus::CHARGING) { notification_state_ = NOTIFICATION_NONE; return false; } - int remaining_seconds = status.battery_seconds_to_empty; + if (TrayPower::IsBatteryChargingUnreliable(status)) { + return UpdateNotificationStateForRemainingPercentage( + status.battery_percentage); + } else { + return UpdateNotificationStateForRemainingTime( + status.battery_seconds_to_empty); + } +} + +bool TrayPower::UpdateNotificationStateForRemainingTime(int remaining_seconds) { if (remaining_seconds >= kNoWarningSeconds) { notification_state_ = NOTIFICATION_NONE; return false; @@ -425,5 +438,36 @@ bool TrayPower::UpdateNotificationState(const PowerSupplyStatus& status) { return false; } +bool TrayPower::UpdateNotificationStateForRemainingPercentage( + double remaining_percentage) { + if (remaining_percentage > kNoWarningPercentage) { + notification_state_ = NOTIFICATION_NONE; + return false; + } + + switch (notification_state_) { + case NOTIFICATION_NONE: + if (remaining_percentage <= kCriticalPercentage) { + notification_state_ = NOTIFICATION_CRITICAL; + return true; + } + if (remaining_percentage <= kLowPowerPercentage) { + notification_state_ = NOTIFICATION_LOW_POWER; + return true; + } + return false; + case NOTIFICATION_LOW_POWER: + if (remaining_percentage <= kCriticalPercentage) { + notification_state_ = NOTIFICATION_CRITICAL; + return true; + } + return false; + case NOTIFICATION_CRITICAL: + return false; + } + NOTREACHED(); + return false; +} + } // namespace internal } // namespace ash diff --git a/ash/system/power/tray_power.h b/ash/system/power/tray_power.h index 7865b1a..19eaf63 100644 --- a/ash/system/power/tray_power.h +++ b/ash/system/power/tray_power.h @@ -87,6 +87,9 @@ class TrayPower : public SystemTrayItem, // Sets |notification_state_|. Returns true if a notification should be shown. bool UpdateNotificationState(const PowerSupplyStatus& status); + bool UpdateNotificationStateForRemainingTime(int remaining_seconds); + bool UpdateNotificationStateForRemainingPercentage( + double remaining_percentage); tray::PowerTrayView* power_tray_; tray::PowerNotificationView* notification_view_; diff --git a/chromeos/dbus/power_manager_client.cc b/chromeos/dbus/power_manager_client.cc index 2783b69..c453b6b 100644 --- a/chromeos/dbus/power_manager_client.cc +++ b/chromeos/dbus/power_manager_client.cc @@ -803,12 +803,6 @@ class PowerManagerClientStubImpl : public PowerManagerClient { status_.line_power_on = !discharging_; status_.battery_is_present = true; status_.battery_percentage = battery_percentage_; - status_.battery_seconds_to_empty = - std::max(1, battery_percentage_ * kSecondsToEmptyFullBattery / 100); - status_.battery_seconds_to_full = - std::max(static_cast<int64>(1), - kSecondsToEmptyFullBattery - status_.battery_seconds_to_empty); - if (cycle_count_ != 2) { status_.battery_state = discharging_ ? PowerSupplyStatus::DISCHARGING : PowerSupplyStatus::CHARGING; @@ -818,6 +812,15 @@ class PowerManagerClientStubImpl : public PowerManagerClient { PowerSupplyStatus::NEITHER_CHARGING_NOR_DISCHARGING; } + int64 remaining_battery_time = + std::max(1, battery_percentage_ * kSecondsToEmptyFullBattery / 100); + status_.battery_seconds_to_empty = + status_.battery_state == PowerSupplyStatus::DISCHARGING ? + remaining_battery_time : 0; + status_.battery_seconds_to_full = + status_.battery_state == PowerSupplyStatus::DISCHARGING ? + 0 : std::max(static_cast<int64>(1), + kSecondsToEmptyFullBattery - remaining_battery_time); FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status_)); } |