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

Commit 982384a0 authored by Kweku Adams's avatar Kweku Adams
Browse files

Get battery presence at setup, if possible.

TARE may go through "boot" setup when it's enabled after boot. Checking
the battery presence during setup would help ensure proper behavior on a
battery-less devic (that may not send another BATTERY_CHANGED broadcast
after the very first one).

Bug: 240726265
Test: flash device and check TARE and JobScheduler dumps
Change-Id: I7e575f2b6a8f7624e5bdcf33112fbd928ebd9abc
parent a4e04044
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -815,6 +815,18 @@ public class InternalResourceService extends SystemService {
        synchronized (mLock) {
            registerListeners();
            mCurrentBatteryLevel = getCurrentBatteryLevel();
            // Get the current battery presence, if available. This would succeed if TARE is
            // toggled long after boot.
            final Intent batteryStatus = getContext().registerReceiver(null,
                    new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
            if (batteryStatus != null) {
                final boolean hasBattery =
                        batteryStatus.getBooleanExtra(BatteryManager.EXTRA_PRESENT, true);
                if (mHasBattery != hasBattery) {
                    mHasBattery = hasBattery;
                    mConfigObserver.updateEnabledStatus();
                }
            }
        }
    }