Loading services/core/java/com/android/server/am/BatteryStatsService.java +30 −12 Original line number Diff line number Diff line Loading @@ -2908,19 +2908,37 @@ public final class BatteryStatsService extends IBatteryStats.Stub final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); final long currentTime = System.currentTimeMillis(); final boolean onBattery = BatteryStatsImpl.isOnBattery(plugType, status); final boolean batteryStateChanged; // We still schedule this task over the handler thread to make sure we've had // all existing pending work handled before setting the battery state mHandler.post(() -> { // 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 mWorker.scheduleRunnable(() -> { synchronized (mStats) { batteryStateChanged = mStats.isOnBattery() != onBattery; final boolean onBattery = BatteryStatsImpl.isOnBattery(plugType, status); if (mStats.isOnBattery() == onBattery) { // The battery state has not changed, so we don't need to sync external // stats immediately. mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt, chargeUAh, chargeFullUAh, chargeTimeToFullSeconds, elapsedRealtime, uptime, currentTime); return; } mHandler.post(() -> { mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt, chargeUAh, chargeFullUAh, chargeTimeToFullSeconds, elapsedRealtime, uptime, currentTime); if (batteryStateChanged) { mWorker.scheduleSync("battery-state", BatteryExternalStatsWorker.UPDATE_ALL); } // Sync external stats first as the battery has changed states. If we don't sync // before changing the state, we may not collect the relevant data later. // Order here is guaranteed since we're scheduling from the same thread and we // are using a single threaded executor. mWorker.scheduleSync("battery-state", BatteryExternalStatsWorker.UPDATE_ALL); mWorker.scheduleRunnable(() -> { synchronized (mStats) { mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt, chargeUAh, chargeFullUAh, chargeTimeToFullSeconds, elapsedRealtime, uptime, currentTime); } }); }); }); } } Loading Loading
services/core/java/com/android/server/am/BatteryStatsService.java +30 −12 Original line number Diff line number Diff line Loading @@ -2908,19 +2908,37 @@ public final class BatteryStatsService extends IBatteryStats.Stub final long elapsedRealtime = SystemClock.elapsedRealtime(); final long uptime = SystemClock.uptimeMillis(); final long currentTime = System.currentTimeMillis(); final boolean onBattery = BatteryStatsImpl.isOnBattery(plugType, status); final boolean batteryStateChanged; // We still schedule this task over the handler thread to make sure we've had // all existing pending work handled before setting the battery state mHandler.post(() -> { // 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 mWorker.scheduleRunnable(() -> { synchronized (mStats) { batteryStateChanged = mStats.isOnBattery() != onBattery; final boolean onBattery = BatteryStatsImpl.isOnBattery(plugType, status); if (mStats.isOnBattery() == onBattery) { // The battery state has not changed, so we don't need to sync external // stats immediately. mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt, chargeUAh, chargeFullUAh, chargeTimeToFullSeconds, elapsedRealtime, uptime, currentTime); return; } mHandler.post(() -> { mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt, chargeUAh, chargeFullUAh, chargeTimeToFullSeconds, elapsedRealtime, uptime, currentTime); if (batteryStateChanged) { mWorker.scheduleSync("battery-state", BatteryExternalStatsWorker.UPDATE_ALL); } // Sync external stats first as the battery has changed states. If we don't sync // before changing the state, we may not collect the relevant data later. // Order here is guaranteed since we're scheduling from the same thread and we // are using a single threaded executor. mWorker.scheduleSync("battery-state", BatteryExternalStatsWorker.UPDATE_ALL); mWorker.scheduleRunnable(() -> { synchronized (mStats) { mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt, chargeUAh, chargeFullUAh, chargeTimeToFullSeconds, elapsedRealtime, uptime, currentTime); } }); }); }); } } Loading