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

Commit d7616ef7 authored by Adam Lesinski's avatar Adam Lesinski
Browse files

BatteryStats: Prevent BatteryService from blocking

BatteryService is a low level service, and we shouldn't have it
block in BatteryStatsService while collecting external data from
components like WiFi. Deadlocks can occur this way.

Bug:22559655
Change-Id: I64026453d191695eb583a47163ab6f48f882b085
parent f0bead28
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
@@ -855,9 +855,16 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        return mStats.isOnBattery();
    }

    public void setBatteryState(int status, int health, int plugType, int level,
            int temp, int volt) {
    @Override
    public void setBatteryState(final int status, final int health, final int plugType,
                                final int level, final int temp, final int volt) {
        enforceCallingPermission();

        // BatteryService calls us here and we may update external state. It would be wrong
        // to block such a low level service like BatteryService on external stats like WiFi.
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                synchronized (mStats) {
                    final boolean onBattery = plugType == BatteryStatsImpl.BATTERY_PLUGGED_NONE;
                    if (mStats.isOnBattery() == onBattery) {
@@ -875,6 +882,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                    mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt);
                }
            }
        });
    }
    
    public long getAwakeTimeBattery() {
        mContext.enforceCallingOrSelfPermission(