mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
852411e746
This adds support for battery charge, voltage, battery charge counter in power_monitor and populates these fields from powerd data. BUG=b:162479956 TEST=Compare voltage_now, charge_full, charge_now/charge_counter, current_now fields in sysfs on host and in ARCVM TEST=CTS tests android.cts.statsd.atom.HostAtomTests#testBatteryVoltage, android.cts.statsd.atom.HostAtomTests#testFullBatteryCapacity and android.cts.statsd.atom.HostAtomTests#testRemainingBatteryCapacity pass in ARCVM Change-Id: I3f93f499fa7d00cc5a0a2b69e7cfbcd233a2983a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2681212 Tested-by: Alex Lau <alexlau@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Alex Lau <alexlau@chromium.org>
49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
// Copyright 2020 The Chromium OS Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
use std::error::Error;
|
|
use std::os::unix::io::RawFd;
|
|
|
|
pub trait PowerMonitor {
|
|
fn poll_fd(&self) -> RawFd;
|
|
fn read_message(&mut self) -> std::result::Result<Option<PowerData>, Box<dyn Error>>;
|
|
}
|
|
|
|
pub struct PowerData {
|
|
pub ac_online: bool,
|
|
pub battery: Option<BatteryData>,
|
|
}
|
|
|
|
pub struct BatteryData {
|
|
pub status: BatteryStatus,
|
|
pub percent: u32,
|
|
/// Battery voltage in microvolts.
|
|
pub voltage: u32,
|
|
/// Battery current in microamps.
|
|
pub current: u32,
|
|
/// Battery charge counter in microampere hours.
|
|
pub charge_counter: u32,
|
|
/// Battery full charge counter in microampere hours.
|
|
pub charge_full: u32,
|
|
}
|
|
|
|
pub enum BatteryStatus {
|
|
Unknown,
|
|
Charging,
|
|
Discharging,
|
|
NotCharging,
|
|
}
|
|
|
|
pub trait CreatePowerMonitorFn:
|
|
Send + Fn() -> std::result::Result<Box<dyn PowerMonitor>, Box<dyn Error>>
|
|
{
|
|
}
|
|
|
|
impl<T> CreatePowerMonitorFn for T where
|
|
T: Send + Fn() -> std::result::Result<Box<dyn PowerMonitor>, Box<dyn Error>>
|
|
{
|
|
}
|
|
|
|
#[cfg(feature = "powerd")]
|
|
pub mod powerd;
|