Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 893f923e authored by Sarvesh Kalwit's avatar Sarvesh Kalwit
Browse files

Floss: Refresh peripheral battery data if cache is empty

The Bluetooth stack restarts when a user signs out, so cached battery
data is cleared. This change manually refreshes peripheral battery data
if the battery data cache is empty.

Bug: 331896555
Test: m && manually with Logitech Casa Keys, signing out and in
Flag: EXEMPT, Floss only
Change-Id: I758f6d90a7c8047d69ae9f808ea378ac7588af5a
parent 811f3370
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -57,8 +57,20 @@ impl BatteryProviderManager {
    }

    /// Get the best battery info available for a given device.
    pub fn get_battery_info(&self, remote_address: RawAddress) -> Option<BatterySet> {
        self.battery_info.get(&remote_address)?.pick_best()
    pub fn get_battery_info(&mut self, remote_address: RawAddress) -> Option<BatterySet> {
        if let Some(info) = self.battery_info.get(&remote_address) {
            return info.pick_best();
        }

        // If no battery info found, refresh and retry
        self.refresh_battery_info();
        match self.battery_info.get(&remote_address) {
            None => {
                debug!("No battery info found for [{}]", DisplayAddress(&remote_address));
                return None;
            }
            Some(info) => return info.pick_best(),
        }
    }

    /// Removes a battery provider callback.