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

Commit fc28d6fc authored by Adam Lesinski's avatar Adam Lesinski Committed by Android (Google) Code Review
Browse files

Merge "BatteryStats: Prevent BatteryService from blocking" into mnc-dev

parents f68e0236 d7616ef7
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
@@ -860,9 +860,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) {
@@ -880,6 +887,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                    mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt);
                }
            }
        });
    }
    
    public long getAwakeTimeBattery() {
        mContext.enforceCallingOrSelfPermission(