Loading services/core/java/com/android/server/am/BatteryStatsService.java +27 −11 Original line number Original line Diff line number Diff line Loading @@ -83,11 +83,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub public void handleMessage(Message msg) { public void handleMessage(Message msg) { switch (msg.what) { switch (msg.what) { case MSG_SYNC_EXTERNAL_STATS: case MSG_SYNC_EXTERNAL_STATS: updateExternalStats((String)msg.obj); updateExternalStats((String)msg.obj, false); break; break; case MSG_WRITE_TO_DISK: case MSG_WRITE_TO_DISK: updateExternalStats("write"); updateExternalStats("write", true); synchronized (mStats) { synchronized (mStats) { mStats.writeAsyncLocked(); mStats.writeAsyncLocked(); } } Loading Loading @@ -137,7 +137,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub public void shutdown() { public void shutdown() { Slog.w("BatteryStats", "Writing battery stats before shutdown..."); Slog.w("BatteryStats", "Writing battery stats before shutdown..."); updateExternalStats("shutdown"); updateExternalStats("shutdown", true); synchronized (mStats) { synchronized (mStats) { mStats.shutdownLocked(); mStats.shutdownLocked(); } } Loading Loading @@ -237,7 +237,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub //Slog.i("foo", "SENDING BATTERY INFO:"); //Slog.i("foo", "SENDING BATTERY INFO:"); //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM)); //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM)); Parcel out = Parcel.obtain(); Parcel out = Parcel.obtain(); updateExternalStats("get-stats"); updateExternalStats("get-stats", true); synchronized (mStats) { synchronized (mStats) { mStats.writeToParcel(out, 0); mStats.writeToParcel(out, 0); } } Loading @@ -252,7 +252,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub //Slog.i("foo", "SENDING BATTERY INFO:"); //Slog.i("foo", "SENDING BATTERY INFO:"); //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM)); //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM)); Parcel out = Parcel.obtain(); Parcel out = Parcel.obtain(); updateExternalStats("get-stats"); updateExternalStats("get-stats", true); synchronized (mStats) { synchronized (mStats) { mStats.writeToParcel(out, 0); mStats.writeToParcel(out, 0); } } Loading Loading @@ -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 // 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. // immediately here, we may not collect the relevant data later. updateExternalStats("battery-state"); updateExternalStats("battery-state", false); synchronized (mStats) { synchronized (mStats) { mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt); mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt); } } Loading Loading @@ -933,9 +933,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub pw.println("Battery stats reset."); pw.println("Battery stats reset."); noOutput = true; noOutput = true; } } updateExternalStats("dump"); updateExternalStats("dump", true); } else if ("--write".equals(arg)) { } else if ("--write".equals(arg)) { updateExternalStats("dump"); updateExternalStats("dump", true); synchronized (mStats) { synchronized (mStats) { mStats.writeSyncLocked(); mStats.writeSyncLocked(); pw.println("Battery stats written."); pw.println("Battery stats written."); Loading Loading @@ -999,7 +999,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY; flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY; } } // Fetch data from external sources and update the BatteryStatsImpl object with them. // Fetch data from external sources and update the BatteryStatsImpl object with them. updateExternalStats("dump"); updateExternalStats("dump", true); } finally { } finally { Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident); } } Loading Loading @@ -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 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. * 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) { synchronized (mExternalStatsLock) { if (mContext == null) { if (mContext == null) { // We haven't started yet (which means the BatteryStatsImpl object has // We haven't started yet (which means the BatteryStatsImpl object has Loading @@ -1152,7 +1160,15 @@ public final class BatteryStatsService extends IBatteryStats.Stub } } final WifiActivityEnergyInfo wifiEnergyInfo = pullWifiEnergyInfoLocked(); 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) { synchronized (mStats) { if (mStats.mRecordAllHistory) { if (mStats.mRecordAllHistory) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long elapsedRealtime = SystemClock.elapsedRealtime(); Loading Loading
services/core/java/com/android/server/am/BatteryStatsService.java +27 −11 Original line number Original line Diff line number Diff line Loading @@ -83,11 +83,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub public void handleMessage(Message msg) { public void handleMessage(Message msg) { switch (msg.what) { switch (msg.what) { case MSG_SYNC_EXTERNAL_STATS: case MSG_SYNC_EXTERNAL_STATS: updateExternalStats((String)msg.obj); updateExternalStats((String)msg.obj, false); break; break; case MSG_WRITE_TO_DISK: case MSG_WRITE_TO_DISK: updateExternalStats("write"); updateExternalStats("write", true); synchronized (mStats) { synchronized (mStats) { mStats.writeAsyncLocked(); mStats.writeAsyncLocked(); } } Loading Loading @@ -137,7 +137,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub public void shutdown() { public void shutdown() { Slog.w("BatteryStats", "Writing battery stats before shutdown..."); Slog.w("BatteryStats", "Writing battery stats before shutdown..."); updateExternalStats("shutdown"); updateExternalStats("shutdown", true); synchronized (mStats) { synchronized (mStats) { mStats.shutdownLocked(); mStats.shutdownLocked(); } } Loading Loading @@ -237,7 +237,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub //Slog.i("foo", "SENDING BATTERY INFO:"); //Slog.i("foo", "SENDING BATTERY INFO:"); //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM)); //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM)); Parcel out = Parcel.obtain(); Parcel out = Parcel.obtain(); updateExternalStats("get-stats"); updateExternalStats("get-stats", true); synchronized (mStats) { synchronized (mStats) { mStats.writeToParcel(out, 0); mStats.writeToParcel(out, 0); } } Loading @@ -252,7 +252,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub //Slog.i("foo", "SENDING BATTERY INFO:"); //Slog.i("foo", "SENDING BATTERY INFO:"); //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM)); //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM)); Parcel out = Parcel.obtain(); Parcel out = Parcel.obtain(); updateExternalStats("get-stats"); updateExternalStats("get-stats", true); synchronized (mStats) { synchronized (mStats) { mStats.writeToParcel(out, 0); mStats.writeToParcel(out, 0); } } Loading Loading @@ -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 // 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. // immediately here, we may not collect the relevant data later. updateExternalStats("battery-state"); updateExternalStats("battery-state", false); synchronized (mStats) { synchronized (mStats) { mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt); mStats.setBatteryStateLocked(status, health, plugType, level, temp, volt); } } Loading Loading @@ -933,9 +933,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub pw.println("Battery stats reset."); pw.println("Battery stats reset."); noOutput = true; noOutput = true; } } updateExternalStats("dump"); updateExternalStats("dump", true); } else if ("--write".equals(arg)) { } else if ("--write".equals(arg)) { updateExternalStats("dump"); updateExternalStats("dump", true); synchronized (mStats) { synchronized (mStats) { mStats.writeSyncLocked(); mStats.writeSyncLocked(); pw.println("Battery stats written."); pw.println("Battery stats written."); Loading Loading @@ -999,7 +999,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY; flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY; } } // Fetch data from external sources and update the BatteryStatsImpl object with them. // Fetch data from external sources and update the BatteryStatsImpl object with them. updateExternalStats("dump"); updateExternalStats("dump", true); } finally { } finally { Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident); } } Loading Loading @@ -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 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. * 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) { synchronized (mExternalStatsLock) { if (mContext == null) { if (mContext == null) { // We haven't started yet (which means the BatteryStatsImpl object has // We haven't started yet (which means the BatteryStatsImpl object has Loading @@ -1152,7 +1160,15 @@ public final class BatteryStatsService extends IBatteryStats.Stub } } final WifiActivityEnergyInfo wifiEnergyInfo = pullWifiEnergyInfoLocked(); 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) { synchronized (mStats) { if (mStats.mRecordAllHistory) { if (mStats.mRecordAllHistory) { final long elapsedRealtime = SystemClock.elapsedRealtime(); final long elapsedRealtime = SystemClock.elapsedRealtime(); Loading