summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2015-05-21 15:04:18 -0700
committerThe Android Automerger <android-build@google.com>2015-05-22 08:46:25 -0700
commitf7a06315e77d9de5c87789174edb3b0346cd1a54 (patch)
treeacfdb82a5fa7064fbe56eb0c0ec0f5cfba48d7c7
parent5048207d983fbff2acec941e5c6c191e0bf7e9be (diff)
downloadframeworks_base-f7a06315e77d9de5c87789174edb3b0346cd1a54.zip
frameworks_base-f7a06315e77d9de5c87789174edb3b0346cd1a54.tar.gz
frameworks_base-f7a06315e77d9de5c87789174edb3b0346cd1a54.tar.bz2
BatteryStatsService: Only query bluetooth on demand.
Bluetooth was being queried too often, leading to more power consumption and wakelock time. Bug:21063567 Bug:21269307 Change-Id: Idddbab46d13016ef8528e095945b7817c12f7266
-rw-r--r--services/core/java/com/android/server/am/BatteryStatsService.java38
1 files changed, 27 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
index a61223a..b1cc288 100644
--- a/services/core/java/com/android/server/am/BatteryStatsService.java
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -83,11 +83,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_SYNC_EXTERNAL_STATS:
- updateExternalStats((String)msg.obj);
+ updateExternalStats((String)msg.obj, false);
break;
case MSG_WRITE_TO_DISK:
- updateExternalStats("write");
+ updateExternalStats("write", true);
synchronized (mStats) {
mStats.writeAsyncLocked();
}
@@ -137,7 +137,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
public void shutdown() {
Slog.w("BatteryStats", "Writing battery stats before shutdown...");
- updateExternalStats("shutdown");
+ updateExternalStats("shutdown", true);
synchronized (mStats) {
mStats.shutdownLocked();
}
@@ -237,7 +237,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
//Slog.i("foo", "SENDING BATTERY INFO:");
//mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
Parcel out = Parcel.obtain();
- updateExternalStats("get-stats");
+ updateExternalStats("get-stats", true);
synchronized (mStats) {
mStats.writeToParcel(out, 0);
}
@@ -252,7 +252,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
//Slog.i("foo", "SENDING BATTERY INFO:");
//mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
Parcel out = Parcel.obtain();
- updateExternalStats("get-stats");
+ updateExternalStats("get-stats", true);
synchronized (mStats) {
mStats.writeToParcel(out, 0);
}
@@ -779,7 +779,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
// 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");
+ updateExternalStats("battery-state", false);
synchronized (mStats) {
mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt);
}
@@ -933,9 +933,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub
pw.println("Battery stats reset.");
noOutput = true;
}
- updateExternalStats("dump");
+ updateExternalStats("dump", true);
} else if ("--write".equals(arg)) {
- updateExternalStats("dump");
+ updateExternalStats("dump", true);
synchronized (mStats) {
mStats.writeSyncLocked();
pw.println("Battery stats written.");
@@ -999,7 +999,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY;
}
// Fetch data from external sources and update the BatteryStatsImpl object with them.
- updateExternalStats("dump");
+ updateExternalStats("dump", true);
} finally {
Binder.restoreCallingIdentity(ident);
}
@@ -1142,8 +1142,16 @@ public final class BatteryStatsService extends IBatteryStats.Stub
*
* We first grab a lock specific to this method, then once all the data has been collected,
* we grab the mStats lock and update the data.
+ *
+ * TODO(adamlesinski): When we start distributing bluetooth data to apps, we'll want to
+ * separate these external stats so that they can be collected individually and on different
+ * intervals.
+ *
+ * @param reason The reason why this collection was requested. Useful for debugging.
+ * @param force If false, some stats may decide not to be collected for efficiency as their
+ * results aren't needed immediately. When true, collect all stats unconditionally.
*/
- void updateExternalStats(String reason) {
+ void updateExternalStats(String reason, boolean force) {
synchronized (mExternalStatsLock) {
if (mContext == null) {
// We haven't started yet (which means the BatteryStatsImpl object has
@@ -1152,7 +1160,15 @@ public final class BatteryStatsService extends IBatteryStats.Stub
}
final WifiActivityEnergyInfo wifiEnergyInfo = pullWifiEnergyInfoLocked();
- final BluetoothActivityEnergyInfo bluetoothEnergyInfo = pullBluetoothEnergyInfoLocked();
+ final BluetoothActivityEnergyInfo bluetoothEnergyInfo;
+ if (force) {
+ // We only pull bluetooth stats when we have to, as we are not distributing its
+ // use amongst apps and the sampling frequency does not matter.
+ bluetoothEnergyInfo = pullBluetoothEnergyInfoLocked();
+ } else {
+ bluetoothEnergyInfo = null;
+ }
+
synchronized (mStats) {
if (mStats.mRecordAllHistory) {
final long elapsedRealtime = SystemClock.elapsedRealtime();