diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-07-27 20:01:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-27 20:01:34 +0000 |
commit | fc28d6fc9dec30e4cd98cc894d596f7df986f5b9 (patch) | |
tree | aa4c375791219f3817aef4e4ff2e257d1ff7eed3 | |
parent | f68e0236a67a8d6f8ec167df0daf332221149b51 (diff) | |
parent | d7616ef73c48a1e5d6ba0e36fc6e85b007832d25 (diff) | |
download | frameworks_base-fc28d6fc9dec30e4cd98cc894d596f7df986f5b9.zip frameworks_base-fc28d6fc9dec30e4cd98cc894d596f7df986f5b9.tar.gz frameworks_base-fc28d6fc9dec30e4cd98cc894d596f7df986f5b9.tar.bz2 |
Merge "BatteryStats: Prevent BatteryService from blocking" into mnc-dev
-rw-r--r-- | services/core/java/com/android/server/am/BatteryStatsService.java | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java index 4102f37..447fe87 100644 --- a/services/core/java/com/android/server/am/BatteryStatsService.java +++ b/services/core/java/com/android/server/am/BatteryStatsService.java @@ -859,26 +859,35 @@ public final class BatteryStatsService extends IBatteryStats.Stub public boolean isOnBattery() { return mStats.isOnBattery(); } - - public void setBatteryState(int status, int health, int plugType, int level, - int temp, int volt) { - enforceCallingPermission(); - synchronized (mStats) { - final boolean onBattery = plugType == BatteryStatsImpl.BATTERY_PLUGGED_NONE; - 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); - return; - } - } - // Sync external stats first as the battery has changed states. If we don't sync - // immediately here, we may not collect the relevant data later. - updateExternalStats("battery-state", UPDATE_ALL); - synchronized (mStats) { - mStats.setBatteryStateLocked(status, health, plugType, level, temp, 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) { + // The battery state has not changed, so we don't need to sync external + // stats immediately. + mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt); + return; + } + } + + // Sync external stats first as the battery has changed states. If we don't sync + // immediately here, we may not collect the relevant data later. + updateExternalStats("battery-state", UPDATE_ALL); + synchronized (mStats) { + mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt); + } + } + }); } public long getAwakeTimeBattery() { |