blob: 7db4ac20067b158c258fce0c6d835105a76f3a13 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.os;
18
19import java.io.PrintWriter;
Dianne Hackborne4a59512010-12-07 11:08:07 -080020import java.util.ArrayList;
Dianne Hackborn81038902012-11-26 17:04:09 -080021import java.util.Collections;
22import java.util.Comparator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import java.util.Formatter;
Dianne Hackborne4a59512010-12-07 11:08:07 -080024import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import java.util.Map;
26
Dianne Hackborna7c837f2014-01-15 16:20:44 -080027import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080028import android.content.pm.ApplicationInfo;
Wink Saville52840902011-02-18 12:40:47 -080029import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080030import android.text.format.DateFormat;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.util.Printer;
32import android.util.SparseArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070033import android.util.TimeUtils;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080034import com.android.internal.os.BatterySipper;
35import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37/**
38 * A class providing access to battery usage statistics, including information on
39 * wakelocks, processes, packages, and services. All times are represented in microseconds
40 * except where indicated otherwise.
41 * @hide
42 */
43public abstract class BatteryStats implements Parcelable {
44
45 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070046
47 /** @hide */
48 public static final String SERVICE_NAME = "batterystats";
49
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 /**
51 * A constant indicating a partial wake lock timer.
52 */
53 public static final int WAKE_TYPE_PARTIAL = 0;
54
55 /**
56 * A constant indicating a full wake lock timer.
57 */
58 public static final int WAKE_TYPE_FULL = 1;
59
60 /**
61 * A constant indicating a window wake lock timer.
62 */
63 public static final int WAKE_TYPE_WINDOW = 2;
64
65 /**
66 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 */
68 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070069
70 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070071 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070072 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070073 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070074
75 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070076 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070077 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070078 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070079
80 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070081 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070082 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070083 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084
Robert Greenwalt5347bd42009-05-13 15:10:16 -070085 /**
86 * A constant indicating a wifi multicast timer
Robert Greenwalt5347bd42009-05-13 15:10:16 -070087 */
88 public static final int WIFI_MULTICAST_ENABLED = 7;
89
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070091 * A constant indicating an audio turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070092 */
93 public static final int AUDIO_TURNED_ON = 7;
94
95 /**
96 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070097 */
98 public static final int VIDEO_TURNED_ON = 8;
99
100 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800101 * A constant indicating a vibrator on timer
102 */
103 public static final int VIBRATOR_ON = 9;
104
105 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700106 * A constant indicating a foreground activity timer
107 */
108 public static final int FOREGROUND_ACTIVITY = 10;
109
110 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700111 * A constant indicating a wifi batched scan is active
112 */
113 public static final int WIFI_BATCHED_SCAN = 11;
114
115 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 * Include all of the data in the stats, including previously saved data.
117 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700118 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119
120 /**
121 * Include only the last run in the stats.
122 */
123 public static final int STATS_LAST = 1;
124
125 /**
126 * Include only the current run in the stats.
127 */
128 public static final int STATS_CURRENT = 2;
129
130 /**
131 * Include only the run since the last time the device was unplugged in the stats.
132 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700133 public static final int STATS_SINCE_UNPLUGGED = 3;
Evan Millare84de8d2009-04-02 22:16:12 -0700134
135 // NOTE: Update this list if you add/change any stats above.
136 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700137 // and "unplugged". They were shortened for efficiency sake.
Evan Millare84de8d2009-04-02 22:16:12 -0700138 private static final String[] STAT_NAMES = { "t", "l", "c", "u" };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139
140 /**
141 * Bump the version on this if the checkin format changes.
142 */
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700143 private static final int BATTERY_STATS_CHECKIN_VERSION = 7;
Evan Millar22ac0432009-03-31 11:33:18 -0700144
145 private static final long BYTES_PER_KB = 1024;
146 private static final long BYTES_PER_MB = 1048576; // 1024^2
147 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
Dianne Hackborne4a59512010-12-07 11:08:07 -0800150 private static final String UID_DATA = "uid";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700152 private static final String PROCESS_DATA = "pr";
153 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800154 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700155 private static final String FOREGROUND_DATA = "fg";
Evan Millare84de8d2009-04-02 22:16:12 -0700156 private static final String WAKELOCK_DATA = "wl";
Evan Millarc64edde2009-04-18 12:26:32 -0700157 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Evan Millare84de8d2009-04-02 22:16:12 -0700158 private static final String NETWORK_DATA = "nt";
159 private static final String USER_ACTIVITY_DATA = "ua";
160 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800161 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700162 private static final String BATTERY_LEVEL_DATA = "lv";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700163 private static final String WIFI_DATA = "wfl";
Evan Millare84de8d2009-04-02 22:16:12 -0700164 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800165 private static final String GLOBAL_NETWORK_DATA = "gn";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800166 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700167 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700168 private static final String SCREEN_BRIGHTNESS_DATA = "br";
169 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700170 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700171 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
172 private static final String DATA_CONNECTION_TIME_DATA = "dct";
173 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800174 private static final String WIFI_STATE_TIME_DATA = "wst";
175 private static final String WIFI_STATE_COUNT_DATA = "wsc";
176 private static final String BLUETOOTH_STATE_TIME_DATA = "bst";
177 private static final String BLUETOOTH_STATE_COUNT_DATA = "bsc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800178 private static final String POWER_USE_SUMMARY_DATA = "pws";
179 private static final String POWER_USE_ITEM_DATA = "pwi";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700181 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 private final Formatter mFormatter = new Formatter(mFormatBuilder);
183
184 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700185 * State for keeping track of counting information.
186 */
187 public static abstract class Counter {
188
189 /**
190 * Returns the count associated with this Counter for the
191 * selected type of statistics.
192 *
193 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
194 */
Evan Millarc64edde2009-04-18 12:26:32 -0700195 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700196
197 /**
198 * Temporary for debugging.
199 */
200 public abstract void logState(Printer pw, String prefix);
201 }
202
203 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 * State for keeping track of timing information.
205 */
206 public static abstract class Timer {
207
208 /**
209 * Returns the count associated with this Timer for the
210 * selected type of statistics.
211 *
212 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
213 */
Evan Millarc64edde2009-04-18 12:26:32 -0700214 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215
216 /**
217 * Returns the total time in microseconds associated with this Timer for the
218 * selected type of statistics.
219 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800220 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
222 * @return a time in microseconds
223 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800224 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 /**
227 * Temporary for debugging.
228 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700229 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 }
231
232 /**
233 * The statistics associated with a particular uid.
234 */
235 public static abstract class Uid {
236
237 /**
238 * Returns a mapping containing wakelock statistics.
239 *
240 * @return a Map from Strings to Uid.Wakelock objects.
241 */
242 public abstract Map<String, ? extends Wakelock> getWakelockStats();
243
244 /**
245 * The statistics associated with a particular wake lock.
246 */
247 public static abstract class Wakelock {
248 public abstract Timer getWakeTime(int type);
249 }
250
251 /**
252 * Returns a mapping containing sensor statistics.
253 *
254 * @return a Map from Integer sensor ids to Uid.Sensor objects.
255 */
256 public abstract Map<Integer, ? extends Sensor> getSensorStats();
257
258 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700259 * Returns a mapping containing active process data.
260 */
261 public abstract SparseArray<? extends Pid> getPidStats();
262
263 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 * Returns a mapping containing process statistics.
265 *
266 * @return a Map from Strings to Uid.Proc objects.
267 */
268 public abstract Map<String, ? extends Proc> getProcessStats();
269
270 /**
271 * Returns a mapping containing package statistics.
272 *
273 * @return a Map from Strings to Uid.Pkg objects.
274 */
275 public abstract Map<String, ? extends Pkg> getPackageStats();
276
277 /**
278 * {@hide}
279 */
280 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700281
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800282 public abstract void noteWifiRunningLocked(long elapsedRealtime);
283 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
284 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
285 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
286 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
287 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
288 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
289 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
290 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
291 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
292 public abstract void noteAudioTurnedOnLocked(long elapsedRealtime);
293 public abstract void noteAudioTurnedOffLocked(long elapsedRealtime);
294 public abstract void noteVideoTurnedOnLocked(long elapsedRealtime);
295 public abstract void noteVideoTurnedOffLocked(long elapsedRealtime);
296 public abstract void noteActivityResumedLocked(long elapsedRealtime);
297 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800298 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
299 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
300 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
301 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
302 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
303 public abstract long getAudioTurnedOnTime(long elapsedRealtimeUs, int which);
304 public abstract long getVideoTurnedOnTime(long elapsedRealtimeUs, int which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700305 public abstract Timer getForegroundActivityTimer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800306 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307
Robert Greenwalta029ea12013-09-25 16:38:12 -0700308 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
309
Dianne Hackborn617f8772009-03-31 15:04:46 -0700310 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700311 * Note that these must match the constants in android.os.PowerManager.
312 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
313 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700314 */
315 static final String[] USER_ACTIVITY_TYPES = {
Jeff Browndf693de2012-07-27 12:03:38 -0700316 "other", "button", "touch"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700317 };
318
Jeff Browndf693de2012-07-27 12:03:38 -0700319 public static final int NUM_USER_ACTIVITY_TYPES = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700320
Dianne Hackborn617f8772009-03-31 15:04:46 -0700321 public abstract void noteUserActivityLocked(int type);
322 public abstract boolean hasUserActivity();
323 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700324
325 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800326 public abstract long getNetworkActivityBytes(int type, int which);
327 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800328 public abstract long getMobileRadioActiveTime(int which);
329 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800332 /*
333 * FIXME: it's not correct to use this magic value because it
334 * could clash with a sensor handle (which are defined by
335 * the sensor HAL, and therefore out of our control
336 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 // Magic sensor number for the GPS.
338 public static final int GPS = -10000;
339
340 public abstract int getHandle();
341
342 public abstract Timer getSensorTime();
343 }
344
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700345 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800346 public int mWakeNesting;
347 public long mWakeSumMs;
348 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700349 }
350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 /**
352 * The statistics associated with a particular process.
353 */
354 public static abstract class Proc {
355
Dianne Hackborn287952c2010-09-22 22:34:31 -0700356 public static class ExcessivePower {
357 public static final int TYPE_WAKE = 1;
358 public static final int TYPE_CPU = 2;
359
360 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700361 public long overTime;
362 public long usedTime;
363 }
364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800366 * Returns true if this process is still active in the battery stats.
367 */
368 public abstract boolean isActive();
369
370 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 * Returns the total time (in 1/100 sec) spent executing in user code.
372 *
373 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
374 */
375 public abstract long getUserTime(int which);
376
377 /**
378 * Returns the total time (in 1/100 sec) spent executing in system code.
379 *
380 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
381 */
382 public abstract long getSystemTime(int which);
383
384 /**
385 * Returns the number of times the process has been started.
386 *
387 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
388 */
389 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700390
391 /**
392 * Returns the cpu time spent in microseconds while the process was in the foreground.
393 * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
394 * @return foreground cpu time in microseconds
395 */
396 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700397
398 /**
399 * Returns the approximate cpu time spent in microseconds, at a certain CPU speed.
400 * @param speedStep the index of the CPU speed. This is not the actual speed of the
401 * CPU.
402 * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
403 * @see BatteryStats#getCpuSpeedSteps()
404 */
405 public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700406
Dianne Hackborn287952c2010-09-22 22:34:31 -0700407 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700408
Dianne Hackborn287952c2010-09-22 22:34:31 -0700409 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 }
411
412 /**
413 * The statistics associated with a particular package.
414 */
415 public static abstract class Pkg {
416
417 /**
418 * Returns the number of times this package has done something that could wake up the
419 * device from sleep.
420 *
421 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
422 */
423 public abstract int getWakeups(int which);
424
425 /**
426 * Returns a mapping containing service statistics.
427 */
428 public abstract Map<String, ? extends Serv> getServiceStats();
429
430 /**
431 * The statistics associated with a particular service.
432 */
433 public abstract class Serv {
434
435 /**
436 * Returns the amount of time spent started.
437 *
438 * @param batteryUptime elapsed uptime on battery in microseconds.
439 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
440 * @return
441 */
442 public abstract long getStartTime(long batteryUptime, int which);
443
444 /**
445 * Returns the total number of times startService() has been called.
446 *
447 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
448 */
449 public abstract int getStarts(int which);
450
451 /**
452 * Returns the total number times the service has been launched.
453 *
454 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
455 */
456 public abstract int getLaunches(int which);
457 }
458 }
459 }
460
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800461 public final static class HistoryTag {
462 public String string;
463 public int uid;
464
465 public int poolIdx;
466
467 public void setTo(HistoryTag o) {
468 string = o.string;
469 uid = o.uid;
470 poolIdx = o.poolIdx;
471 }
472
473 public void setTo(String _string, int _uid) {
474 string = _string;
475 uid = _uid;
476 poolIdx = -1;
477 }
478
479 public void writeToParcel(Parcel dest, int flags) {
480 dest.writeString(string);
481 dest.writeInt(uid);
482 }
483
484 public void readFromParcel(Parcel src) {
485 string = src.readString();
486 uid = src.readInt();
487 poolIdx = -1;
488 }
489
490 @Override
491 public boolean equals(Object o) {
492 if (this == o) return true;
493 if (o == null || getClass() != o.getClass()) return false;
494
495 HistoryTag that = (HistoryTag) o;
496
497 if (uid != that.uid) return false;
498 if (!string.equals(that.string)) return false;
499
500 return true;
501 }
502
503 @Override
504 public int hashCode() {
505 int result = string.hashCode();
506 result = 31 * result + uid;
507 return result;
508 }
509 }
510
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700511 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700512 public HistoryItem next;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700513
514 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800515
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800516 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800517 public static final byte CMD_NULL = -1;
518 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800519 public static final byte CMD_CURRENT_TIME = 5;
520 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800521
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700522 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700523
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800524 /**
525 * Return whether the command code is a delta data update.
526 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800527 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800528 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800529 }
530
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700531 public byte batteryLevel;
532 public byte batteryStatus;
533 public byte batteryHealth;
534 public byte batteryPlugType;
535
Sungmin Choic7e9e8b2013-01-16 12:57:36 +0900536 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700537 public char batteryVoltage;
538
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700539 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700540 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800541 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700542 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800543 public static final int STATE_SIGNAL_STRENGTH_SHIFT = 3;
544 public static final int STATE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700545 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800546 public static final int STATE_PHONE_STATE_SHIFT = 6;
547 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700548 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800549 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800550 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800551
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700552 // These states always appear directly in the first int token
553 // of a delta change; they should be ones that change relatively
554 // frequently.
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800555 public static final int STATE_WAKE_LOCK_FLAG = 1<<31;
556 public static final int STATE_SENSOR_ON_FLAG = 1<<30;
557 public static final int STATE_GPS_ON_FLAG = 1<<29;
558 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -0800559 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800560 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -0800561 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800562 public static final int STATE_WIFI_RUNNING_FLAG = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700563 // These are on the lower bits used for the command; if they change
564 // we need to write another int of data.
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800565 public static final int STATE_PHONE_SCANNING_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700566 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
567 public static final int STATE_VIDEO_ON_FLAG = 1<<21;
568 public static final int STATE_SCREEN_ON_FLAG = 1<<20;
569 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19;
570 public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18;
571 public static final int STATE_WIFI_ON_FLAG = 1<<17;
572 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700573
Dianne Hackbornf47d8f22010-10-08 10:46:55 -0700574 public static final int MOST_INTERESTING_STATES =
575 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
576 | STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG;
577
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700578 public int states;
579
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800580 // The wake lock that was acquired at this point.
581 public HistoryTag wakelockTag;
582
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800583 // Kernel wakeup reason at this point.
584 public HistoryTag wakeReasonTag;
585
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800586 public static final int EVENT_FLAG_START = 0x8000;
587 public static final int EVENT_FLAG_FINISH = 0x4000;
588
589 // No event in this item.
590 public static final int EVENT_NONE = 0x0000;
591 // Event is about a process that is running.
592 public static final int EVENT_PROC = 0x0001;
593 // Event is about an application package that is in the foreground.
594 public static final int EVENT_FOREGROUND = 0x0002;
595 // Event is about an application package that is at the top of the screen.
596 public static final int EVENT_TOP = 0x0003;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -0800597 // Event is about an application package that is at the top of the screen.
598 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800599 // Number of event types.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -0800600 public static final int EVENT_COUNT = 0x0005;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800601
602 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
603 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
604 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
605 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
606 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
607 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -0800608 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
609 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800610
611 // For CMD_EVENT.
612 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800613 public HistoryTag eventTag;
614
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800615 // Only set for CMD_CURRENT_TIME.
616 public long currentTime;
617
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800618 // Meta-data when reading.
619 public int numReadInts;
620
621 // Pre-allocated objects.
622 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800623 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800624 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800625
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700626 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700627 }
628
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700629 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700630 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800631 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700632 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700633 }
634
635 public int describeContents() {
636 return 0;
637 }
638
639 public void writeToParcel(Parcel dest, int flags) {
640 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700641 int bat = (((int)cmd)&0xff)
642 | ((((int)batteryLevel)<<8)&0xff00)
643 | ((((int)batteryStatus)<<16)&0xf0000)
644 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800645 | ((((int)batteryPlugType)<<24)&0xf000000)
646 | (wakelockTag != null ? 0x10000000 : 0)
647 | (wakeReasonTag != null ? 0x20000000 : 0)
648 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700649 dest.writeInt(bat);
650 bat = (((int)batteryTemperature)&0xffff)
651 | ((((int)batteryVoltage)<<16)&0xffff0000);
652 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700653 dest.writeInt(states);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800654 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800655 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800656 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800657 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800658 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800659 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800660 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800661 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800662 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800663 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800664 if (cmd == CMD_CURRENT_TIME) {
665 dest.writeLong(currentTime);
666 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700667 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700668
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800669 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800670 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700671 int bat = src.readInt();
672 cmd = (byte)(bat&0xff);
673 batteryLevel = (byte)((bat>>8)&0xff);
674 batteryStatus = (byte)((bat>>16)&0xf);
675 batteryHealth = (byte)((bat>>20)&0xf);
676 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800677 int bat2 = src.readInt();
678 batteryTemperature = (short)(bat2&0xffff);
679 batteryVoltage = (char)((bat2>>16)&0xffff);
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700680 states = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800681 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800682 wakelockTag = localWakelockTag;
683 wakelockTag.readFromParcel(src);
684 } else {
685 wakelockTag = null;
686 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800687 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800688 wakeReasonTag = localWakeReasonTag;
689 wakeReasonTag.readFromParcel(src);
690 } else {
691 wakeReasonTag = null;
692 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800693 if ((bat&0x40000000) != 0) {
694 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800695 eventTag = localEventTag;
696 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800697 } else {
698 eventCode = EVENT_NONE;
699 eventTag = null;
700 }
701 if (cmd == CMD_CURRENT_TIME) {
702 currentTime = src.readLong();
703 } else {
704 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700705 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800706 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700707 }
708
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700709 public void clear() {
710 time = 0;
711 cmd = CMD_NULL;
712 batteryLevel = 0;
713 batteryStatus = 0;
714 batteryHealth = 0;
715 batteryPlugType = 0;
716 batteryTemperature = 0;
717 batteryVoltage = 0;
718 states = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800719 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800720 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800721 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800722 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700723 }
724
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700725 public void setTo(HistoryItem o) {
726 time = o.time;
727 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800728 setToCommon(o);
729 }
730
731 public void setTo(long time, byte cmd, HistoryItem o) {
732 this.time = time;
733 this.cmd = cmd;
734 setToCommon(o);
735 }
736
737 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700738 batteryLevel = o.batteryLevel;
739 batteryStatus = o.batteryStatus;
740 batteryHealth = o.batteryHealth;
741 batteryPlugType = o.batteryPlugType;
742 batteryTemperature = o.batteryTemperature;
743 batteryVoltage = o.batteryVoltage;
744 states = o.states;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800745 if (o.wakelockTag != null) {
746 wakelockTag = localWakelockTag;
747 wakelockTag.setTo(o.wakelockTag);
748 } else {
749 wakelockTag = null;
750 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800751 if (o.wakeReasonTag != null) {
752 wakeReasonTag = localWakeReasonTag;
753 wakeReasonTag.setTo(o.wakeReasonTag);
754 } else {
755 wakeReasonTag = null;
756 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800757 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800758 if (o.eventTag != null) {
759 eventTag = localEventTag;
760 eventTag.setTo(o.eventTag);
761 } else {
762 eventTag = null;
763 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800764 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700765 }
766
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800767 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700768 return batteryLevel == o.batteryLevel
769 && batteryStatus == o.batteryStatus
770 && batteryHealth == o.batteryHealth
771 && batteryPlugType == o.batteryPlugType
772 && batteryTemperature == o.batteryTemperature
773 && batteryVoltage == o.batteryVoltage
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800774 && states == o.states
775 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700776 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800777
778 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800779 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800780 return false;
781 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800782 if (wakelockTag != o.wakelockTag) {
783 if (wakelockTag == null || o.wakelockTag == null) {
784 return false;
785 }
786 if (!wakelockTag.equals(o.wakelockTag)) {
787 return false;
788 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800789 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800790 if (wakeReasonTag != o.wakeReasonTag) {
791 if (wakeReasonTag == null || o.wakeReasonTag == null) {
792 return false;
793 }
794 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
795 return false;
796 }
797 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800798 if (eventTag != o.eventTag) {
799 if (eventTag == null || o.eventTag == null) {
800 return false;
801 }
802 if (!eventTag.equals(o.eventTag)) {
803 return false;
804 }
805 }
806 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800807 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700808 }
809
810 public static final class BitDescription {
811 public final int mask;
812 public final int shift;
813 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800814 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700815 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800816 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700817
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800818 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700819 this.mask = mask;
820 this.shift = -1;
821 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800822 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700823 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800824 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700825 }
826
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800827 public BitDescription(int mask, int shift, String name, String shortName,
828 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700829 this.mask = mask;
830 this.shift = shift;
831 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800832 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700833 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800834 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700835 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700836 }
837
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800838 public abstract int getHistoryTotalSize();
839
840 public abstract int getHistoryUsedSize();
841
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700842 public abstract boolean startIteratingHistoryLocked();
843
Dianne Hackborn099bc622014-01-22 13:39:16 -0800844 public abstract int getHistoryStringPoolSize();
845
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800846 public abstract int getHistoryStringPoolBytes();
847
848 public abstract String getHistoryTagPoolString(int index);
849
850 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -0800851
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700852 public abstract boolean getNextHistoryLocked(HistoryItem out);
853
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700854 public abstract void finishIteratingHistoryLocked();
855
856 public abstract boolean startIteratingOldHistoryLocked();
857
858 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
859
860 public abstract void finishIteratingOldHistoryLocked();
861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700863 * Return the base time offset for the battery history.
864 */
865 public abstract long getHistoryBaseTime();
866
867 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 * Returns the number of times the device has been started.
869 */
870 public abstract int getStartCount();
871
872 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700873 * Returns the time in microseconds that the screen has been on while the device was
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 * running on battery.
875 *
876 * {@hide}
877 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800878 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879
Dianne Hackborn77b987f2014-02-26 16:20:52 -0800880 /**
881 * Returns the number of times the screen was turned on.
882 *
883 * {@hide}
884 */
885 public abstract int getScreenOnCount(int which);
886
Dianne Hackborn617f8772009-03-31 15:04:46 -0700887 public static final int SCREEN_BRIGHTNESS_DARK = 0;
888 public static final int SCREEN_BRIGHTNESS_DIM = 1;
889 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
890 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
891 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
892
893 static final String[] SCREEN_BRIGHTNESS_NAMES = {
894 "dark", "dim", "medium", "light", "bright"
895 };
896
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800897 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
898 "0", "1", "2", "3", "4"
899 };
900
Dianne Hackborn617f8772009-03-31 15:04:46 -0700901 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
902
903 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700904 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -0700905 * the given brightness
906 *
907 * {@hide}
908 */
909 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800910 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700911
912 public abstract int getInputEventCount(int which);
913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800914 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700915 * Returns the time in microseconds that the phone has been on while the device was
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 * running on battery.
917 *
918 * {@hide}
919 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800920 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -0700921
922 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -0800923 * Returns the number of times a phone call was activated.
924 *
925 * {@hide}
926 */
927 public abstract int getPhoneOnCount(int which);
928
929 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700930 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -0700931 * the given signal strength.
932 *
933 * {@hide}
934 */
935 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800936 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -0700937
Dianne Hackborn617f8772009-03-31 15:04:46 -0700938 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -0700939 * Returns the time in microseconds that the phone has been trying to
940 * acquire a signal.
941 *
942 * {@hide}
943 */
944 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800945 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -0700946
947 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700948 * Returns the number of times the phone has entered the given signal strength.
949 *
950 * {@hide}
951 */
952 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
953
Dianne Hackborne13c4c02014-02-11 17:18:35 -0800954 /**
955 * Returns the time in microseconds that the mobile network has been active
956 * (in a high power state).
957 *
958 * {@hide}
959 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800960 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -0800961
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800962 /**
963 * Returns the number of times that the mobile network has transitioned to the
964 * active state.
965 *
966 * {@hide}
967 */
968 public abstract int getMobileRadioActiveCount(int which);
969
970 /**
971 * Returns the time in microseconds that the mobile network has been active
972 * (in a high power state) but not being able to blame on an app.
973 *
974 * {@hide}
975 */
976 public abstract long getMobileRadioActiveUnknownTime(int which);
977
978 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -0800979 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800980 *
981 * {@hide}
982 */
983 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -0800984
Dianne Hackborn627bba72009-03-24 22:32:56 -0700985 public static final int DATA_CONNECTION_NONE = 0;
986 public static final int DATA_CONNECTION_GPRS = 1;
987 public static final int DATA_CONNECTION_EDGE = 2;
988 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700989 public static final int DATA_CONNECTION_CDMA = 4;
990 public static final int DATA_CONNECTION_EVDO_0 = 5;
991 public static final int DATA_CONNECTION_EVDO_A = 6;
992 public static final int DATA_CONNECTION_1xRTT = 7;
993 public static final int DATA_CONNECTION_HSDPA = 8;
994 public static final int DATA_CONNECTION_HSUPA = 9;
995 public static final int DATA_CONNECTION_HSPA = 10;
996 public static final int DATA_CONNECTION_IDEN = 11;
997 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -0700998 public static final int DATA_CONNECTION_LTE = 13;
999 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001000 public static final int DATA_CONNECTION_HSPAP = 15;
1001 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001002
Dianne Hackborn627bba72009-03-24 22:32:56 -07001003 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001004 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001005 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001006 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001007 };
1008
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001009 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001010
1011 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001012 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001013 * the given data connection.
1014 *
1015 * {@hide}
1016 */
1017 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001018 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001019
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001021 * Returns the number of times the phone has entered the given data
1022 * connection type.
1023 *
1024 * {@hide}
1025 */
1026 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001027
1028 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1029 = new BitDescription[] {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001030 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1031 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001032 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001033 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1034 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1035 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001036 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001037 new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running", "Wr"),
1038 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001039 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
1040 new BitDescription(HistoryItem.STATE_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001041 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1042 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
1043 new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
1044 new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi", "W"),
1045 new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
1046 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1047 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1048 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1049 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1050 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1051 new String[] {"in", "out", "emergency", "off"},
1052 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001053 new BitDescription(HistoryItem.STATE_SIGNAL_STRENGTH_MASK,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001054 HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength", "Pss",
1055 SignalStrength.SIGNAL_STRENGTH_NAMES, new String[] {
1056 "0", "1", "2", "3", "4"
1057 }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001058 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1059 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1060 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001061 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001062
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001063 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001064 "null", "proc", "fg", "top", "sync"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001065 };
1066
1067 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001068 "Enl", "Epr", "Efg", "Etp", "Esy"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001069 };
1070
Dianne Hackborn617f8772009-03-31 15:04:46 -07001071 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001072 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001073 * running on battery.
1074 *
1075 * {@hide}
1076 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001077 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001078
1079 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001080 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001081 * been in the running state while the device was running on battery.
1082 *
1083 * {@hide}
1084 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001085 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001086
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001087 public static final int WIFI_STATE_OFF = 0;
1088 public static final int WIFI_STATE_OFF_SCANNING = 1;
1089 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
1090 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
1091 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
1092 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
1093 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
1094 public static final int WIFI_STATE_SOFT_AP = 7;
1095
1096 static final String[] WIFI_STATE_NAMES = {
1097 "off", "scanning", "no_net", "disconn",
1098 "sta", "p2p", "sta_p2p", "soft_ap"
1099 };
1100
1101 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
1102
1103 /**
1104 * Returns the time in microseconds that WiFi has been running in the given state.
1105 *
1106 * {@hide}
1107 */
1108 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001109 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001110
1111 /**
1112 * Returns the number of times that WiFi has entered the given state.
1113 *
1114 * {@hide}
1115 */
1116 public abstract int getWifiStateCount(int wifiState, int which);
1117
The Android Open Source Project10592532009-03-18 17:39:46 -07001118 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001119 * Returns the time in microseconds that bluetooth has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001120 * running on battery.
1121 *
1122 * {@hide}
1123 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001124 public abstract long getBluetoothOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001125
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001126 public abstract int getBluetoothPingCount();
1127
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001128 public static final int BLUETOOTH_STATE_INACTIVE = 0;
1129 public static final int BLUETOOTH_STATE_LOW = 1;
1130 public static final int BLUETOOTH_STATE_MEDIUM = 2;
1131 public static final int BLUETOOTH_STATE_HIGH = 3;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001132
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001133 static final String[] BLUETOOTH_STATE_NAMES = {
1134 "inactive", "low", "med", "high"
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001135 };
1136
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001137 public static final int NUM_BLUETOOTH_STATES = BLUETOOTH_STATE_HIGH +1;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001138
1139 /**
1140 * Returns the time in microseconds that Bluetooth has been running in the
1141 * given active state.
1142 *
1143 * {@hide}
1144 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001145 public abstract long getBluetoothStateTime(int bluetoothState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001146 long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001147
1148 /**
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001149 * Returns the number of times that Bluetooth has entered the given active state.
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001150 *
1151 * {@hide}
1152 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001153 public abstract int getBluetoothStateCount(int bluetoothState, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001154
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001155 public static final int NETWORK_MOBILE_RX_DATA = 0;
1156 public static final int NETWORK_MOBILE_TX_DATA = 1;
1157 public static final int NETWORK_WIFI_RX_DATA = 2;
1158 public static final int NETWORK_WIFI_TX_DATA = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001159
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001160 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001161
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001162 public abstract long getNetworkActivityBytes(int type, int which);
1163 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001164
The Android Open Source Project10592532009-03-18 17:39:46 -07001165 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08001166 * Return the wall clock time when battery stats data collection started.
1167 */
1168 public abstract long getStartClockTime();
1169
1170 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 * Return whether we are currently running on battery.
1172 */
1173 public abstract boolean getIsOnBattery();
1174
1175 /**
1176 * Returns a SparseArray containing the statistics for each uid.
1177 */
1178 public abstract SparseArray<? extends Uid> getUidStats();
1179
1180 /**
1181 * Returns the current battery uptime in microseconds.
1182 *
1183 * @param curTime the amount of elapsed realtime in microseconds.
1184 */
1185 public abstract long getBatteryUptime(long curTime);
1186
1187 /**
1188 * Returns the current battery realtime in microseconds.
1189 *
1190 * @param curTime the amount of elapsed realtime in microseconds.
1191 */
1192 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001193
1194 /**
Evan Millar633a1742009-04-02 16:36:33 -07001195 * Returns the battery percentage level at the last time the device was unplugged from power, or
1196 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07001197 */
Evan Millar633a1742009-04-02 16:36:33 -07001198 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07001199
1200 /**
Evan Millar633a1742009-04-02 16:36:33 -07001201 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
1202 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07001203 */
Evan Millar633a1742009-04-02 16:36:33 -07001204 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205
1206 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001207 * Get the amount the battery has discharged since the stats were
1208 * last reset after charging, as a lower-end approximation.
1209 */
1210 public abstract int getLowDischargeAmountSinceCharge();
1211
1212 /**
1213 * Get the amount the battery has discharged since the stats were
1214 * last reset after charging, as an upper-end approximation.
1215 */
1216 public abstract int getHighDischargeAmountSinceCharge();
1217
1218 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08001219 * Get the amount the battery has discharged while the screen was on,
1220 * since the last time power was unplugged.
1221 */
1222 public abstract int getDischargeAmountScreenOn();
1223
1224 /**
1225 * Get the amount the battery has discharged while the screen was on,
1226 * since the last time the device was charged.
1227 */
1228 public abstract int getDischargeAmountScreenOnSinceCharge();
1229
1230 /**
1231 * Get the amount the battery has discharged while the screen was off,
1232 * since the last time power was unplugged.
1233 */
1234 public abstract int getDischargeAmountScreenOff();
1235
1236 /**
1237 * Get the amount the battery has discharged while the screen was off,
1238 * since the last time the device was charged.
1239 */
1240 public abstract int getDischargeAmountScreenOffSinceCharge();
1241
1242 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 * Returns the total, last, or current battery uptime in microseconds.
1244 *
1245 * @param curTime the elapsed realtime in microseconds.
1246 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
1247 */
1248 public abstract long computeBatteryUptime(long curTime, int which);
1249
1250 /**
1251 * Returns the total, last, or current battery realtime in microseconds.
1252 *
1253 * @param curTime the current elapsed realtime in microseconds.
1254 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
1255 */
1256 public abstract long computeBatteryRealtime(long curTime, int which);
1257
1258 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001259 * Returns the total, last, or current battery screen off uptime in microseconds.
1260 *
1261 * @param curTime the elapsed realtime in microseconds.
1262 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
1263 */
1264 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
1265
1266 /**
1267 * Returns the total, last, or current battery screen off realtime in microseconds.
1268 *
1269 * @param curTime the current elapsed realtime in microseconds.
1270 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
1271 */
1272 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
1273
1274 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 * Returns the total, last, or current uptime in microseconds.
1276 *
1277 * @param curTime the current elapsed realtime in microseconds.
1278 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
1279 */
1280 public abstract long computeUptime(long curTime, int which);
1281
1282 /**
1283 * Returns the total, last, or current realtime in microseconds.
1284 * *
1285 * @param curTime the current elapsed realtime in microseconds.
1286 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
1287 */
1288 public abstract long computeRealtime(long curTime, int which);
Evan Millarc64edde2009-04-18 12:26:32 -07001289
1290 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291
Amith Yamasanie43530a2009-08-21 13:11:37 -07001292 /** Returns the number of different speeds that the CPU can run at */
1293 public abstract int getCpuSpeedSteps();
1294
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001295 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
1296
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001297 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 long days = seconds / (60 * 60 * 24);
1299 if (days != 0) {
1300 out.append(days);
1301 out.append("d ");
1302 }
1303 long used = days * 60 * 60 * 24;
1304
1305 long hours = (seconds - used) / (60 * 60);
1306 if (hours != 0 || used != 0) {
1307 out.append(hours);
1308 out.append("h ");
1309 }
1310 used += hours * 60 * 60;
1311
1312 long mins = (seconds-used) / 60;
1313 if (mins != 0 || used != 0) {
1314 out.append(mins);
1315 out.append("m ");
1316 }
1317 used += mins * 60;
1318
1319 if (seconds != 0 || used != 0) {
1320 out.append(seconds-used);
1321 out.append("s ");
1322 }
1323 }
1324
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001325 public final static void formatTime(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001326 long sec = time / 100;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001327 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 sb.append((time - (sec * 100)) * 10);
1329 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 }
1331
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001332 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001334 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 sb.append(time - (sec * 1000));
1336 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 }
1338
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001339 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001340 long sec = time / 1000;
1341 formatTimeRaw(sb, sec);
1342 sb.append(time - (sec * 1000));
1343 sb.append("ms");
1344 }
1345
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001346 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001348 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 }
1350 float perc = ((float)num) / ((float)den) * 100;
1351 mFormatBuilder.setLength(0);
1352 mFormatter.format("%.1f%%", perc);
1353 return mFormatBuilder.toString();
1354 }
1355
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001356 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07001357 mFormatBuilder.setLength(0);
1358
1359 if (bytes < BYTES_PER_KB) {
1360 return bytes + "B";
1361 } else if (bytes < BYTES_PER_MB) {
1362 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
1363 return mFormatBuilder.toString();
1364 } else if (bytes < BYTES_PER_GB){
1365 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
1366 return mFormatBuilder.toString();
1367 } else {
1368 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
1369 return mFormatBuilder.toString();
1370 }
1371 }
1372
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001373 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07001374 if (timer != null) {
1375 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001376 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07001377 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
1378 return totalTimeMillis;
1379 }
1380 return 0;
1381 }
1382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 /**
1384 *
1385 * @param sb a StringBuilder object.
1386 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001387 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 * @param name the name of the wakelock.
1389 * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
1390 * @param linePrefix a String to be prepended to each line of output.
1391 * @return the line prefix
1392 */
1393 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001394 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395
1396 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001397 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001398
Evan Millarc64edde2009-04-18 12:26:32 -07001399 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001400 if (totalTimeMillis != 0) {
1401 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001402 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08001403 if (name != null) {
1404 sb.append(name);
1405 sb.append(' ');
1406 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 sb.append('(');
1408 sb.append(count);
1409 sb.append(" times)");
1410 return ", ";
1411 }
1412 }
1413 return linePrefix;
1414 }
1415
1416 /**
1417 * Checkin version of wakelock printer. Prints simple comma-separated list.
1418 *
1419 * @param sb a StringBuilder object.
1420 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001421 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 * @param name the name of the wakelock.
1423 * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
1424 * @param linePrefix a String to be prepended to each line of output.
1425 * @return the line prefix
1426 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001427 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
1428 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 long totalTimeMicros = 0;
1430 int count = 0;
1431 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001432 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07001433 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 }
1435 sb.append(linePrefix);
1436 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
1437 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07001438 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 sb.append(count);
1440 return ",";
1441 }
1442
1443 /**
1444 * Dump a comma-separated line of values for terse checkin mode.
1445 *
1446 * @param pw the PageWriter to dump log to
1447 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
1448 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
1449 * @param args type-dependent data arguments
1450 */
1451 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
1452 Object... args ) {
1453 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
1454 pw.print(uid); pw.print(',');
1455 pw.print(category); pw.print(',');
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001456 pw.print(type);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457
1458 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001459 pw.print(',');
1460 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001462 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 }
1464
1465 /**
1466 * Checkin server version of dump to produce more compact, computer-readable log.
1467 *
1468 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 */
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001470 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 final long rawUptime = SystemClock.uptimeMillis() * 1000;
1472 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
1473 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
1475 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001476 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
1477 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
1478 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 final long totalRealtime = computeRealtime(rawRealtime, which);
1480 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001481 final long screenOnTime = getScreenOnTime(rawRealtime, which);
1482 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
1483 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
1484 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
1485 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486
1487 StringBuilder sb = new StringBuilder(128);
1488
Evan Millar22ac0432009-03-31 11:33:18 -07001489 SparseArray<? extends Uid> uidStats = getUidStats();
1490 final int NU = uidStats.size();
1491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07001493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 // Dump "battery" stat
1495 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001496 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07001497 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08001498 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001499 getStartClockTime(),
1500 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001502 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07001503 long fullWakeLockTimeTotal = 0;
1504 long partialWakeLockTimeTotal = 0;
1505
1506 for (int iu = 0; iu < NU; iu++) {
1507 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001508
Evan Millar22ac0432009-03-31 11:33:18 -07001509 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1510 if (wakelocks.size() > 0) {
1511 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1512 : wakelocks.entrySet()) {
1513 Uid.Wakelock wl = ent.getValue();
1514
1515 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
1516 if (fullWakeTimer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001517 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
1518 which);
Evan Millar22ac0432009-03-31 11:33:18 -07001519 }
1520
1521 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
1522 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001523 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001524 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07001525 }
1526 }
1527 }
1528 }
1529
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001530 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
1531 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
1532 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
1533 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
1534 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
1535 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
1536 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
1537 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
1538
1539 // Dump network stats
1540 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
1541 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
1542 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets);
1543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001544 // Dump misc stats
1545 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001546 screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000,
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001547 wifiRunningTime / 1000, bluetoothOnTime / 1000,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001548 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Dianne Hackborn617f8772009-03-31 15:04:46 -07001549 fullWakeLockTimeTotal, partialWakeLockTimeTotal,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001550 getInputEventCount(which), getMobileRadioActiveTime(rawRealtime, which));
Dianne Hackborn617f8772009-03-31 15:04:46 -07001551
1552 // Dump screen brightness stats
1553 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
1554 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001555 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07001556 }
1557 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07001558
Dianne Hackborn627bba72009-03-24 22:32:56 -07001559 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08001560 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
1561 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001562 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001563 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001564 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001565 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001566 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08001567 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07001568 args[i] = getPhoneSignalStrengthCount(i, which);
1569 }
1570 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001571
Dianne Hackborn627bba72009-03-24 22:32:56 -07001572 // Dump network type stats
1573 args = new Object[NUM_DATA_CONNECTION_TYPES];
1574 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001575 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001576 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001577 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
1578 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1579 args[i] = getPhoneDataConnectionCount(i, which);
1580 }
1581 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001582
1583 // Dump wifi state stats
1584 args = new Object[NUM_WIFI_STATES];
1585 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001586 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001587 }
1588 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
1589 for (int i=0; i<NUM_WIFI_STATES; i++) {
1590 args[i] = getWifiStateCount(i, which);
1591 }
1592 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
1593
1594 // Dump bluetooth state stats
1595 args = new Object[NUM_BLUETOOTH_STATES];
1596 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001597 args[i] = getBluetoothStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001598 }
1599 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_TIME_DATA, args);
1600 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
1601 args[i] = getBluetoothStateCount(i, which);
1602 }
1603 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_COUNT_DATA, args);
1604
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001605 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001606 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07001607 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07001608 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08001610 if (which == STATS_SINCE_UNPLUGGED) {
1611 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
1612 getDischargeStartLevel()-getDischargeCurrentLevel(),
1613 getDischargeStartLevel()-getDischargeCurrentLevel(),
1614 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
1615 } else {
1616 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
1617 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
1618 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
1619 }
1620
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001621 if (reqUid < 0) {
1622 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
1623 if (kernelWakelocks.size() > 0) {
1624 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
1625 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001626 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001627
1628 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
1629 sb.toString());
1630 }
Evan Millarc64edde2009-04-18 12:26:32 -07001631 }
1632 }
1633
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001634 BatteryStatsHelper helper = new BatteryStatsHelper(context);
1635 helper.create(this);
1636 helper.refreshStats(which, UserHandle.USER_ALL);
1637 List<BatterySipper> sippers = helper.getUsageList();
1638 if (sippers != null && sippers.size() > 0) {
1639 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
1640 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08001641 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001642 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
1643 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
1644 for (int i=0; i<sippers.size(); i++) {
1645 BatterySipper bs = sippers.get(i);
1646 int uid = 0;
1647 String label;
1648 switch (bs.drainType) {
1649 case IDLE:
1650 label="idle";
1651 break;
1652 case CELL:
1653 label="cell";
1654 break;
1655 case PHONE:
1656 label="phone";
1657 break;
1658 case WIFI:
1659 label="wifi";
1660 break;
1661 case BLUETOOTH:
1662 label="blue";
1663 break;
1664 case SCREEN:
1665 label="scrn";
1666 break;
1667 case APP:
1668 uid = bs.uidObj.getUid();
1669 label = "uid";
1670 break;
1671 case USER:
1672 uid = UserHandle.getUid(bs.userId, 0);
1673 label = "user";
1674 break;
1675 case UNACCOUNTED:
1676 label = "unacc";
1677 break;
1678 case OVERCOUNTED:
1679 label = "over";
1680 break;
1681 default:
1682 label = "???";
1683 }
1684 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
1685 BatteryStatsHelper.makemAh(bs.value));
1686 }
1687 }
1688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 for (int iu = 0; iu < NU; iu++) {
1690 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001691 if (reqUid >= 0 && uid != reqUid) {
1692 continue;
1693 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 Uid u = uidStats.valueAt(iu);
1695 // Dump Network stats per uid, if any
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001696 long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
1697 long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
1698 long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
1699 long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
1700 long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
1701 long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001702 long mobileActiveTime = u.getMobileRadioActiveTime(which);
1703 int mobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001704 long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
1705 long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001706 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
1707 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
1708 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001709
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001710 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
1711 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001712 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001713 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
1714 wifiBytesRx, wifiBytesTx,
1715 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001716 wifiPacketsRx, wifiPacketsTx,
1717 mobileActiveTime, mobileActiveCount);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001718 }
1719
Nick Pelly6ccaa542012-06-15 15:22:47 -07001720 if (fullWifiLockOnTime != 0 || wifiScanTime != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001721 || uidWifiRunningTime != 0) {
Nick Pelly6ccaa542012-06-15 15:22:47 -07001722 dumpLine(pw, uid, category, WIFI_DATA,
1723 fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001724 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001725
Dianne Hackborn617f8772009-03-31 15:04:46 -07001726 if (u.hasUserActivity()) {
1727 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
1728 boolean hasData = false;
1729 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
1730 int val = u.getUserActivityCount(i, which);
1731 args[i] = val;
1732 if (val != 0) hasData = true;
1733 }
1734 if (hasData) {
1735 dumpLine(pw, 0 /* uid */, category, USER_ACTIVITY_DATA, args);
1736 }
1737 }
1738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001739 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1740 if (wakelocks.size() > 0) {
1741 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1742 : wakelocks.entrySet()) {
1743 Uid.Wakelock wl = ent.getValue();
1744 String linePrefix = "";
1745 sb.setLength(0);
Evan Millarc64edde2009-04-18 12:26:32 -07001746 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001747 rawRealtime, "f", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07001748 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001749 rawRealtime, "p", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07001750 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001751 rawRealtime, "w", which, linePrefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001752
1753 // Only log if we had at lease one wakelock...
1754 if (sb.length() > 0) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001755 String name = ent.getKey();
1756 if (name.indexOf(',') >= 0) {
1757 name = name.replace(',', '_');
1758 }
1759 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001760 }
1761 }
1762 }
1763
1764 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
1765 if (sensors.size() > 0) {
1766 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
1767 : sensors.entrySet()) {
1768 Uid.Sensor se = ent.getValue();
1769 int sensorNumber = ent.getKey();
1770 Timer timer = se.getSensorTime();
1771 if (timer != null) {
1772 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001773 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Evan Millarc64edde2009-04-18 12:26:32 -07001774 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 if (totalTime != 0) {
1776 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
1777 }
1778 }
1779 }
1780 }
1781
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001782 Timer vibTimer = u.getVibratorOnTimer();
1783 if (vibTimer != null) {
1784 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001785 long totalTime = (vibTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001786 int count = vibTimer.getCountLocked(which);
1787 if (totalTime != 0) {
1788 dumpLine(pw, uid, category, VIBRATOR_DATA, totalTime, count);
1789 }
1790 }
1791
Jeff Sharkey3e013e82013-04-25 14:48:19 -07001792 Timer fgTimer = u.getForegroundActivityTimer();
1793 if (fgTimer != null) {
1794 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001795 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07001796 int count = fgTimer.getCountLocked(which);
1797 if (totalTime != 0) {
1798 dumpLine(pw, uid, category, FOREGROUND_DATA, totalTime, count);
1799 }
1800 }
1801
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001802 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
1803 if (processStats.size() > 0) {
1804 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
1805 : processStats.entrySet()) {
1806 Uid.Proc ps = ent.getValue();
Jeff Sharkey3e013e82013-04-25 14:48:19 -07001807
1808 final long userMillis = ps.getUserTime(which) * 10;
1809 final long systemMillis = ps.getSystemTime(which) * 10;
1810 final long foregroundMillis = ps.getForegroundTime(which) * 10;
1811 final long starts = ps.getStarts(which);
1812
1813 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
1814 || starts != 0) {
1815 dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis,
1816 systemMillis, foregroundMillis, starts);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 }
1818 }
1819 }
1820
1821 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
1822 if (packageStats.size() > 0) {
1823 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
1824 : packageStats.entrySet()) {
1825
1826 Uid.Pkg ps = ent.getValue();
1827 int wakeups = ps.getWakeups(which);
1828 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
1829 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
1830 : serviceStats.entrySet()) {
1831 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
1832 long startTime = ss.getStartTime(batteryUptime, which);
1833 int starts = ss.getStarts(which);
1834 int launches = ss.getLaunches(which);
1835 if (startTime != 0 || starts != 0 || launches != 0) {
1836 dumpLine(pw, uid, category, APK_DATA,
1837 wakeups, // wakeup alarms
1838 ent.getKey(), // Apk
1839 sent.getKey(), // service
1840 startTime / 1000, // time spent started, in ms
1841 starts,
1842 launches);
1843 }
1844 }
1845 }
1846 }
1847 }
1848 }
1849
Dianne Hackborn81038902012-11-26 17:04:09 -08001850 static final class TimerEntry {
1851 final String mName;
1852 final int mId;
1853 final BatteryStats.Timer mTimer;
1854 final long mTime;
1855 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
1856 mName = name;
1857 mId = id;
1858 mTimer = timer;
1859 mTime = time;
1860 }
1861 }
1862
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001863 private void printmAh(PrintWriter printer, double power) {
1864 printer.print(BatteryStatsHelper.makemAh(power));
1865 }
1866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001868 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
1869 int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 final long rawUptime = SystemClock.uptimeMillis() * 1000;
1871 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
1872 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001873
1874 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
1875 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
1876 final long totalRealtime = computeRealtime(rawRealtime, which);
1877 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001878 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
1879 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
1880 which);
1881
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882 StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07001883
1884 SparseArray<? extends Uid> uidStats = getUidStats();
1885 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001887 sb.setLength(0);
1888 sb.append(prefix);
1889 sb.append(" Time on battery: ");
1890 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
1891 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
1892 sb.append(") realtime, ");
1893 formatTimeMs(sb, whichBatteryUptime / 1000);
1894 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
1895 sb.append(") uptime");
1896 pw.println(sb.toString());
1897 sb.setLength(0);
1898 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001899 sb.append(" Time on battery screen off: ");
1900 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
1901 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
1902 sb.append(") realtime, ");
1903 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
1904 sb.append("(");
1905 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
1906 sb.append(") uptime");
1907 pw.println(sb.toString());
1908 sb.setLength(0);
1909 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001910 sb.append(" Total run time: ");
1911 formatTimeMs(sb, totalRealtime / 1000);
1912 sb.append("realtime, ");
1913 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001914 sb.append("uptime");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001915 pw.println(sb.toString());
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08001916 pw.print(" Start clock time: ");
1917 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
1918
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001919 final long screenOnTime = getScreenOnTime(rawRealtime, which);
1920 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
1921 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
1922 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
1923 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001924 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001925 sb.append(prefix);
1926 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
1927 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001928 sb.append(") "); sb.append(getScreenOnCount(which));
1929 sb.append("x, Input events: "); sb.append(getInputEventCount(which));
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001930 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001931 if (phoneOnTime != 0) {
1932 sb.setLength(0);
1933 sb.append(prefix);
1934 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
1935 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
1936 sb.append(") "); sb.append(getPhoneOnCount(which));
1937 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001938 sb.setLength(0);
1939 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001940 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07001941 boolean didOne = false;
1942 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001943 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001944 if (time == 0) {
1945 continue;
1946 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001947 sb.append("\n ");
1948 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001949 didOne = true;
1950 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
1951 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001952 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001953 sb.append("(");
1954 sb.append(formatRatioLocked(time, screenOnTime));
1955 sb.append(")");
1956 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001957 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07001958 pw.println(sb.toString());
The Android Open Source Project10592532009-03-18 17:39:46 -07001959
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001960 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07001961 long fullWakeLockTimeTotalMicros = 0;
1962 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08001963
Dianne Hackborn81038902012-11-26 17:04:09 -08001964 final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>();
1965
Evan Millar22ac0432009-03-31 11:33:18 -07001966 for (int iu = 0; iu < NU; iu++) {
1967 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001968
Evan Millar22ac0432009-03-31 11:33:18 -07001969 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1970 if (wakelocks.size() > 0) {
1971 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1972 : wakelocks.entrySet()) {
1973 Uid.Wakelock wl = ent.getValue();
1974
1975 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
1976 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001977 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001978 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07001979 }
1980
1981 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
1982 if (partialWakeTimer != null) {
Dianne Hackborn81038902012-11-26 17:04:09 -08001983 long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001984 rawRealtime, which);
Dianne Hackborn81038902012-11-26 17:04:09 -08001985 if (totalTimeMicros > 0) {
1986 if (reqUid < 0) {
1987 // Only show the ordered list of all wake
1988 // locks if the caller is not asking for data
1989 // about a specific uid.
1990 timers.add(new TimerEntry(ent.getKey(), u.getUid(),
1991 partialWakeTimer, totalTimeMicros));
1992 }
1993 partialWakeLockTimeTotalMicros += totalTimeMicros;
1994 }
Evan Millar22ac0432009-03-31 11:33:18 -07001995 }
1996 }
1997 }
1998 }
1999
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002000 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2001 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2002 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2003 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2004 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2005 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2006 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2007 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
2008
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002009 if (fullWakeLockTimeTotalMicros != 0) {
2010 sb.setLength(0);
2011 sb.append(prefix);
2012 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
2013 (fullWakeLockTimeTotalMicros + 500) / 1000);
2014 pw.println(sb.toString());
2015 }
2016
2017 if (partialWakeLockTimeTotalMicros != 0) {
2018 sb.setLength(0);
2019 sb.append(prefix);
2020 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
2021 (partialWakeLockTimeTotalMicros + 500) / 1000);
2022 pw.println(sb.toString());
2023 }
2024
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002025 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002026 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
2027 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
2028 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
2029 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002030 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002031 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002032 sb.append(" Signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002033 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08002034 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002035 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002036 if (time == 0) {
2037 continue;
2038 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002039 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002040 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002041 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08002042 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002043 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002044 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002045 sb.append("(");
2046 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002047 sb.append(") ");
2048 sb.append(getPhoneSignalStrengthCount(i, which));
2049 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002050 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002051 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002052 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07002053
2054 sb.setLength(0);
2055 sb.append(prefix);
2056 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002057 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002058 pw.println(sb.toString());
2059
Dianne Hackborn627bba72009-03-24 22:32:56 -07002060 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002061 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002062 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002063 didOne = false;
2064 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002065 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002066 if (time == 0) {
2067 continue;
2068 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002069 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002070 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002071 didOne = true;
2072 sb.append(DATA_CONNECTION_NAMES[i]);
2073 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002074 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002075 sb.append("(");
2076 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002077 sb.append(") ");
2078 sb.append(getPhoneDataConnectionCount(i, which));
2079 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002080 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002081 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002082 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07002083
2084 sb.setLength(0);
2085 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002086 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002087 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002088 formatTimeMs(sb, mobileActiveTime / 1000);
2089 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
2090 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
2091 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07002092 pw.println(sb.toString());
2093
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002094 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
2095 if (mobileActiveUnknownTime != 0) {
2096 sb.setLength(0);
2097 sb.append(prefix);
2098 sb.append(" Mobile radio active unknown time: ");
2099 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
2100 sb.append("(");
2101 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
2102 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
2103 sb.append("x");
2104 pw.println(sb.toString());
2105 }
2106
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002107 pw.print(prefix);
2108 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
2109 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
2110 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
2111 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002112 sb.setLength(0);
2113 sb.append(prefix);
2114 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
2115 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
2116 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
2117 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002118 sb.append(")");
2119 pw.println(sb.toString());
2120
2121 sb.setLength(0);
2122 sb.append(prefix);
2123 sb.append(" Wifi states:");
2124 didOne = false;
2125 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002126 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002127 if (time == 0) {
2128 continue;
2129 }
2130 sb.append("\n ");
2131 didOne = true;
2132 sb.append(WIFI_STATE_NAMES[i]);
2133 sb.append(" ");
2134 formatTimeMs(sb, time/1000);
2135 sb.append("(");
2136 sb.append(formatRatioLocked(time, whichBatteryRealtime));
2137 sb.append(") ");
2138 sb.append(getPhoneDataConnectionCount(i, which));
2139 sb.append("x");
2140 }
2141 if (!didOne) sb.append(" (no activity)");
2142 pw.println(sb.toString());
2143
2144 sb.setLength(0);
2145 sb.append(prefix);
2146 sb.append(" Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002147 sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime));
2148 sb.append(")");
2149 pw.println(sb.toString());
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002150
2151 sb.setLength(0);
2152 sb.append(prefix);
2153 sb.append(" Bluetooth states:");
2154 didOne = false;
2155 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002156 final long time = getBluetoothStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002157 if (time == 0) {
2158 continue;
2159 }
2160 sb.append("\n ");
2161 didOne = true;
2162 sb.append(BLUETOOTH_STATE_NAMES[i]);
2163 sb.append(" ");
2164 formatTimeMs(sb, time/1000);
2165 sb.append("(");
2166 sb.append(formatRatioLocked(time, whichBatteryRealtime));
2167 sb.append(") ");
2168 sb.append(getPhoneDataConnectionCount(i, which));
2169 sb.append("x");
2170 }
2171 if (!didOne) sb.append(" (no activity)");
2172 pw.println(sb.toString());
2173
2174 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07002175
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002176 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07002177 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002178 pw.print(prefix); pw.println(" Device is currently unplugged");
2179 pw.print(prefix); pw.print(" Discharge cycle start level: ");
2180 pw.println(getDischargeStartLevel());
2181 pw.print(prefix); pw.print(" Discharge cycle current level: ");
2182 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07002183 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002184 pw.print(prefix); pw.println(" Device is currently plugged into power");
2185 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
2186 pw.println(getDischargeStartLevel());
2187 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
2188 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002189 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002190 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
2191 pw.println(getDischargeAmountScreenOn());
2192 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
2193 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07002194 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002195 } else {
2196 pw.print(prefix); pw.println(" Device battery use since last full charge");
2197 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
2198 pw.println(getLowDischargeAmountSinceCharge());
2199 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
2200 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002201 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
2202 pw.println(getDischargeAmountScreenOnSinceCharge());
2203 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
2204 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08002205 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07002206 }
Dianne Hackborn81038902012-11-26 17:04:09 -08002207
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002208 BatteryStatsHelper helper = new BatteryStatsHelper(context);
2209 helper.create(this);
2210 helper.refreshStats(which, UserHandle.USER_ALL);
2211 List<BatterySipper> sippers = helper.getUsageList();
2212 if (sippers != null && sippers.size() > 0) {
2213 pw.print(prefix); pw.println(" Estimated power use (mAh):");
2214 pw.print(prefix); pw.print(" Capacity: ");
2215 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08002216 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002217 pw.print(", Min drain: "); printmAh(pw, helper.getMinDrainedPower());
2218 pw.print(", Max drain: "); printmAh(pw, helper.getMaxDrainedPower());
2219 pw.println();
2220 for (int i=0; i<sippers.size(); i++) {
2221 BatterySipper bs = sippers.get(i);
2222 switch (bs.drainType) {
2223 case IDLE:
2224 pw.print(prefix); pw.print(" Idle: "); printmAh(pw, bs.value);
2225 pw.println();
2226 break;
2227 case CELL:
2228 pw.print(prefix); pw.print(" Cell standby: "); printmAh(pw, bs.value);
2229 pw.println();
2230 break;
2231 case PHONE:
2232 pw.print(prefix); pw.print(" Phone calls: "); printmAh(pw, bs.value);
2233 pw.println();
2234 break;
2235 case WIFI:
2236 pw.print(prefix); pw.print(" Wifi: "); printmAh(pw, bs.value);
2237 pw.println();
2238 break;
2239 case BLUETOOTH:
2240 pw.print(prefix); pw.print(" Bluetooth: "); printmAh(pw, bs.value);
2241 pw.println();
2242 break;
2243 case SCREEN:
2244 pw.print(prefix); pw.print(" Screen: "); printmAh(pw, bs.value);
2245 pw.println();
2246 break;
2247 case APP:
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002248 pw.print(prefix); pw.print(" Uid ");
2249 UserHandle.formatUid(pw, bs.uidObj.getUid());
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002250 pw.print(": "); printmAh(pw, bs.value); pw.println();
2251 break;
2252 case USER:
2253 pw.print(prefix); pw.print(" User "); pw.print(bs.userId);
2254 pw.print(": "); printmAh(pw, bs.value); pw.println();
2255 break;
2256 case UNACCOUNTED:
2257 pw.print(prefix); pw.print(" Unaccounted: "); printmAh(pw, bs.value);
2258 pw.println();
2259 break;
2260 case OVERCOUNTED:
2261 pw.print(prefix); pw.print(" Over-counted: "); printmAh(pw, bs.value);
2262 pw.println();
2263 break;
2264 }
2265 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08002266 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002267 }
2268
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002269 sippers = helper.getMobilemsppList();
2270 if (sippers != null && sippers.size() > 0) {
2271 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002272 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002273 for (int i=0; i<sippers.size(); i++) {
2274 BatterySipper bs = sippers.get(i);
2275 sb.setLength(0);
2276 sb.append(prefix); sb.append(" Uid ");
2277 UserHandle.formatUid(sb, bs.uidObj.getUid());
2278 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
2279 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
2280 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002281 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002282 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002283 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002284 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002285 sb.setLength(0);
2286 sb.append(prefix);
2287 sb.append(" TOTAL TIME: ");
2288 formatTimeMs(sb, totalTime);
2289 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
2290 sb.append(")");
2291 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002292 pw.println();
2293 }
2294
Dianne Hackbornc51cf032014-03-02 19:08:15 -08002295 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
2296 @Override
2297 public int compare(TimerEntry lhs, TimerEntry rhs) {
2298 long lhsTime = lhs.mTime;
2299 long rhsTime = rhs.mTime;
2300 if (lhsTime < rhsTime) {
2301 return 1;
2302 }
2303 if (lhsTime > rhsTime) {
2304 return -1;
2305 }
2306 return 0;
2307 }
2308 };
2309
2310 if (reqUid < 0) {
2311 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
2312 if (kernelWakelocks.size() > 0) {
2313 final ArrayList<TimerEntry> ktimers = new ArrayList<TimerEntry>();
2314 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
2315 BatteryStats.Timer timer = ent.getValue();
2316 long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
2317 if (totalTimeMillis > 0) {
2318 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
2319 }
2320 }
2321 if (ktimers.size() > 0) {
2322 Collections.sort(ktimers, timerComparator);
2323 pw.print(prefix); pw.println(" All kernel wake locks:");
2324 for (int i=0; i<ktimers.size(); i++) {
2325 TimerEntry timer = ktimers.get(i);
2326 String linePrefix = ": ";
2327 sb.setLength(0);
2328 sb.append(prefix);
2329 sb.append(" Kernel Wake lock ");
2330 sb.append(timer.mName);
2331 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
2332 which, linePrefix);
2333 if (!linePrefix.equals(": ")) {
2334 sb.append(" realtime");
2335 // Only print out wake locks that were held
2336 pw.println(sb.toString());
2337 }
2338 }
2339 pw.println();
2340 }
2341 }
2342 }
2343
Dianne Hackborn81038902012-11-26 17:04:09 -08002344 if (timers.size() > 0) {
2345 Collections.sort(timers, timerComparator);
2346 pw.print(prefix); pw.println(" All partial wake locks:");
2347 for (int i=0; i<timers.size(); i++) {
2348 TimerEntry timer = timers.get(i);
2349 sb.setLength(0);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07002350 sb.append(" Wake lock ");
2351 UserHandle.formatUid(sb, timer.mId);
Dianne Hackborn81038902012-11-26 17:04:09 -08002352 sb.append(" ");
2353 sb.append(timer.mName);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002354 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
Dianne Hackborn81038902012-11-26 17:04:09 -08002355 sb.append(" realtime");
2356 pw.println(sb.toString());
2357 }
2358 timers.clear();
2359 pw.println();
2360 }
Evan Millar22ac0432009-03-31 11:33:18 -07002361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 for (int iu=0; iu<NU; iu++) {
2363 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08002364 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002365 continue;
2366 }
2367
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07002369
2370 pw.print(prefix);
2371 pw.print(" ");
2372 UserHandle.formatUid(pw, uid);
2373 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002375
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002376 long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2377 long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2378 long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2379 long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2380 long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2381 long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002382 long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
2383 int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002384 long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2385 long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002386 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
2387 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
2388 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002389
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002390 if (mobileRxBytes > 0 || mobileTxBytes > 0
2391 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002392 pw.print(prefix); pw.print(" Mobile network: ");
2393 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002394 pw.print(formatBytesLocked(mobileTxBytes));
2395 pw.print(" sent (packets "); pw.print(mobileRxPackets);
2396 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002398 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
2399 sb.setLength(0);
2400 sb.append(prefix); sb.append(" Mobile radio active: ");
2401 formatTimeMs(sb, uidMobileActiveTime / 1000);
2402 sb.append("(");
2403 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
2404 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
2405 long packets = mobileRxPackets + mobileTxPackets;
2406 if (packets == 0) {
2407 packets = 1;
2408 }
2409 sb.append(" @ ");
2410 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
2411 sb.append(" mspp");
2412 pw.println(sb.toString());
2413 }
2414
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002415 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002416 pw.print(prefix); pw.print(" Wi-Fi network: ");
2417 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002418 pw.print(formatBytesLocked(wifiTxBytes));
2419 pw.print(" sent (packets "); pw.print(wifiRxPackets);
2420 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002421 }
2422
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002423 if (fullWifiLockOnTime != 0 || wifiScanTime != 0
2424 || uidWifiRunningTime != 0) {
2425 sb.setLength(0);
2426 sb.append(prefix); sb.append(" Wifi Running: ");
2427 formatTimeMs(sb, uidWifiRunningTime / 1000);
2428 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
2429 whichBatteryRealtime)); sb.append(")\n");
2430 sb.append(prefix); sb.append(" Full Wifi Lock: ");
2431 formatTimeMs(sb, fullWifiLockOnTime / 1000);
2432 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
2433 whichBatteryRealtime)); sb.append(")\n");
2434 sb.append(prefix); sb.append(" Wifi Scan: ");
2435 formatTimeMs(sb, wifiScanTime / 1000);
2436 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
2437 whichBatteryRealtime)); sb.append(")");
2438 pw.println(sb.toString());
2439 }
2440
Dianne Hackborn617f8772009-03-31 15:04:46 -07002441 if (u.hasUserActivity()) {
2442 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07002443 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002444 int val = u.getUserActivityCount(i, which);
2445 if (val != 0) {
2446 if (!hasData) {
2447 sb.setLength(0);
2448 sb.append(" User activity: ");
2449 hasData = true;
2450 } else {
2451 sb.append(", ");
2452 }
2453 sb.append(val);
2454 sb.append(" ");
2455 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
2456 }
2457 }
2458 if (hasData) {
2459 pw.println(sb.toString());
2460 }
2461 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462
2463 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
2464 if (wakelocks.size() > 0) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002465 long totalFull = 0, totalPartial = 0, totalWindow = 0;
2466 int count = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002467 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
2468 : wakelocks.entrySet()) {
2469 Uid.Wakelock wl = ent.getValue();
2470 String linePrefix = ": ";
2471 sb.setLength(0);
2472 sb.append(prefix);
2473 sb.append(" Wake lock ");
2474 sb.append(ent.getKey());
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002475 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476 "full", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002477 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 "partial", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002479 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 "window", which, linePrefix);
2481 if (!linePrefix.equals(": ")) {
2482 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05002483 // Only print out wake locks that were held
2484 pw.println(sb.toString());
2485 uidActivity = true;
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002486 count++;
2487 }
2488 totalFull += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002489 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002490 totalPartial += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002491 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002492 totalWindow += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002493 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002494 }
2495 if (count > 1) {
2496 if (totalFull != 0 || totalPartial != 0 || totalWindow != 0) {
2497 sb.setLength(0);
2498 sb.append(prefix);
2499 sb.append(" TOTAL wake: ");
2500 boolean needComma = false;
2501 if (totalFull != 0) {
2502 needComma = true;
2503 formatTimeMs(sb, totalFull);
2504 sb.append("full");
2505 }
2506 if (totalPartial != 0) {
2507 if (needComma) {
2508 sb.append(", ");
2509 }
2510 needComma = true;
2511 formatTimeMs(sb, totalPartial);
2512 sb.append("partial");
2513 }
2514 if (totalWindow != 0) {
2515 if (needComma) {
2516 sb.append(", ");
2517 }
2518 needComma = true;
2519 formatTimeMs(sb, totalWindow);
2520 sb.append("window");
2521 }
2522 sb.append(" realtime");
2523 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 }
2526 }
2527
2528 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
2529 if (sensors.size() > 0) {
2530 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
2531 : sensors.entrySet()) {
2532 Uid.Sensor se = ent.getValue();
2533 int sensorNumber = ent.getKey();
2534 sb.setLength(0);
2535 sb.append(prefix);
2536 sb.append(" Sensor ");
2537 int handle = se.getHandle();
2538 if (handle == Uid.Sensor.GPS) {
2539 sb.append("GPS");
2540 } else {
2541 sb.append(handle);
2542 }
2543 sb.append(": ");
2544
2545 Timer timer = se.getSensorTime();
2546 if (timer != null) {
2547 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -07002548 long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002549 rawRealtime, which) + 500) / 1000;
Evan Millarc64edde2009-04-18 12:26:32 -07002550 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 //timer.logState();
2552 if (totalTime != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002553 formatTimeMs(sb, totalTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 sb.append("realtime (");
2555 sb.append(count);
2556 sb.append(" times)");
2557 } else {
2558 sb.append("(not used)");
2559 }
2560 } else {
2561 sb.append("(not used)");
2562 }
2563
2564 pw.println(sb.toString());
2565 uidActivity = true;
2566 }
2567 }
2568
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002569 Timer vibTimer = u.getVibratorOnTimer();
2570 if (vibTimer != null) {
2571 // Convert from microseconds to milliseconds with rounding
2572 long totalTime = (vibTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002573 rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002574 int count = vibTimer.getCountLocked(which);
2575 //timer.logState();
2576 if (totalTime != 0) {
2577 sb.setLength(0);
2578 sb.append(prefix);
2579 sb.append(" Vibrator: ");
2580 formatTimeMs(sb, totalTime);
2581 sb.append("realtime (");
2582 sb.append(count);
2583 sb.append(" times)");
2584 pw.println(sb.toString());
2585 uidActivity = true;
2586 }
2587 }
2588
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002589 Timer fgTimer = u.getForegroundActivityTimer();
2590 if (fgTimer != null) {
2591 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002592 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002593 int count = fgTimer.getCountLocked(which);
2594 if (totalTime != 0) {
2595 sb.setLength(0);
2596 sb.append(prefix);
2597 sb.append(" Foreground activities: ");
2598 formatTimeMs(sb, totalTime);
2599 sb.append("realtime (");
2600 sb.append(count);
2601 sb.append(" times)");
2602 pw.println(sb.toString());
2603 uidActivity = true;
2604 }
2605 }
2606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
2608 if (processStats.size() > 0) {
2609 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
2610 : processStats.entrySet()) {
2611 Uid.Proc ps = ent.getValue();
2612 long userTime;
2613 long systemTime;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002614 long foregroundTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002615 int starts;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002616 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617
2618 userTime = ps.getUserTime(which);
2619 systemTime = ps.getSystemTime(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002620 foregroundTime = ps.getForegroundTime(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 starts = ps.getStarts(which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002622 numExcessive = which == STATS_SINCE_CHARGED
Dianne Hackborn287952c2010-09-22 22:34:31 -07002623 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002625 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002626 || numExcessive != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002627 sb.setLength(0);
2628 sb.append(prefix); sb.append(" Proc ");
2629 sb.append(ent.getKey()); sb.append(":\n");
2630 sb.append(prefix); sb.append(" CPU: ");
2631 formatTime(sb, userTime); sb.append("usr + ");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002632 formatTime(sb, systemTime); sb.append("krn ; ");
2633 formatTime(sb, foregroundTime); sb.append("fg");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07002634 if (starts != 0) {
Dianne Hackbornb8071d792010-09-09 16:45:15 -07002635 sb.append("\n"); sb.append(prefix); sb.append(" ");
2636 sb.append(starts); sb.append(" proc starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07002637 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002638 pw.println(sb.toString());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002639 for (int e=0; e<numExcessive; e++) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07002640 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002641 if (ew != null) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07002642 pw.print(prefix); pw.print(" * Killed for ");
2643 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
2644 pw.print("wake lock");
2645 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
2646 pw.print("cpu");
2647 } else {
2648 pw.print("unknown");
2649 }
2650 pw.print(" use: ");
Dianne Hackborn1ebccf52010-08-15 13:04:34 -07002651 TimeUtils.formatDuration(ew.usedTime, pw);
2652 pw.print(" over ");
2653 TimeUtils.formatDuration(ew.overTime, pw);
Robert Greenwalta029ea12013-09-25 16:38:12 -07002654 if (ew.overTime != 0) {
2655 pw.print(" (");
2656 pw.print((ew.usedTime*100)/ew.overTime);
2657 pw.println("%)");
2658 }
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002659 }
2660 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 uidActivity = true;
2662 }
2663 }
2664 }
2665
2666 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
2667 if (packageStats.size() > 0) {
2668 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
2669 : packageStats.entrySet()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002670 pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 boolean apkActivity = false;
2672 Uid.Pkg ps = ent.getValue();
2673 int wakeups = ps.getWakeups(which);
2674 if (wakeups != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002675 pw.print(prefix); pw.print(" ");
2676 pw.print(wakeups); pw.println(" wakeup alarms");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002677 apkActivity = true;
2678 }
2679 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
2680 if (serviceStats.size() > 0) {
2681 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
2682 : serviceStats.entrySet()) {
2683 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
2684 long startTime = ss.getStartTime(batteryUptime, which);
2685 int starts = ss.getStarts(which);
2686 int launches = ss.getLaunches(which);
2687 if (startTime != 0 || starts != 0 || launches != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002688 sb.setLength(0);
2689 sb.append(prefix); sb.append(" Service ");
2690 sb.append(sent.getKey()); sb.append(":\n");
2691 sb.append(prefix); sb.append(" Created for: ");
2692 formatTimeMs(sb, startTime / 1000);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002693 sb.append("uptime\n");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002694 sb.append(prefix); sb.append(" Starts: ");
2695 sb.append(starts);
2696 sb.append(", launches: "); sb.append(launches);
2697 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 apkActivity = true;
2699 }
2700 }
2701 }
2702 if (!apkActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002703 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704 }
2705 uidActivity = true;
2706 }
2707 }
2708 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002709 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002710 }
2711 }
2712 }
2713
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002714 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002715 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002716 int diff = oldval ^ newval;
2717 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002718 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002719 for (int i=0; i<descriptions.length; i++) {
2720 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002721 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002722 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002723 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002724 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002725 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002726 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
2727 didWake = true;
2728 pw.print("=");
2729 if (longNames) {
2730 UserHandle.formatUid(pw, wakelockTag.uid);
2731 pw.print(":\"");
2732 pw.print(wakelockTag.string);
2733 pw.print("\"");
2734 } else {
2735 pw.print(wakelockTag.poolIdx);
2736 }
2737 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002738 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002739 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002740 pw.print("=");
2741 int val = (newval&bd.mask)>>bd.shift;
2742 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002743 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002744 } else {
2745 pw.print(val);
2746 }
2747 }
2748 }
2749 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002750 if (!didWake && wakelockTag != null) {
2751 pw.print(longNames ? "wake_lock=" : "w=");
2752 if (longNames) {
2753 UserHandle.formatUid(pw, wakelockTag.uid);
2754 pw.print(":\"");
2755 pw.print(wakelockTag.string);
2756 pw.print("\"");
2757 } else {
2758 pw.print(wakelockTag.poolIdx);
2759 }
2760 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002761 }
2762
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002763 public void prepareForDumpLocked() {
2764 }
2765
2766 public static class HistoryPrinter {
2767 int oldState = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002768 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002769 int oldStatus = -1;
2770 int oldHealth = -1;
2771 int oldPlug = -1;
2772 int oldTemp = -1;
2773 int oldVolt = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002774 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002775
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002776 public void printNextItem(PrintWriter pw, HistoryItem rec, long now, boolean checkin) {
2777 if (!checkin) {
2778 pw.print(" ");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08002779 if (now >= 0) {
2780 TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
2781 } else {
2782 TimeUtils.formatDuration(rec.time, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
2783 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002784 pw.print(" (");
2785 pw.print(rec.numReadInts);
2786 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002787 } else {
2788 if (lastTime < 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08002789 if (now >= 0) {
2790 pw.print("@");
2791 pw.print(rec.time-now);
2792 } else {
2793 pw.print(rec.time);
2794 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002795 } else {
2796 pw.print(rec.time-lastTime);
2797 }
2798 lastTime = rec.time;
2799 }
2800 if (rec.cmd == HistoryItem.CMD_START) {
2801 if (checkin) {
2802 pw.print(":");
2803 }
2804 pw.println("START");
Dianne Hackborne5167ca2014-03-08 14:39:10 -08002805 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME) {
2806 if (checkin) {
2807 pw.print(":");
2808 }
2809 pw.print("TIME:");
2810 if (checkin) {
2811 pw.println(rec.currentTime);
2812 } else {
2813 pw.print(" ");
2814 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
2815 rec.currentTime).toString());
2816 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002817 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
2818 if (checkin) {
2819 pw.print(":");
2820 }
2821 pw.println("*OVERFLOW*");
2822 } else {
2823 if (!checkin) {
2824 if (rec.batteryLevel < 10) pw.print("00");
2825 else if (rec.batteryLevel < 100) pw.print("0");
2826 pw.print(rec.batteryLevel);
2827 pw.print(" ");
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002828 if (rec.states < 0) ;
2829 else if (rec.states < 0x10) pw.print("0000000");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002830 else if (rec.states < 0x100) pw.print("000000");
2831 else if (rec.states < 0x1000) pw.print("00000");
2832 else if (rec.states < 0x10000) pw.print("0000");
2833 else if (rec.states < 0x100000) pw.print("000");
2834 else if (rec.states < 0x1000000) pw.print("00");
2835 else if (rec.states < 0x10000000) pw.print("0");
2836 pw.print(Integer.toHexString(rec.states));
2837 } else {
2838 if (oldLevel != rec.batteryLevel) {
2839 oldLevel = rec.batteryLevel;
2840 pw.print(",Bl="); pw.print(rec.batteryLevel);
2841 }
2842 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002843 if (oldStatus != rec.batteryStatus) {
2844 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002845 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002846 switch (oldStatus) {
2847 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002848 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002849 break;
2850 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002851 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002852 break;
2853 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002854 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002855 break;
2856 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002857 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002858 break;
2859 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002860 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002861 break;
2862 default:
2863 pw.print(oldStatus);
2864 break;
2865 }
2866 }
2867 if (oldHealth != rec.batteryHealth) {
2868 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002869 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002870 switch (oldHealth) {
2871 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002872 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002873 break;
2874 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002875 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002876 break;
2877 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002878 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002879 break;
2880 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002881 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002882 break;
2883 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002884 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002885 break;
2886 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002887 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002888 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002889 case BatteryManager.BATTERY_HEALTH_COLD:
2890 pw.print(checkin ? "c" : "cold");
2891 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002892 default:
2893 pw.print(oldHealth);
2894 break;
2895 }
2896 }
2897 if (oldPlug != rec.batteryPlugType) {
2898 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002899 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002900 switch (oldPlug) {
2901 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002902 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002903 break;
2904 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002905 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002906 break;
2907 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002908 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002909 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07002910 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002911 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07002912 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002913 default:
2914 pw.print(oldPlug);
2915 break;
2916 }
2917 }
2918 if (oldTemp != rec.batteryTemperature) {
2919 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002920 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002921 pw.print(oldTemp);
2922 }
2923 if (oldVolt != rec.batteryVoltage) {
2924 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002925 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002926 pw.print(oldVolt);
2927 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002928 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002929 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08002930 if (rec.wakeReasonTag != null) {
2931 if (checkin) {
2932 pw.print(",Wr=");
2933 pw.print(rec.wakeReasonTag.poolIdx);
2934 } else {
2935 pw.print(" wake_reason=");
2936 pw.print(rec.wakeReasonTag.uid);
2937 pw.print(":\"");
2938 pw.print(rec.wakeReasonTag.string);
2939 pw.print("\"");
2940 }
2941 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08002942 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002943 pw.print(checkin ? "," : " ");
2944 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
2945 pw.print("+");
2946 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
2947 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08002948 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002949 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
2950 : HISTORY_EVENT_NAMES;
2951 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
2952 | HistoryItem.EVENT_FLAG_FINISH);
2953 if (idx >= 0 && idx < eventNames.length) {
2954 pw.print(eventNames[idx]);
2955 } else {
2956 pw.print(checkin ? "Ev" : "event");
2957 pw.print(idx);
2958 }
2959 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08002960 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002961 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08002962 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002963 UserHandle.formatUid(pw, rec.eventTag.uid);
2964 pw.print(":\"");
2965 pw.print(rec.eventTag.string);
2966 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08002967 }
2968 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002969 pw.println();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08002970 oldState = rec.states;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002971 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002972 }
2973 }
2974
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002975 private void printSizeValue(PrintWriter pw, long size) {
2976 float result = size;
2977 String suffix = "";
2978 if (result >= 10*1024) {
2979 suffix = "KB";
2980 result = result / 1024;
2981 }
2982 if (result >= 10*1024) {
2983 suffix = "MB";
2984 result = result / 1024;
2985 }
2986 if (result >= 10*1024) {
2987 suffix = "GB";
2988 result = result / 1024;
2989 }
2990 if (result >= 10*1024) {
2991 suffix = "TB";
2992 result = result / 1024;
2993 }
2994 if (result >= 10*1024) {
2995 suffix = "PB";
2996 result = result / 1024;
2997 }
2998 pw.print((int)result);
2999 pw.print(suffix);
3000 }
3001
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003002 public static final int DUMP_UNPLUGGED_ONLY = 1<<0;
3003 public static final int DUMP_CHARGED_ONLY = 1<<1;
3004 public static final int DUMP_HISTORY_ONLY = 1<<2;
3005 public static final int DUMP_INCLUDE_HISTORY = 1<<3;
3006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 /**
3008 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
3009 *
3010 * @param pw a Printer to receive the dump output.
3011 */
3012 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003013 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003014 prepareForDumpLocked();
3015
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003016 final boolean filtering =
3017 (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003018
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003019 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
3020 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
3021
3022 final HistoryItem rec = new HistoryItem();
3023 final long historyTotalSize = getHistoryTotalSize();
3024 final long historyUsedSize = getHistoryUsedSize();
3025 if (startIteratingHistoryLocked()) {
3026 try {
3027 pw.print("Battery History (");
3028 pw.print((100*historyUsedSize)/historyTotalSize);
3029 pw.print("% used, ");
3030 printSizeValue(pw, historyUsedSize);
3031 pw.print(" used of ");
3032 printSizeValue(pw, historyTotalSize);
3033 pw.print(", ");
3034 pw.print(getHistoryStringPoolSize());
3035 pw.print(" strings using ");
3036 printSizeValue(pw, getHistoryStringPoolBytes());
3037 pw.println("):");
3038 HistoryPrinter hprinter = new HistoryPrinter();
3039 long lastTime = -1;
3040 while (getNextHistoryLocked(rec)) {
3041 lastTime = rec.time;
3042 if (rec.time >= histStart) {
3043 hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, false);
3044 }
3045 }
3046 if (histStart >= 0) {
3047 pw.print(" NEXT: "); pw.println(lastTime+1);
3048 }
3049 pw.println();
3050 } finally {
3051 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003052 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003053 }
3054
3055 if (startIteratingOldHistoryLocked()) {
3056 try {
3057 pw.println("Old battery History:");
3058 HistoryPrinter hprinter = new HistoryPrinter();
3059 while (getNextOldHistoryLocked(rec)) {
3060 hprinter.printNextItem(pw, rec, now, false);
3061 }
3062 pw.println();
3063 } finally {
3064 finishIteratingOldHistoryLocked();
3065 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003066 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003067 }
3068
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003069 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08003070 return;
3071 }
3072
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003073 if (!filtering) {
3074 SparseArray<? extends Uid> uidStats = getUidStats();
3075 final int NU = uidStats.size();
3076 boolean didPid = false;
3077 long nowRealtime = SystemClock.elapsedRealtime();
3078 for (int i=0; i<NU; i++) {
3079 Uid uid = uidStats.valueAt(i);
3080 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
3081 if (pids != null) {
3082 for (int j=0; j<pids.size(); j++) {
3083 Uid.Pid pid = pids.valueAt(j);
3084 if (!didPid) {
3085 pw.println("Per-PID Stats:");
3086 didPid = true;
3087 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08003088 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
3089 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003090 pw.print(" PID "); pw.print(pids.keyAt(j));
3091 pw.print(" wake time: ");
3092 TimeUtils.formatDuration(time, pw);
3093 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07003094 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07003095 }
3096 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003097 if (didPid) {
3098 pw.println("");
3099 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003100 }
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07003101
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003102 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07003103 pw.println("Statistics since last charge:");
3104 pw.println(" System starts: " + getStartCount()
3105 + ", currently on battery: " + getIsOnBattery());
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003106 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid);
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07003107 pw.println("");
3108 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003109 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
3110 pw.println("Statistics since last unplugged:");
3111 dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid);
3112 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003113 }
3114
3115 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003116 public void dumpCheckinLocked(Context context, PrintWriter pw,
3117 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003118 prepareForDumpLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003119
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003120 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
3121
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003122 final boolean filtering =
3123 (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0;
3124
3125 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07003126 final HistoryItem rec = new HistoryItem();
3127 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003128 try {
3129 for (int i=0; i<getHistoryStringPoolSize(); i++) {
3130 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
3131 pw.print(HISTORY_STRING_POOL); pw.print(',');
3132 pw.print(i);
3133 pw.print(',');
3134 pw.print(getHistoryTagPoolString(i));
3135 pw.print(',');
3136 pw.print(getHistoryTagPoolUid(i));
3137 pw.println();
3138 }
3139 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003140 long lastTime = -1;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003141 while (getNextHistoryLocked(rec)) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003142 lastTime = rec.time;
3143 if (rec.time >= histStart) {
3144 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
3145 pw.print(HISTORY_DATA); pw.print(',');
3146 hprinter.printNextItem(pw, rec, histStart >= 0 ? -1 : now, true);
3147 }
3148 }
3149 if (histStart >= 0) {
3150 pw.print("NEXT: "); pw.println(lastTime+1);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003151 }
3152 } finally {
3153 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08003154 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003155 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003156 }
3157
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003158 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08003159 return;
3160 }
3161
Dianne Hackborne4a59512010-12-07 11:08:07 -08003162 if (apps != null) {
3163 SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
3164 for (int i=0; i<apps.size(); i++) {
3165 ApplicationInfo ai = apps.get(i);
3166 ArrayList<String> pkgs = uids.get(ai.uid);
3167 if (pkgs == null) {
3168 pkgs = new ArrayList<String>();
3169 uids.put(ai.uid, pkgs);
3170 }
3171 pkgs.add(ai.packageName);
3172 }
3173 SparseArray<? extends Uid> uidStats = getUidStats();
3174 final int NU = uidStats.size();
3175 String[] lineArgs = new String[2];
3176 for (int i=0; i<NU; i++) {
3177 int uid = uidStats.keyAt(i);
3178 ArrayList<String> pkgs = uids.get(uid);
3179 if (pkgs != null) {
3180 for (int j=0; j<pkgs.size(); j++) {
3181 lineArgs[0] = Integer.toString(uid);
3182 lineArgs[1] = pkgs.get(j);
3183 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
3184 (Object[])lineArgs);
3185 }
3186 }
3187 }
3188 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003189 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003190 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003191 }
3192 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003193 dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 }
3195 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196}