Commit f375a4b6 authored by Jeffrey Young's avatar Jeffrey Young Committed by Commit Bot

ambient: rework IsChargerConnected

Handle case of device without battery.
Handle case of battery not full, not charging, but connected to power.

BUG=b:171979755

Cq-Include-Trybots: luci.chrome.try:linux-chromeos-chrome
Change-Id: I0dda61d03e361bcc1a21d5ad9ef33a954debf7e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2500324
Commit-Queue: Jeffrey Young <cowmoo@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822280}
parent b54e1332
...@@ -89,9 +89,19 @@ std::string GetWidgetName() { ...@@ -89,9 +89,19 @@ std::string GetWidgetName() {
// Returns true if the device is currently connected to a charger. // Returns true if the device is currently connected to a charger.
bool IsChargerConnected() { bool IsChargerConnected() {
return (PowerStatus::Get()->IsBatteryCharging() || DCHECK(PowerStatus::IsInitialized());
PowerStatus::Get()->IsBatteryFull()) && auto* power_status = PowerStatus::Get();
PowerStatus::Get()->IsLinePowerConnected(); if (power_status->IsBatteryPresent()) {
// If battery is full or battery is charging, that implies power is
// connected. Also return true if a power source is connected and
// battery is not discharging.
return power_status->IsBatteryCharging() || power_status->IsBatteryFull() ||
(power_status->IsLinePowerConnected() &&
!power_status->IsBatteryDischargingOnLinePower());
} else {
// Chromeboxes have no battery.
return power_status->IsLinePowerConnected();
}
} }
bool IsUiHidden(AmbientUiVisibility visibility) { bool IsUiHidden(AmbientUiVisibility visibility) {
......
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