wlan_power_manager/
lib.rs1use async_trait::async_trait;
6use fidl_fuchsia_power_system as fsystem;
7use log::warn;
8
9pub struct WakeLease {
10 _token: fsystem::LeaseToken,
11}
12
13impl WakeLease {
14 #[doc(hidden)]
17 pub fn from_token_for_test(token: fsystem::LeaseToken) -> Self {
18 Self { _token: token }
19 }
20}
21
22#[async_trait]
23pub trait PowerManager: Send + Sync {
24 async fn take_wake_lease(&self, name: &str) -> Option<WakeLease>;
25}
26
27pub struct DevicePowerManager {
28 activity_governor: Option<fsystem::ActivityGovernorProxy>,
29}
30
31impl DevicePowerManager {
32 pub fn new(activity_governor: Option<fsystem::ActivityGovernorProxy>) -> Self {
33 Self { activity_governor }
34 }
35}
36
37#[async_trait]
38impl PowerManager for DevicePowerManager {
39 async fn take_wake_lease(&self, name: &str) -> Option<WakeLease> {
40 let activity_governor = self.activity_governor.as_ref()?;
41 match activity_governor.acquire_wake_lease(name).await {
42 Ok(Ok(token)) => Some(WakeLease { _token: token }),
43 Ok(Err(e)) => {
44 warn!("Failed to acquire wake lease {}: {:?}", name, e);
45 None
46 }
47 Err(e) => {
48 warn!("FIDL error when acquiring wake lease {}: {:?}", name, e);
49 None
50 }
51 }
52 }
53}