Commit cb022270 authored by Thanh Nguyen's avatar Thanh Nguyen Committed by Commit Bot

[smart-charging] Additional feature for smart charging

Add an additional feature for smart charging that record whether the
device is being charged or not.

Bug: 1028853
Change-Id: Icea89ce2aae3416dae14cd1fa8b8386a4868df2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2053264Reviewed-by: default avatarTony Yeoman <tby@chromium.org>
Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Thanh Nguyen <thanhdng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743345}
parent b7a11ea1
......@@ -273,7 +273,10 @@ void SmartChargingManager::PowerChanged(
periodic_timer_->Start(FROM_HERE, kLoggingInterval, this,
&SmartChargingManager::OnTimerFired);
if (external_power_.value() == power_manager::PowerSupplyProperties::AC) {
is_charging_ = true;
LogEvent(UserChargingEvent::Event::CHARGER_PLUGGED_IN);
} else {
is_charging_ = false;
}
return;
}
......@@ -283,6 +286,8 @@ void SmartChargingManager::PowerChanged(
const bool now_on_ac =
proto.external_power() == power_manager::PowerSupplyProperties::AC;
is_charging_ = now_on_ac;
// User plugged the charger in.
if (!was_on_ac && now_on_ac) {
external_power_ = proto.external_power();
......@@ -375,6 +380,9 @@ void SmartChargingManager::PopulateUserChargingEventProto(
features.set_num_recent_stylus_events(
stylus_counter_->GetTotal(time_since_boot));
if (is_charging_.has_value())
features.set_is_charging(is_charging_.value());
if (screen_brightness_percent_)
features.set_screen_brightness_percent(
static_cast<int>(screen_brightness_percent_.value()));
......
......@@ -176,6 +176,7 @@ class SmartChargingManager : public ui::UserActivityObserver,
base::Optional<double> screen_brightness_percent_;
base::Optional<power_manager::PowerSupplyProperties::ExternalPower>
external_power_;
base::Optional<bool> is_charging_;
base::Optional<base::FilePath> profile_path_;
const std::unique_ptr<SmartChargingUkmLogger> ukm_logger_;
......
......@@ -118,6 +118,10 @@ void SmartChargingUkmLogger::LogEvent(
ukm_smart_charging.SetHaltFromLastCharge(features.halt_from_last_charge());
}
if (features.has_is_charging()) {
ukm_smart_charging.SetIsCharging(features.is_charging());
}
ukm::UkmRecorder* const ukm_recorder = ukm::UkmRecorder::Get();
ukm_smart_charging.Record(ukm_recorder);
}
......
......@@ -67,6 +67,7 @@ TEST_F(SmartChargingUkmLoggerTest, TestRecordCorrectly) {
features->set_screen_brightness_percent(23);
features->set_voltage(3500);
features->set_halt_from_last_charge(true);
features->set_is_charging(true);
// Constructs the expected output.
const UkmMetricMap user_charging_values = {
......@@ -91,7 +92,8 @@ TEST_F(SmartChargingUkmLoggerTest, TestRecordCorrectly) {
{UkmEntry::kDurationRecentVideoPlayingName, 4},
{UkmEntry::kDurationRecentAudioPlayingName, 8},
{UkmEntry::kScreenBrightnessPercentName, 23},
{UkmEntry::kHaltFromLastChargeName, 1}};
{UkmEntry::kHaltFromLastChargeName, 1},
{UkmEntry::kIsChargingName, 1}};
// Log a charging event.
LogEvent(user_charging_event);
......
......@@ -92,6 +92,8 @@ message UserChargingEvent {
// Whether there's any shutdown/suspend action between the last charge
// and current event.
optional bool halt_from_last_charge = 21;
// Whether the device is being charged or not.
optional bool is_charging = 22;
}
message Event {
......
......@@ -9202,6 +9202,11 @@ be describing additional metrics about the same event.
current event.
</summary>
</metric>
<metric name="IsCharging" enum="Boolean">
<summary>
Whether the device is being charged or not.
</summary>
</metric>
<metric name="Month" enum="Month">
<summary>
Event's month (e.g. Jan-Dec) in local time zone. January is 1.
......
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