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

Commit 7a3d4953 authored by Luofan Chen's avatar Luofan Chen Committed by Arian
Browse files

recovery_ui: Retry for getting battery info

Test: Enter recovery and verify battery percentage is correct

Change-Id: I13b9fdb4f8ac5d515b732f98da448991a6b84b6d
parent c8695e63
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -962,6 +962,8 @@ void ScreenRecoveryUI::BattMonitorThreadLoop() {
  auto batt_monitor = std::make_unique<android::BatteryMonitor>();
  batt_monitor->init(config.get());

  bool is_first_call = true;

  while (!batt_monitor_thread_stopped_) {
    bool redraw = false;
    {
@@ -978,7 +980,21 @@ void ScreenRecoveryUI::BattMonitorThreadLoop() {
      }

      android::BatteryProperty prop;
      android::status_t status = batt_monitor->getProperty(android::BATTERY_PROP_CAPACITY, &prop);
      android::base::Timer t;
      android::status_t status;
      while (t.duration() < 5s) {
        status = batt_monitor->getProperty(android::BATTERY_PROP_CAPACITY, &prop);
        if (status == android::OK || !is_first_call) {
          break;
        }

        LOG(WARNING) << "Trying again for reinitializing battery info";
        if (redraw) update_screen_locked();
        batt_monitor->init(config.get());
        std::this_thread::sleep_for(100ms);
      }
      is_first_call = false;

      // If we can't read battery percentage, it may be a device without battery. In this
      // situation, use 100 as a fake battery percentage.
      if (status != android::OK) {