blob: 95dd14800bf0cc2e1990a7ca620240146fef01b7 [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 Hackborn37de0982014-05-09 09:32:18 -070024import java.util.HashMap;
Dianne Hackborne4a59512010-12-07 11:08:07 -080025import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import java.util.Map;
27
Dianne Hackborna7c837f2014-01-15 16:20:44 -080028import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080029import android.content.pm.ApplicationInfo;
Wink Saville52840902011-02-18 12:40:47 -080030import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080031import android.text.format.DateFormat;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070032import android.util.ArrayMap;
Joe Onorato92fd23f2016-07-25 11:18:42 -070033import android.util.Log;
James Carr2dd7e5e2016-07-20 18:48:39 -070034import android.util.LongSparseArray;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070035import android.util.MutableBoolean;
36import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.util.Printer;
38import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070039import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070040import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070041import android.view.Display;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080042import com.android.internal.os.BatterySipper;
43import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
45/**
46 * A class providing access to battery usage statistics, including information on
47 * wakelocks, processes, packages, and services. All times are represented in microseconds
48 * except where indicated otherwise.
49 * @hide
50 */
51public abstract class BatteryStats implements Parcelable {
Joe Onorato92fd23f2016-07-25 11:18:42 -070052 private static final String TAG = "BatteryStats";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
54 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070055
56 /** @hide */
57 public static final String SERVICE_NAME = "batterystats";
58
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 /**
60 * A constant indicating a partial wake lock timer.
61 */
62 public static final int WAKE_TYPE_PARTIAL = 0;
63
64 /**
65 * A constant indicating a full wake lock timer.
66 */
67 public static final int WAKE_TYPE_FULL = 1;
68
69 /**
70 * A constant indicating a window wake lock timer.
71 */
72 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 /**
75 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 */
77 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070078
79 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070080 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070081 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070082 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070083
84 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070085 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070086 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070087 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070088
89 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070090 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070091 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070092 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
Dianne Hackborn62793e42015-03-09 11:15:41 -070094 /**
95 * A constant indicating a wifi multicast timer
96 */
97 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700100 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700101 */
102 public static final int VIDEO_TURNED_ON = 8;
103
104 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800105 * A constant indicating a vibrator on timer
106 */
107 public static final int VIBRATOR_ON = 9;
108
109 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700110 * A constant indicating a foreground activity timer
111 */
112 public static final int FOREGROUND_ACTIVITY = 10;
113
114 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700115 * A constant indicating a wifi batched scan is active
116 */
117 public static final int WIFI_BATCHED_SCAN = 11;
118
119 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700120 * A constant indicating a process state timer
121 */
122 public static final int PROCESS_STATE = 12;
123
124 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700125 * A constant indicating a sync timer
126 */
127 public static final int SYNC = 13;
128
129 /**
130 * A constant indicating a job timer
131 */
132 public static final int JOB = 14;
133
134 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800135 * A constant indicating an audio turn on timer
136 */
137 public static final int AUDIO_TURNED_ON = 15;
138
139 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700140 * A constant indicating a flashlight turn on timer
141 */
142 public static final int FLASHLIGHT_TURNED_ON = 16;
143
144 /**
145 * A constant indicating a camera turn on timer
146 */
147 public static final int CAMERA_TURNED_ON = 17;
148
149 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700150 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700151 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700152 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700153
154 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800155 * A constant indicating a bluetooth scan timer.
156 */
157 public static final int BLUETOOTH_SCAN_ON = 19;
158
159 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 * Include all of the data in the stats, including previously saved data.
161 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700162 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163
164 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 * Include only the current run in the stats.
166 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700167 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168
169 /**
170 * Include only the run since the last time the device was unplugged in the stats.
171 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700172 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700173
174 // NOTE: Update this list if you add/change any stats above.
175 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700176 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700177 private static final String[] STAT_NAMES = { "l", "c", "u" };
178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700180 * Current version of checkin data format.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700181 *
182 * New in version 19:
183 * - Wakelock data (wl) gets current and max times.
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700184 */
Joe Onorato92fd23f2016-07-25 11:18:42 -0700185 static final String CHECKIN_VERSION = "19";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700186
187 /**
188 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700190 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700191
Evan Millar22ac0432009-03-31 11:33:18 -0700192 private static final long BYTES_PER_KB = 1024;
193 private static final long BYTES_PER_MB = 1048576; // 1024^2
194 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700196 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800197 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700198 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700200 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700201 private static final String CPU_DATA = "cpu";
Evan Millare84de8d2009-04-02 22:16:12 -0700202 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800203 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700204 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700205 private static final String STATE_TIME_DATA = "st";
Evan Millare84de8d2009-04-02 22:16:12 -0700206 private static final String WAKELOCK_DATA = "wl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700207 private static final String SYNC_DATA = "sy";
208 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700209 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700210 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700211 private static final String NETWORK_DATA = "nt";
212 private static final String USER_ACTIVITY_DATA = "ua";
213 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800214 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700215 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700216 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700217 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800218 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
219 private static final String WIFI_CONTROLLER_DATA = "wfcd";
220 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
221 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700222 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700223 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800224 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800225 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
226 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800227 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700228 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700229 private static final String SCREEN_BRIGHTNESS_DATA = "br";
230 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700231 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700232 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
233 private static final String DATA_CONNECTION_TIME_DATA = "dct";
234 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800235 private static final String WIFI_STATE_TIME_DATA = "wst";
236 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700237 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
238 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
239 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
240 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800241 private static final String POWER_USE_SUMMARY_DATA = "pws";
242 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700243 private static final String DISCHARGE_STEP_DATA = "dsd";
244 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700245 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
246 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700247 private static final String FLASHLIGHT_DATA = "fla";
248 private static final String CAMERA_DATA = "cam";
249 private static final String VIDEO_DATA = "vid";
250 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251
Adam Lesinski010bf372016-04-11 12:18:18 -0700252 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
253
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700254 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 private final Formatter mFormatter = new Formatter(mFormatBuilder);
256
257 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700258 * State for keeping track of counting information.
259 */
260 public static abstract class Counter {
261
262 /**
263 * Returns the count associated with this Counter for the
264 * selected type of statistics.
265 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700266 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700267 */
Evan Millarc64edde2009-04-18 12:26:32 -0700268 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700269
270 /**
271 * Temporary for debugging.
272 */
273 public abstract void logState(Printer pw, String prefix);
274 }
275
276 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700277 * State for keeping track of long counting information.
278 */
279 public static abstract class LongCounter {
280
281 /**
282 * Returns the count associated with this Counter for the
283 * selected type of statistics.
284 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700285 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700286 */
287 public abstract long getCountLocked(int which);
288
289 /**
290 * Temporary for debugging.
291 */
292 public abstract void logState(Printer pw, String prefix);
293 }
294
295 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800296 * Container class that aggregates counters for transmit, receive, and idle state of a
297 * radio controller.
298 */
299 public static abstract class ControllerActivityCounter {
300 /**
301 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
302 * idle state.
303 */
304 public abstract LongCounter getIdleTimeCounter();
305
306 /**
307 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
308 * receive state.
309 */
310 public abstract LongCounter getRxTimeCounter();
311
312 /**
313 * An array of {@link LongCounter}, representing various transmit levels, where each level
314 * may draw a different amount of power. The levels themselves are controller-specific.
315 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
316 * various transmit level states.
317 */
318 public abstract LongCounter[] getTxTimeCounters();
319
320 /**
321 * @return a non-null {@link LongCounter} representing the power consumed by the controller
322 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
323 * yield a value of 0 if the device doesn't support power calculations.
324 */
325 public abstract LongCounter getPowerCounter();
326 }
327
328 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 * State for keeping track of timing information.
330 */
331 public static abstract class Timer {
332
333 /**
334 * Returns the count associated with this Timer for the
335 * selected type of statistics.
336 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700337 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 */
Evan Millarc64edde2009-04-18 12:26:32 -0700339 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340
341 /**
342 * Returns the total time in microseconds associated with this Timer for the
343 * selected type of statistics.
344 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800345 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700346 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 * @return a time in microseconds
348 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800349 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700350
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700352 * Returns the total time in microseconds associated with this Timer since the
353 * 'mark' was last set.
354 *
355 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
356 * @return a time in microseconds
357 */
358 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
359
360 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700361 * Returns the max duration if it is being tracked.
362 * Not all Timer subclasses track the max duration and the current duration.
363
364 */
365 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
366 return -1;
367 }
368
369 /**
370 * Returns the current time the timer has been active, if it is being tracked.
371 * Not all Timer subclasses track the max duration and the current duration.
372 */
373 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
374 return -1;
375 }
376
377 /**
378 * Returns whether the timer is currently running. Some types of timers
379 * (e.g. BatchTimers) don't know whether the event is currently active,
380 * and report false.
381 */
382 public boolean isRunningLocked() {
383 return false;
384 }
385
386 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 * Temporary for debugging.
388 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700389 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 }
391
392 /**
393 * The statistics associated with a particular uid.
394 */
395 public static abstract class Uid {
396
397 /**
398 * Returns a mapping containing wakelock statistics.
399 *
400 * @return a Map from Strings to Uid.Wakelock objects.
401 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700402 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403
404 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700405 * Returns a mapping containing sync statistics.
406 *
407 * @return a Map from Strings to Timer objects.
408 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700409 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700410
411 /**
412 * Returns a mapping containing scheduled job statistics.
413 *
414 * @return a Map from Strings to Timer objects.
415 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700416 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700417
418 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 * The statistics associated with a particular wake lock.
420 */
421 public static abstract class Wakelock {
422 public abstract Timer getWakeTime(int type);
423 }
424
425 /**
426 * Returns a mapping containing sensor statistics.
427 *
428 * @return a Map from Integer sensor ids to Uid.Sensor objects.
429 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700430 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431
432 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700433 * Returns a mapping containing active process data.
434 */
435 public abstract SparseArray<? extends Pid> getPidStats();
436
437 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 * Returns a mapping containing process statistics.
439 *
440 * @return a Map from Strings to Uid.Proc objects.
441 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700442 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443
444 /**
445 * Returns a mapping containing package statistics.
446 *
447 * @return a Map from Strings to Uid.Pkg objects.
448 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700449 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700450
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800451 public abstract ControllerActivityCounter getWifiControllerActivity();
452 public abstract ControllerActivityCounter getBluetoothControllerActivity();
453 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800454
455 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 * {@hide}
457 */
458 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700459
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800460 public abstract void noteWifiRunningLocked(long elapsedRealtime);
461 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
462 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
463 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
464 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
465 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
466 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
467 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
468 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
469 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800470 public abstract void noteActivityResumedLocked(long elapsedRealtime);
471 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800472 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
473 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
474 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700475 public abstract int getWifiScanCount(int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800476 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700477 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800478 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700479 public abstract Timer getAudioTurnedOnTimer();
480 public abstract Timer getVideoTurnedOnTimer();
481 public abstract Timer getFlashlightTurnedOnTimer();
482 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700483 public abstract Timer getForegroundActivityTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800484 public abstract Timer getBluetoothScanTimer();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700485
Dianne Hackborna0200e32016-03-30 18:01:41 -0700486 // Note: the following times are disjoint. They can be added together to find the
487 // total time a uid has had any processes running at all.
488
489 /**
490 * Time this uid has any processes in the top state (or above such as persistent).
491 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800492 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700493 /**
494 * Time this uid has any process with a started out bound foreground service, but
495 * none in the "top" state.
496 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800497 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700498 /**
499 * Time this uid has any process that is top while the device is sleeping, but none
500 * in the "foreground service" or better state.
501 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800502 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700503 /**
504 * Time this uid has any process in an active foreground state, but none in the
505 * "top sleeping" or better state.
506 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800507 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700508 /**
509 * Time this uid has any process in an active background state, but none in the
510 * "foreground" or better state.
511 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800512 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700513 /**
514 * Time this uid has any processes that are sitting around cached, not in one of the
515 * other active states.
516 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800517 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700518 /**
519 * Total number of process states we track.
520 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800521 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700522
523 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800524 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700525 };
526
527 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800528 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700529
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800530 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531
Robert Greenwalta029ea12013-09-25 16:38:12 -0700532 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
533
Dianne Hackborn617f8772009-03-31 15:04:46 -0700534 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700535 * Note that these must match the constants in android.os.PowerManager.
536 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
537 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700538 */
539 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700540 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700541 };
542
Phil Weaverda80d672016-03-15 16:25:46 -0700543 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700544
Dianne Hackborn617f8772009-03-31 15:04:46 -0700545 public abstract void noteUserActivityLocked(int type);
546 public abstract boolean hasUserActivity();
547 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700548
549 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800550 public abstract long getNetworkActivityBytes(int type, int which);
551 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800552 public abstract long getMobileRadioActiveTime(int which);
553 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700554
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700555 /**
556 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
557 */
558 public abstract long getUserCpuTimeUs(int which);
559
560 /**
561 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
562 */
563 public abstract long getSystemCpuTimeUs(int which);
564
565 /**
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700566 * Get the total cpu power consumed (in milli-ampere-microseconds).
567 */
568 public abstract long getCpuPowerMaUs(int which);
569
570 /**
Adam Lesinski6832f392015-09-05 18:05:40 -0700571 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a
572 * given CPU cluster.
573 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700574 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700575 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700576 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
577 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700578 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700579 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700580
Adam Lesinski5f056f62016-07-14 16:56:08 -0700581 /**
582 * Returns the number of times this UID woke up the Application Processor to
583 * process a mobile radio packet.
584 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
585 */
586 public abstract long getMobileRadioApWakeupCount(int which);
587
588 /**
589 * Returns the number of times this UID woke up the Application Processor to
590 * process a WiFi packet.
591 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
592 */
593 public abstract long getWifiRadioApWakeupCount(int which);
594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800596 /*
597 * FIXME: it's not correct to use this magic value because it
598 * could clash with a sensor handle (which are defined by
599 * the sensor HAL, and therefore out of our control
600 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 // Magic sensor number for the GPS.
602 public static final int GPS = -10000;
603
604 public abstract int getHandle();
605
606 public abstract Timer getSensorTime();
607 }
608
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700609 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800610 public int mWakeNesting;
611 public long mWakeSumMs;
612 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700613 }
614
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 /**
616 * The statistics associated with a particular process.
617 */
618 public static abstract class Proc {
619
Dianne Hackborn287952c2010-09-22 22:34:31 -0700620 public static class ExcessivePower {
621 public static final int TYPE_WAKE = 1;
622 public static final int TYPE_CPU = 2;
623
624 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700625 public long overTime;
626 public long usedTime;
627 }
628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800630 * Returns true if this process is still active in the battery stats.
631 */
632 public abstract boolean isActive();
633
634 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700635 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700637 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 */
639 public abstract long getUserTime(int which);
640
641 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700642 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700644 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 */
646 public abstract long getSystemTime(int which);
647
648 /**
649 * Returns the number of times the process has been started.
650 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700651 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 */
653 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700654
655 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800656 * Returns the number of times the process has crashed.
657 *
658 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
659 */
660 public abstract int getNumCrashes(int which);
661
662 /**
663 * Returns the number of times the process has ANRed.
664 *
665 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
666 */
667 public abstract int getNumAnrs(int which);
668
669 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700670 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700671 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700672 * @return foreground cpu time in microseconds
673 */
674 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700675
Dianne Hackborn287952c2010-09-22 22:34:31 -0700676 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700677
Dianne Hackborn287952c2010-09-22 22:34:31 -0700678 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 }
680
681 /**
682 * The statistics associated with a particular package.
683 */
684 public static abstract class Pkg {
685
686 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700687 * Returns information about all wakeup alarms that have been triggered for this
688 * package. The mapping keys are tag names for the alarms, the counter contains
689 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700691 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692
693 /**
694 * Returns a mapping containing service statistics.
695 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700696 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697
698 /**
699 * The statistics associated with a particular service.
700 */
Joe Onoratoabded112016-02-08 16:49:39 -0800701 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702
703 /**
704 * Returns the amount of time spent started.
705 *
706 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700707 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 * @return
709 */
710 public abstract long getStartTime(long batteryUptime, int which);
711
712 /**
713 * Returns the total number of times startService() has been called.
714 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700715 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 */
717 public abstract int getStarts(int which);
718
719 /**
720 * Returns the total number times the service has been launched.
721 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700722 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 */
724 public abstract int getLaunches(int which);
725 }
726 }
727 }
728
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800729 public static final class LevelStepTracker {
730 public long mLastStepTime = -1;
731 public int mNumStepDurations;
732 public final long[] mStepDurations;
733
734 public LevelStepTracker(int maxLevelSteps) {
735 mStepDurations = new long[maxLevelSteps];
736 }
737
738 public LevelStepTracker(int numSteps, long[] steps) {
739 mNumStepDurations = numSteps;
740 mStepDurations = new long[numSteps];
741 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
742 }
743
744 public long getDurationAt(int index) {
745 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
746 }
747
748 public int getLevelAt(int index) {
749 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
750 >> STEP_LEVEL_LEVEL_SHIFT);
751 }
752
753 public int getInitModeAt(int index) {
754 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
755 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
756 }
757
758 public int getModModeAt(int index) {
759 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
760 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
761 }
762
763 private void appendHex(long val, int topOffset, StringBuilder out) {
764 boolean hasData = false;
765 while (topOffset >= 0) {
766 int digit = (int)( (val>>topOffset) & 0xf );
767 topOffset -= 4;
768 if (!hasData && digit == 0) {
769 continue;
770 }
771 hasData = true;
772 if (digit >= 0 && digit <= 9) {
773 out.append((char)('0' + digit));
774 } else {
775 out.append((char)('a' + digit - 10));
776 }
777 }
778 }
779
780 public void encodeEntryAt(int index, StringBuilder out) {
781 long item = mStepDurations[index];
782 long duration = item & STEP_LEVEL_TIME_MASK;
783 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
784 >> STEP_LEVEL_LEVEL_SHIFT);
785 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
786 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
787 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
788 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
789 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
790 case Display.STATE_OFF: out.append('f'); break;
791 case Display.STATE_ON: out.append('o'); break;
792 case Display.STATE_DOZE: out.append('d'); break;
793 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
794 }
795 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
796 out.append('p');
797 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700798 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
799 out.append('i');
800 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800801 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
802 case Display.STATE_OFF: out.append('F'); break;
803 case Display.STATE_ON: out.append('O'); break;
804 case Display.STATE_DOZE: out.append('D'); break;
805 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
806 }
807 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
808 out.append('P');
809 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700810 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
811 out.append('I');
812 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800813 out.append('-');
814 appendHex(level, 4, out);
815 out.append('-');
816 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
817 }
818
819 public void decodeEntryAt(int index, String value) {
820 final int N = value.length();
821 int i = 0;
822 char c;
823 long out = 0;
824 while (i < N && (c=value.charAt(i)) != '-') {
825 i++;
826 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800827 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800828 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800829 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800830 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800831 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800832 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800833 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
834 << STEP_LEVEL_INITIAL_MODE_SHIFT);
835 break;
836 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
837 << STEP_LEVEL_INITIAL_MODE_SHIFT);
838 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700839 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
840 << STEP_LEVEL_INITIAL_MODE_SHIFT);
841 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800842 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
843 break;
844 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
845 break;
846 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
847 break;
848 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
849 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
850 break;
851 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
852 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800853 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700854 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
855 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
856 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800857 }
858 }
859 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800860 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800861 while (i < N && (c=value.charAt(i)) != '-') {
862 i++;
863 level <<= 4;
864 if (c >= '0' && c <= '9') {
865 level += c - '0';
866 } else if (c >= 'a' && c <= 'f') {
867 level += c - 'a' + 10;
868 } else if (c >= 'A' && c <= 'F') {
869 level += c - 'A' + 10;
870 }
871 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800872 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800873 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
874 long duration = 0;
875 while (i < N && (c=value.charAt(i)) != '-') {
876 i++;
877 duration <<= 4;
878 if (c >= '0' && c <= '9') {
879 duration += c - '0';
880 } else if (c >= 'a' && c <= 'f') {
881 duration += c - 'a' + 10;
882 } else if (c >= 'A' && c <= 'F') {
883 duration += c - 'A' + 10;
884 }
885 }
886 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
887 }
888
889 public void init() {
890 mLastStepTime = -1;
891 mNumStepDurations = 0;
892 }
893
894 public void clearTime() {
895 mLastStepTime = -1;
896 }
897
898 public long computeTimePerLevel() {
899 final long[] steps = mStepDurations;
900 final int numSteps = mNumStepDurations;
901
902 // For now we'll do a simple average across all steps.
903 if (numSteps <= 0) {
904 return -1;
905 }
906 long total = 0;
907 for (int i=0; i<numSteps; i++) {
908 total += steps[i] & STEP_LEVEL_TIME_MASK;
909 }
910 return total / numSteps;
911 /*
912 long[] buckets = new long[numSteps];
913 int numBuckets = 0;
914 int numToAverage = 4;
915 int i = 0;
916 while (i < numSteps) {
917 long totalTime = 0;
918 int num = 0;
919 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
920 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
921 num++;
922 }
923 buckets[numBuckets] = totalTime / num;
924 numBuckets++;
925 numToAverage *= 2;
926 i += num;
927 }
928 if (numBuckets < 1) {
929 return -1;
930 }
931 long averageTime = buckets[numBuckets-1];
932 for (i=numBuckets-2; i>=0; i--) {
933 averageTime = (averageTime + buckets[i]) / 2;
934 }
935 return averageTime;
936 */
937 }
938
939 public long computeTimeEstimate(long modesOfInterest, long modeValues,
940 int[] outNumOfInterest) {
941 final long[] steps = mStepDurations;
942 final int count = mNumStepDurations;
943 if (count <= 0) {
944 return -1;
945 }
946 long total = 0;
947 int numOfInterest = 0;
948 for (int i=0; i<count; i++) {
949 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
950 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
951 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
952 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
953 // If the modes of interest didn't change during this step period...
954 if ((modMode&modesOfInterest) == 0) {
955 // And the mode values during this period match those we are measuring...
956 if ((initMode&modesOfInterest) == modeValues) {
957 // Then this can be used to estimate the total time!
958 numOfInterest++;
959 total += steps[i] & STEP_LEVEL_TIME_MASK;
960 }
961 }
962 }
963 if (numOfInterest <= 0) {
964 return -1;
965 }
966
967 if (outNumOfInterest != null) {
968 outNumOfInterest[0] = numOfInterest;
969 }
970
971 // The estimated time is the average time we spend in each level, multipled
972 // by 100 -- the total number of battery levels
973 return (total / numOfInterest) * 100;
974 }
975
976 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
977 int stepCount = mNumStepDurations;
978 final long lastStepTime = mLastStepTime;
979 if (lastStepTime >= 0 && numStepLevels > 0) {
980 final long[] steps = mStepDurations;
981 long duration = elapsedRealtime - lastStepTime;
982 for (int i=0; i<numStepLevels; i++) {
983 System.arraycopy(steps, 0, steps, 1, steps.length-1);
984 long thisDuration = duration / (numStepLevels-i);
985 duration -= thisDuration;
986 if (thisDuration > STEP_LEVEL_TIME_MASK) {
987 thisDuration = STEP_LEVEL_TIME_MASK;
988 }
989 steps[0] = thisDuration | modeBits;
990 }
991 stepCount += numStepLevels;
992 if (stepCount > steps.length) {
993 stepCount = steps.length;
994 }
995 }
996 mNumStepDurations = stepCount;
997 mLastStepTime = elapsedRealtime;
998 }
999
1000 public void readFromParcel(Parcel in) {
1001 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001002 if (N > mStepDurations.length) {
1003 throw new ParcelFormatException("more step durations than available: " + N);
1004 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001005 mNumStepDurations = N;
1006 for (int i=0; i<N; i++) {
1007 mStepDurations[i] = in.readLong();
1008 }
1009 }
1010
1011 public void writeToParcel(Parcel out) {
1012 final int N = mNumStepDurations;
1013 out.writeInt(N);
1014 for (int i=0; i<N; i++) {
1015 out.writeLong(mStepDurations[i]);
1016 }
1017 }
1018 }
1019
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001020 public static final class PackageChange {
1021 public String mPackageName;
1022 public boolean mUpdate;
1023 public int mVersionCode;
1024 }
1025
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001026 public static final class DailyItem {
1027 public long mStartTime;
1028 public long mEndTime;
1029 public LevelStepTracker mDischargeSteps;
1030 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001031 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001032 }
1033
1034 public abstract DailyItem getDailyItemLocked(int daysAgo);
1035
1036 public abstract long getCurrentDailyStartTime();
1037
1038 public abstract long getNextMinDailyDeadline();
1039
1040 public abstract long getNextMaxDailyDeadline();
1041
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001042 public final static class HistoryTag {
1043 public String string;
1044 public int uid;
1045
1046 public int poolIdx;
1047
1048 public void setTo(HistoryTag o) {
1049 string = o.string;
1050 uid = o.uid;
1051 poolIdx = o.poolIdx;
1052 }
1053
1054 public void setTo(String _string, int _uid) {
1055 string = _string;
1056 uid = _uid;
1057 poolIdx = -1;
1058 }
1059
1060 public void writeToParcel(Parcel dest, int flags) {
1061 dest.writeString(string);
1062 dest.writeInt(uid);
1063 }
1064
1065 public void readFromParcel(Parcel src) {
1066 string = src.readString();
1067 uid = src.readInt();
1068 poolIdx = -1;
1069 }
1070
1071 @Override
1072 public boolean equals(Object o) {
1073 if (this == o) return true;
1074 if (o == null || getClass() != o.getClass()) return false;
1075
1076 HistoryTag that = (HistoryTag) o;
1077
1078 if (uid != that.uid) return false;
1079 if (!string.equals(that.string)) return false;
1080
1081 return true;
1082 }
1083
1084 @Override
1085 public int hashCode() {
1086 int result = string.hashCode();
1087 result = 31 * result + uid;
1088 return result;
1089 }
1090 }
1091
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001092 /**
1093 * Optional detailed information that can go into a history step. This is typically
1094 * generated each time the battery level changes.
1095 */
1096 public final static class HistoryStepDetails {
1097 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1098 public int userTime;
1099 public int systemTime;
1100
1101 // Top three apps using CPU in the last step, with times in 1/100 second.
1102 public int appCpuUid1;
1103 public int appCpuUTime1;
1104 public int appCpuSTime1;
1105 public int appCpuUid2;
1106 public int appCpuUTime2;
1107 public int appCpuSTime2;
1108 public int appCpuUid3;
1109 public int appCpuUTime3;
1110 public int appCpuSTime3;
1111
1112 // Information from /proc/stat
1113 public int statUserTime;
1114 public int statSystemTime;
1115 public int statIOWaitTime;
1116 public int statIrqTime;
1117 public int statSoftIrqTime;
1118 public int statIdlTime;
1119
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001120 // Platform-level low power state stats
1121 public String statPlatformIdleState;
1122
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001123 public HistoryStepDetails() {
1124 clear();
1125 }
1126
1127 public void clear() {
1128 userTime = systemTime = 0;
1129 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1130 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1131 = appCpuUTime3 = appCpuSTime3 = 0;
1132 }
1133
1134 public void writeToParcel(Parcel out) {
1135 out.writeInt(userTime);
1136 out.writeInt(systemTime);
1137 out.writeInt(appCpuUid1);
1138 out.writeInt(appCpuUTime1);
1139 out.writeInt(appCpuSTime1);
1140 out.writeInt(appCpuUid2);
1141 out.writeInt(appCpuUTime2);
1142 out.writeInt(appCpuSTime2);
1143 out.writeInt(appCpuUid3);
1144 out.writeInt(appCpuUTime3);
1145 out.writeInt(appCpuSTime3);
1146 out.writeInt(statUserTime);
1147 out.writeInt(statSystemTime);
1148 out.writeInt(statIOWaitTime);
1149 out.writeInt(statIrqTime);
1150 out.writeInt(statSoftIrqTime);
1151 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001152 out.writeString(statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001153 }
1154
1155 public void readFromParcel(Parcel in) {
1156 userTime = in.readInt();
1157 systemTime = in.readInt();
1158 appCpuUid1 = in.readInt();
1159 appCpuUTime1 = in.readInt();
1160 appCpuSTime1 = in.readInt();
1161 appCpuUid2 = in.readInt();
1162 appCpuUTime2 = in.readInt();
1163 appCpuSTime2 = in.readInt();
1164 appCpuUid3 = in.readInt();
1165 appCpuUTime3 = in.readInt();
1166 appCpuSTime3 = in.readInt();
1167 statUserTime = in.readInt();
1168 statSystemTime = in.readInt();
1169 statIOWaitTime = in.readInt();
1170 statIrqTime = in.readInt();
1171 statSoftIrqTime = in.readInt();
1172 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001173 statPlatformIdleState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001174 }
1175 }
1176
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001177 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001178 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001179
1180 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001181 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001182
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001183 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001184 public static final byte CMD_NULL = -1;
1185 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001186 public static final byte CMD_CURRENT_TIME = 5;
1187 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001188 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001189 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001190
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001191 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001192
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001193 /**
1194 * Return whether the command code is a delta data update.
1195 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001196 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001197 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001198 }
1199
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001200 public byte batteryLevel;
1201 public byte batteryStatus;
1202 public byte batteryHealth;
1203 public byte batteryPlugType;
1204
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001205 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001206 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001207
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001208 // The charge of the battery in micro-Ampere-hours.
1209 public int batteryChargeUAh;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001210
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001211 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001212 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001213 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001214 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001215 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1216 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001217 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001218 public static final int STATE_PHONE_STATE_SHIFT = 6;
1219 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001220 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001221 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001222 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001223
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001224 // These states always appear directly in the first int token
1225 // of a delta change; they should be ones that change relatively
1226 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001227 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1228 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001229 public static final int STATE_GPS_ON_FLAG = 1<<29;
1230 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001231 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001232 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001233 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001234 // Do not use, this is used for coulomb delta count.
1235 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001236 // These are on the lower bits used for the command; if they change
1237 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001238 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001239 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001240 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001241 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1242 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1243 // empty slot
1244 // empty slot
1245 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001246
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001247 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001248 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1249
1250 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001251
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001252 public int states;
1253
Dianne Hackborn3251b902014-06-20 14:40:53 -07001254 // Constants from WIFI_SUPPL_STATE_*
1255 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1256 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1257 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1258 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1259 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1260 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1261
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001262 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001263 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1264 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1265 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001266 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001267 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1268 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1269 public static final int STATE2_CHARGING_FLAG = 1<<24;
1270 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1271 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1272 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001273 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001274
1275 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001276 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001277 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1278
1279 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001280
Dianne Hackborn40c87252014-03-19 16:55:40 -07001281 public int states2;
1282
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001283 // The wake lock that was acquired at this point.
1284 public HistoryTag wakelockTag;
1285
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001286 // Kernel wakeup reason at this point.
1287 public HistoryTag wakeReasonTag;
1288
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001289 // Non-null when there is more detailed information at this step.
1290 public HistoryStepDetails stepDetails;
1291
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001292 public static final int EVENT_FLAG_START = 0x8000;
1293 public static final int EVENT_FLAG_FINISH = 0x4000;
1294
1295 // No event in this item.
1296 public static final int EVENT_NONE = 0x0000;
1297 // Event is about a process that is running.
1298 public static final int EVENT_PROC = 0x0001;
1299 // Event is about an application package that is in the foreground.
1300 public static final int EVENT_FOREGROUND = 0x0002;
1301 // Event is about an application package that is at the top of the screen.
1302 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001303 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001304 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001305 // Events for all additional wake locks aquired/release within a wake block.
1306 // These are not generated by default.
1307 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001308 // Event is about an application executing a scheduled job.
1309 public static final int EVENT_JOB = 0x0006;
1310 // Events for users running.
1311 public static final int EVENT_USER_RUNNING = 0x0007;
1312 // Events for foreground user.
1313 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001314 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001315 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001316 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001317 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001318 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001319 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001320 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001321 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001322 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001323 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001324 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001325 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001326 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001327 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001328 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001329 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001330 // Event for a package being on the temporary whitelist.
1331 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001332 // Event for the screen waking up.
1333 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001334 // Event for the UID that woke up the application processor.
1335 // Used for wakeups coming from WiFi, modem, etc.
1336 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001337 // Event for reporting that a specific partial wake lock has been held for a long duration.
1338 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001339
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001340 // Number of event types.
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001341 public static final int EVENT_COUNT = 0x0015;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001342 // Mask to extract out only the type part of the event.
1343 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001344
1345 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1346 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1347 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1348 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1349 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1350 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001351 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1352 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001353 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1354 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001355 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1356 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1357 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1358 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1359 public static final int EVENT_USER_FOREGROUND_START =
1360 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1361 public static final int EVENT_USER_FOREGROUND_FINISH =
1362 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001363 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1364 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001365 public static final int EVENT_TEMP_WHITELIST_START =
1366 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1367 public static final int EVENT_TEMP_WHITELIST_FINISH =
1368 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001369 public static final int EVENT_LONG_WAKE_LOCK_START =
1370 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1371 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1372 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001373
1374 // For CMD_EVENT.
1375 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001376 public HistoryTag eventTag;
1377
Dianne Hackborn9a755432014-05-15 17:05:22 -07001378 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001379 public long currentTime;
1380
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001381 // Meta-data when reading.
1382 public int numReadInts;
1383
1384 // Pre-allocated objects.
1385 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001386 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001387 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001388
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001389 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001390 }
1391
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001392 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001393 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001394 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001395 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001396 }
1397
1398 public int describeContents() {
1399 return 0;
1400 }
1401
1402 public void writeToParcel(Parcel dest, int flags) {
1403 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001404 int bat = (((int)cmd)&0xff)
1405 | ((((int)batteryLevel)<<8)&0xff00)
1406 | ((((int)batteryStatus)<<16)&0xf0000)
1407 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001408 | ((((int)batteryPlugType)<<24)&0xf000000)
1409 | (wakelockTag != null ? 0x10000000 : 0)
1410 | (wakeReasonTag != null ? 0x20000000 : 0)
1411 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001412 dest.writeInt(bat);
1413 bat = (((int)batteryTemperature)&0xffff)
1414 | ((((int)batteryVoltage)<<16)&0xffff0000);
1415 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001416 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001417 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001418 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001419 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001420 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001421 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001422 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001423 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001424 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001425 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001426 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001427 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001428 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001429 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001430 dest.writeLong(currentTime);
1431 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001432 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001433
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001434 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001435 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001436 int bat = src.readInt();
1437 cmd = (byte)(bat&0xff);
1438 batteryLevel = (byte)((bat>>8)&0xff);
1439 batteryStatus = (byte)((bat>>16)&0xf);
1440 batteryHealth = (byte)((bat>>20)&0xf);
1441 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001442 int bat2 = src.readInt();
1443 batteryTemperature = (short)(bat2&0xffff);
1444 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001445 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001446 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001447 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001448 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001449 wakelockTag = localWakelockTag;
1450 wakelockTag.readFromParcel(src);
1451 } else {
1452 wakelockTag = null;
1453 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001454 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001455 wakeReasonTag = localWakeReasonTag;
1456 wakeReasonTag.readFromParcel(src);
1457 } else {
1458 wakeReasonTag = null;
1459 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001460 if ((bat&0x40000000) != 0) {
1461 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001462 eventTag = localEventTag;
1463 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001464 } else {
1465 eventCode = EVENT_NONE;
1466 eventTag = null;
1467 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001468 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001469 currentTime = src.readLong();
1470 } else {
1471 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001472 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001473 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001474 }
1475
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001476 public void clear() {
1477 time = 0;
1478 cmd = CMD_NULL;
1479 batteryLevel = 0;
1480 batteryStatus = 0;
1481 batteryHealth = 0;
1482 batteryPlugType = 0;
1483 batteryTemperature = 0;
1484 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001485 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001486 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001487 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001488 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001489 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001490 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001491 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001492 }
1493
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001494 public void setTo(HistoryItem o) {
1495 time = o.time;
1496 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001497 setToCommon(o);
1498 }
1499
1500 public void setTo(long time, byte cmd, HistoryItem o) {
1501 this.time = time;
1502 this.cmd = cmd;
1503 setToCommon(o);
1504 }
1505
1506 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001507 batteryLevel = o.batteryLevel;
1508 batteryStatus = o.batteryStatus;
1509 batteryHealth = o.batteryHealth;
1510 batteryPlugType = o.batteryPlugType;
1511 batteryTemperature = o.batteryTemperature;
1512 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001513 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001514 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001515 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001516 if (o.wakelockTag != null) {
1517 wakelockTag = localWakelockTag;
1518 wakelockTag.setTo(o.wakelockTag);
1519 } else {
1520 wakelockTag = null;
1521 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001522 if (o.wakeReasonTag != null) {
1523 wakeReasonTag = localWakeReasonTag;
1524 wakeReasonTag.setTo(o.wakeReasonTag);
1525 } else {
1526 wakeReasonTag = null;
1527 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001528 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001529 if (o.eventTag != null) {
1530 eventTag = localEventTag;
1531 eventTag.setTo(o.eventTag);
1532 } else {
1533 eventTag = null;
1534 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001535 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001536 }
1537
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001538 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001539 return batteryLevel == o.batteryLevel
1540 && batteryStatus == o.batteryStatus
1541 && batteryHealth == o.batteryHealth
1542 && batteryPlugType == o.batteryPlugType
1543 && batteryTemperature == o.batteryTemperature
1544 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001545 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001546 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001547 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001548 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001549 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001550
1551 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001552 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001553 return false;
1554 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001555 if (wakelockTag != o.wakelockTag) {
1556 if (wakelockTag == null || o.wakelockTag == null) {
1557 return false;
1558 }
1559 if (!wakelockTag.equals(o.wakelockTag)) {
1560 return false;
1561 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001562 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001563 if (wakeReasonTag != o.wakeReasonTag) {
1564 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1565 return false;
1566 }
1567 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1568 return false;
1569 }
1570 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001571 if (eventTag != o.eventTag) {
1572 if (eventTag == null || o.eventTag == null) {
1573 return false;
1574 }
1575 if (!eventTag.equals(o.eventTag)) {
1576 return false;
1577 }
1578 }
1579 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001580 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001581 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001582
1583 public final static class HistoryEventTracker {
1584 private final HashMap<String, SparseIntArray>[] mActiveEvents
1585 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1586
1587 public boolean updateState(int code, String name, int uid, int poolIdx) {
1588 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1589 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1590 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1591 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001592 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001593 mActiveEvents[idx] = active;
1594 }
1595 SparseIntArray uids = active.get(name);
1596 if (uids == null) {
1597 uids = new SparseIntArray();
1598 active.put(name, uids);
1599 }
1600 if (uids.indexOfKey(uid) >= 0) {
1601 // Already set, nothing to do!
1602 return false;
1603 }
1604 uids.put(uid, poolIdx);
1605 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1606 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1607 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1608 if (active == null) {
1609 // not currently active, nothing to do.
1610 return false;
1611 }
1612 SparseIntArray uids = active.get(name);
1613 if (uids == null) {
1614 // not currently active, nothing to do.
1615 return false;
1616 }
1617 idx = uids.indexOfKey(uid);
1618 if (idx < 0) {
1619 // not currently active, nothing to do.
1620 return false;
1621 }
1622 uids.removeAt(idx);
1623 if (uids.size() <= 0) {
1624 active.remove(name);
1625 }
1626 }
1627 return true;
1628 }
1629
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001630 public void removeEvents(int code) {
1631 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1632 mActiveEvents[idx] = null;
1633 }
1634
Dianne Hackborn37de0982014-05-09 09:32:18 -07001635 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1636 return mActiveEvents[code];
1637 }
1638 }
1639
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001640 public static final class BitDescription {
1641 public final int mask;
1642 public final int shift;
1643 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001644 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001645 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001646 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001647
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001648 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001649 this.mask = mask;
1650 this.shift = -1;
1651 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001652 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001653 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001654 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001655 }
1656
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001657 public BitDescription(int mask, int shift, String name, String shortName,
1658 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001659 this.mask = mask;
1660 this.shift = shift;
1661 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001662 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001663 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001664 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001665 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001666 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001667
Dianne Hackbornfc064132014-06-02 12:42:12 -07001668 /**
1669 * Don't allow any more batching in to the current history event. This
1670 * is called when printing partial histories, so to ensure that the next
1671 * history event will go in to a new batch after what was printed in the
1672 * last partial history.
1673 */
1674 public abstract void commitCurrentHistoryBatchLocked();
1675
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001676 public abstract int getHistoryTotalSize();
1677
1678 public abstract int getHistoryUsedSize();
1679
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001680 public abstract boolean startIteratingHistoryLocked();
1681
Dianne Hackborn099bc622014-01-22 13:39:16 -08001682 public abstract int getHistoryStringPoolSize();
1683
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001684 public abstract int getHistoryStringPoolBytes();
1685
1686 public abstract String getHistoryTagPoolString(int index);
1687
1688 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001689
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001690 public abstract boolean getNextHistoryLocked(HistoryItem out);
1691
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001692 public abstract void finishIteratingHistoryLocked();
1693
1694 public abstract boolean startIteratingOldHistoryLocked();
1695
1696 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1697
1698 public abstract void finishIteratingOldHistoryLocked();
1699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001701 * Return the base time offset for the battery history.
1702 */
1703 public abstract long getHistoryBaseTime();
1704
1705 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 * Returns the number of times the device has been started.
1707 */
1708 public abstract int getStartCount();
1709
1710 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001711 * 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 -08001712 * running on battery.
1713 *
1714 * {@hide}
1715 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001716 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001718 /**
1719 * Returns the number of times the screen was turned on.
1720 *
1721 * {@hide}
1722 */
1723 public abstract int getScreenOnCount(int which);
1724
Jeff Browne95c3cd2014-05-02 16:59:26 -07001725 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1726
Dianne Hackborn617f8772009-03-31 15:04:46 -07001727 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1728 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1729 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1730 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1731 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1732
1733 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1734 "dark", "dim", "medium", "light", "bright"
1735 };
1736
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001737 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1738 "0", "1", "2", "3", "4"
1739 };
1740
Dianne Hackborn617f8772009-03-31 15:04:46 -07001741 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001742
Dianne Hackborn617f8772009-03-31 15:04:46 -07001743 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001744 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001745 * the given brightness
1746 *
1747 * {@hide}
1748 */
1749 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001750 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001752 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001753 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001754 * running on battery.
1755 *
1756 * {@hide}
1757 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001758 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001759
1760 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001761 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001762 *
1763 * {@hide}
1764 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001765 public abstract int getPowerSaveModeEnabledCount(int which);
1766
1767 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001768 * Constant for device idle mode: not active.
1769 */
1770 public static final int DEVICE_IDLE_MODE_OFF = 0;
1771
1772 /**
1773 * Constant for device idle mode: active in lightweight mode.
1774 */
1775 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1776
1777 /**
1778 * Constant for device idle mode: active in full mode.
1779 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001780 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001781
1782 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001783 * Returns the time in microseconds that device has been in idle mode while
1784 * running on battery.
1785 *
1786 * {@hide}
1787 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001788 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001789
1790 /**
1791 * Returns the number of times that the devie has gone in to idle mode.
1792 *
1793 * {@hide}
1794 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001795 public abstract int getDeviceIdleModeCount(int mode, int which);
1796
1797 /**
1798 * Return the longest duration we spent in a particular device idle mode (fully in the
1799 * mode, not in idle maintenance etc).
1800 */
1801 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001802
1803 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001804 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001805 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001806 * counts all of the time that we consider the device to be idle, whether or not
1807 * it is currently in the actual device idle mode.
1808 *
1809 * {@hide}
1810 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001811 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001812
1813 /**
1814 * Returns the number of times that the devie has started idling.
1815 *
1816 * {@hide}
1817 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001818 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001819
1820 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001821 * Returns the number of times that connectivity state changed.
1822 *
1823 * {@hide}
1824 */
1825 public abstract int getNumConnectivityChange(int which);
1826
1827 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001828 * 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 -08001829 * running on battery.
1830 *
1831 * {@hide}
1832 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001833 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001834
1835 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001836 * Returns the number of times a phone call was activated.
1837 *
1838 * {@hide}
1839 */
1840 public abstract int getPhoneOnCount(int which);
1841
1842 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001843 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001844 * the given signal strength.
1845 *
1846 * {@hide}
1847 */
1848 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001849 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001850
Dianne Hackborn617f8772009-03-31 15:04:46 -07001851 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001852 * Returns the time in microseconds that the phone has been trying to
1853 * acquire a signal.
1854 *
1855 * {@hide}
1856 */
1857 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001858 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001859
1860 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001861 * Returns the number of times the phone has entered the given signal strength.
1862 *
1863 * {@hide}
1864 */
1865 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1866
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001867 /**
1868 * Returns the time in microseconds that the mobile network has been active
1869 * (in a high power state).
1870 *
1871 * {@hide}
1872 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001873 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001874
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001875 /**
1876 * Returns the number of times that the mobile network has transitioned to the
1877 * active state.
1878 *
1879 * {@hide}
1880 */
1881 public abstract int getMobileRadioActiveCount(int which);
1882
1883 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001884 * Returns the time in microseconds that is the difference between the mobile radio
1885 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1886 * from the radio.
1887 *
1888 * {@hide}
1889 */
1890 public abstract long getMobileRadioActiveAdjustedTime(int which);
1891
1892 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001893 * Returns the time in microseconds that the mobile network has been active
1894 * (in a high power state) but not being able to blame on an app.
1895 *
1896 * {@hide}
1897 */
1898 public abstract long getMobileRadioActiveUnknownTime(int which);
1899
1900 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001901 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001902 *
1903 * {@hide}
1904 */
1905 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001906
Dianne Hackborn627bba72009-03-24 22:32:56 -07001907 public static final int DATA_CONNECTION_NONE = 0;
1908 public static final int DATA_CONNECTION_GPRS = 1;
1909 public static final int DATA_CONNECTION_EDGE = 2;
1910 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001911 public static final int DATA_CONNECTION_CDMA = 4;
1912 public static final int DATA_CONNECTION_EVDO_0 = 5;
1913 public static final int DATA_CONNECTION_EVDO_A = 6;
1914 public static final int DATA_CONNECTION_1xRTT = 7;
1915 public static final int DATA_CONNECTION_HSDPA = 8;
1916 public static final int DATA_CONNECTION_HSUPA = 9;
1917 public static final int DATA_CONNECTION_HSPA = 10;
1918 public static final int DATA_CONNECTION_IDEN = 11;
1919 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001920 public static final int DATA_CONNECTION_LTE = 13;
1921 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001922 public static final int DATA_CONNECTION_HSPAP = 15;
1923 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001924
Dianne Hackborn627bba72009-03-24 22:32:56 -07001925 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001926 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001927 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001928 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001929 };
1930
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001931 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001932
1933 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001934 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001935 * the given data connection.
1936 *
1937 * {@hide}
1938 */
1939 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001940 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001943 * Returns the number of times the phone has entered the given data
1944 * connection type.
1945 *
1946 * {@hide}
1947 */
1948 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001949
Dianne Hackborn3251b902014-06-20 14:40:53 -07001950 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1951 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1952 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1953 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1954 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1955 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1956 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1957 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1958 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1959 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1960 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1961 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1962 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1963
1964 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1965
1966 static final String[] WIFI_SUPPL_STATE_NAMES = {
1967 "invalid", "disconn", "disabled", "inactive", "scanning",
1968 "authenticating", "associating", "associated", "4-way-handshake",
1969 "group-handshake", "completed", "dormant", "uninit"
1970 };
1971
1972 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1973 "inv", "dsc", "dis", "inact", "scan",
1974 "auth", "ascing", "asced", "4-way",
1975 "group", "compl", "dorm", "uninit"
1976 };
1977
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001978 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1979 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001980 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001981 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1982 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001983 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001984 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1985 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1986 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001987 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001988 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001989 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001990 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001991 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1992 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001993 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1994 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1995 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1996 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1997 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1998 new String[] {"in", "out", "emergency", "off"},
1999 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002000 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2001 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2002 SignalStrength.SIGNAL_STRENGTH_NAMES,
2003 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002004 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2005 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2006 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002007 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002008
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002009 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2010 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002011 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002012 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002013 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002014 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002015 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002016 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2017 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2018 new String[] { "off", "light", "full", "???" },
2019 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002020 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2021 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2022 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002023 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2024 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2025 new String[] { "0", "1", "2", "3", "4" },
2026 new String[] { "0", "1", "2", "3", "4" }),
2027 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2028 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2029 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002030 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002031 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002032 };
2033
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002034 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002035 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002036 "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist",
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07002037 "screenwake", "wakeupap", "longwake"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002038 };
2039
2040 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002041 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002042 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07002043 "Esw", "Ewa", "Elw"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002044 };
2045
Dianne Hackborn617f8772009-03-31 15:04:46 -07002046 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002047 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002048 * running on battery.
2049 *
2050 * {@hide}
2051 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002052 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002053
2054 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002055 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002056 * been in the running state while the device was running on battery.
2057 *
2058 * {@hide}
2059 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002060 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002061
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002062 public static final int WIFI_STATE_OFF = 0;
2063 public static final int WIFI_STATE_OFF_SCANNING = 1;
2064 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2065 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2066 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2067 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2068 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2069 public static final int WIFI_STATE_SOFT_AP = 7;
2070
2071 static final String[] WIFI_STATE_NAMES = {
2072 "off", "scanning", "no_net", "disconn",
2073 "sta", "p2p", "sta_p2p", "soft_ap"
2074 };
2075
2076 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2077
2078 /**
2079 * Returns the time in microseconds that WiFi has been running in the given state.
2080 *
2081 * {@hide}
2082 */
2083 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002084 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002085
2086 /**
2087 * Returns the number of times that WiFi has entered the given state.
2088 *
2089 * {@hide}
2090 */
2091 public abstract int getWifiStateCount(int wifiState, int which);
2092
The Android Open Source Project10592532009-03-18 17:39:46 -07002093 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002094 * Returns the time in microseconds that the wifi supplicant has been
2095 * in a given state.
2096 *
2097 * {@hide}
2098 */
2099 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2100
2101 /**
2102 * Returns the number of times that the wifi supplicant has transitioned
2103 * to a given state.
2104 *
2105 * {@hide}
2106 */
2107 public abstract int getWifiSupplStateCount(int state, int which);
2108
2109 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2110
2111 /**
2112 * Returns the time in microseconds that WIFI has been running with
2113 * the given signal strength.
2114 *
2115 * {@hide}
2116 */
2117 public abstract long getWifiSignalStrengthTime(int strengthBin,
2118 long elapsedRealtimeUs, int which);
2119
2120 /**
2121 * Returns the number of times WIFI has entered the given signal strength.
2122 *
2123 * {@hide}
2124 */
2125 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2126
2127 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002128 * Returns the time in microseconds that the flashlight has been on while the device was
2129 * running on battery.
2130 *
2131 * {@hide}
2132 */
2133 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2134
2135 /**
2136 * Returns the number of times that the flashlight has been turned on while the device was
2137 * running on battery.
2138 *
2139 * {@hide}
2140 */
2141 public abstract long getFlashlightOnCount(int which);
2142
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002143 /**
2144 * Returns the time in microseconds that the camera has been on while the device was
2145 * running on battery.
2146 *
2147 * {@hide}
2148 */
2149 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2150
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002151 /**
2152 * Returns the time in microseconds that bluetooth scans were running while the device was
2153 * on battery.
2154 *
2155 * {@hide}
2156 */
2157 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002158
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002159 public static final int NETWORK_MOBILE_RX_DATA = 0;
2160 public static final int NETWORK_MOBILE_TX_DATA = 1;
2161 public static final int NETWORK_WIFI_RX_DATA = 2;
2162 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002163 public static final int NETWORK_BT_RX_DATA = 4;
2164 public static final int NETWORK_BT_TX_DATA = 5;
2165 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_BT_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002166
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002167 public abstract long getNetworkActivityBytes(int type, int which);
2168 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002169
Adam Lesinskie08af192015-03-25 16:42:59 -07002170 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002171 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002172 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002173 * actual power data.
2174 */
2175 public abstract boolean hasWifiActivityReporting();
2176
2177 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002178 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2179 * in various radio controller states, such as transmit, receive, and idle.
2180 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002181 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002182 public abstract ControllerActivityCounter getWifiControllerActivity();
2183
2184 /**
2185 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2186 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2187 * actual power data.
2188 */
2189 public abstract boolean hasBluetoothActivityReporting();
2190
2191 /**
2192 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2193 * in various radio controller states, such as transmit, receive, and idle.
2194 * @return non-null {@link ControllerActivityCounter}
2195 */
2196 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2197
2198 /**
2199 * Returns true if the BatteryStats object has detailed modem power reports.
2200 * When true, calling {@link #getModemControllerActivity()} will yield the
2201 * actual power data.
2202 */
2203 public abstract boolean hasModemActivityReporting();
2204
2205 /**
2206 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2207 * in various radio controller states, such as transmit, receive, and idle.
2208 * @return non-null {@link ControllerActivityCounter}
2209 */
2210 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002211
The Android Open Source Project10592532009-03-18 17:39:46 -07002212 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002213 * Return the wall clock time when battery stats data collection started.
2214 */
2215 public abstract long getStartClockTime();
2216
2217 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002218 * Return platform version tag that we were running in when the battery stats started.
2219 */
2220 public abstract String getStartPlatformVersion();
2221
2222 /**
2223 * Return platform version tag that we were running in when the battery stats ended.
2224 */
2225 public abstract String getEndPlatformVersion();
2226
2227 /**
2228 * Return the internal version code of the parcelled format.
2229 */
2230 public abstract int getParcelVersion();
2231
2232 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002233 * Return whether we are currently running on battery.
2234 */
2235 public abstract boolean getIsOnBattery();
2236
2237 /**
2238 * Returns a SparseArray containing the statistics for each uid.
2239 */
2240 public abstract SparseArray<? extends Uid> getUidStats();
2241
2242 /**
2243 * Returns the current battery uptime in microseconds.
2244 *
2245 * @param curTime the amount of elapsed realtime in microseconds.
2246 */
2247 public abstract long getBatteryUptime(long curTime);
2248
2249 /**
2250 * Returns the current battery realtime in microseconds.
2251 *
2252 * @param curTime the amount of elapsed realtime in microseconds.
2253 */
2254 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07002255
2256 /**
Evan Millar633a1742009-04-02 16:36:33 -07002257 * Returns the battery percentage level at the last time the device was unplugged from power, or
2258 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002259 */
Evan Millar633a1742009-04-02 16:36:33 -07002260 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07002261
2262 /**
Evan Millar633a1742009-04-02 16:36:33 -07002263 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2264 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002265 */
Evan Millar633a1742009-04-02 16:36:33 -07002266 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267
2268 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002269 * Get the amount the battery has discharged since the stats were
2270 * last reset after charging, as a lower-end approximation.
2271 */
2272 public abstract int getLowDischargeAmountSinceCharge();
2273
2274 /**
2275 * Get the amount the battery has discharged since the stats were
2276 * last reset after charging, as an upper-end approximation.
2277 */
2278 public abstract int getHighDischargeAmountSinceCharge();
2279
2280 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002281 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2282 */
2283 public abstract int getDischargeAmount(int which);
2284
2285 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002286 * Get the amount the battery has discharged while the screen was on,
2287 * since the last time power was unplugged.
2288 */
2289 public abstract int getDischargeAmountScreenOn();
2290
2291 /**
2292 * Get the amount the battery has discharged while the screen was on,
2293 * since the last time the device was charged.
2294 */
2295 public abstract int getDischargeAmountScreenOnSinceCharge();
2296
2297 /**
2298 * Get the amount the battery has discharged while the screen was off,
2299 * since the last time power was unplugged.
2300 */
2301 public abstract int getDischargeAmountScreenOff();
2302
2303 /**
2304 * Get the amount the battery has discharged while the screen was off,
2305 * since the last time the device was charged.
2306 */
2307 public abstract int getDischargeAmountScreenOffSinceCharge();
2308
2309 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 * Returns the total, last, or current battery uptime in microseconds.
2311 *
2312 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002313 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 */
2315 public abstract long computeBatteryUptime(long curTime, int which);
2316
2317 /**
2318 * Returns the total, last, or current battery realtime in microseconds.
2319 *
2320 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002321 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 */
2323 public abstract long computeBatteryRealtime(long curTime, int which);
2324
2325 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002326 * Returns the total, last, or current battery screen off uptime in microseconds.
2327 *
2328 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002329 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002330 */
2331 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2332
2333 /**
2334 * Returns the total, last, or current battery screen off realtime in microseconds.
2335 *
2336 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002337 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002338 */
2339 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2340
2341 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 * Returns the total, last, or current uptime in microseconds.
2343 *
2344 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002345 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346 */
2347 public abstract long computeUptime(long curTime, int which);
2348
2349 /**
2350 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002351 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002353 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 */
2355 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002356
2357 /**
2358 * Compute an approximation for how much run time (in microseconds) is remaining on
2359 * the battery. Returns -1 if no time can be computed: either there is not
2360 * enough current data to make a decision, or the battery is currently
2361 * charging.
2362 *
2363 * @param curTime The current elepsed realtime in microseconds.
2364 */
2365 public abstract long computeBatteryTimeRemaining(long curTime);
2366
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002367 // The part of a step duration that is the actual time.
2368 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2369
2370 // Bits in a step duration that are the new battery level we are at.
2371 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002372 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002373
2374 // Bits in a step duration that are the initial mode we were in at that step.
2375 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002376 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002377
2378 // Bits in a step duration that indicate which modes changed during that step.
2379 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002380 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002381
2382 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2383 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2384
2385 // Step duration mode: power save is on.
2386 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2387
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002388 // Step duration mode: device is currently in idle mode.
2389 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2390
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002391 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2392 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002393 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2394 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002395 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2396 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2397 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2398 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2399 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002400 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2401 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002402 };
2403 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2404 (Display.STATE_OFF-1),
2405 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002406 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002407 (Display.STATE_ON-1),
2408 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2409 (Display.STATE_DOZE-1),
2410 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2411 (Display.STATE_DOZE_SUSPEND-1),
2412 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002413 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002414 };
2415 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2416 "screen off",
2417 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002418 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002419 "screen on",
2420 "screen on power save",
2421 "screen doze",
2422 "screen doze power save",
2423 "screen doze-suspend",
2424 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002425 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002426 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002427
2428 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002429 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2430 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2431 * a coulomb counter.
2432 */
2433 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2434
2435 /**
2436 * Return the counter keeping track of the amount of battery discharge measured in
2437 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2438 * a coulomb counter.
2439 */
2440 public abstract LongCounter getDischargeCoulombCounter();
2441
2442 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002443 * Returns the estimated real battery capacity, which may be less than the capacity
2444 * declared by the PowerProfile.
2445 * @return The estimated battery capacity in mAh.
2446 */
2447 public abstract int getEstimatedBatteryCapacity();
2448
2449 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002450 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002451 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002452 public abstract LevelStepTracker getDischargeLevelStepTracker();
2453
2454 /**
2455 * Return the array of daily discharge step durations.
2456 */
2457 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002458
2459 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002460 * Compute an approximation for how much time (in microseconds) remains until the battery
2461 * is fully charged. Returns -1 if no time can be computed: either there is not
2462 * enough current data to make a decision, or the battery is currently
2463 * discharging.
2464 *
2465 * @param curTime The current elepsed realtime in microseconds.
2466 */
2467 public abstract long computeChargeTimeRemaining(long curTime);
2468
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002469 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002470 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002471 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002472 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002473
2474 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002475 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002476 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002477 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002478
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002479 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2480
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002481 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002482
Evan Millarc64edde2009-04-18 12:26:32 -07002483 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484
James Carr2dd7e5e2016-07-20 18:48:39 -07002485 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2486
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002487 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2488
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002489 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 long days = seconds / (60 * 60 * 24);
2491 if (days != 0) {
2492 out.append(days);
2493 out.append("d ");
2494 }
2495 long used = days * 60 * 60 * 24;
2496
2497 long hours = (seconds - used) / (60 * 60);
2498 if (hours != 0 || used != 0) {
2499 out.append(hours);
2500 out.append("h ");
2501 }
2502 used += hours * 60 * 60;
2503
2504 long mins = (seconds-used) / 60;
2505 if (mins != 0 || used != 0) {
2506 out.append(mins);
2507 out.append("m ");
2508 }
2509 used += mins * 60;
2510
2511 if (seconds != 0 || used != 0) {
2512 out.append(seconds-used);
2513 out.append("s ");
2514 }
2515 }
2516
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002517 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002519 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002520 sb.append(time - (sec * 1000));
2521 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 }
2523
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002524 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002525 long sec = time / 1000;
2526 formatTimeRaw(sb, sec);
2527 sb.append(time - (sec * 1000));
2528 sb.append("ms");
2529 }
2530
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002531 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002532 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002533 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 }
2535 float perc = ((float)num) / ((float)den) * 100;
2536 mFormatBuilder.setLength(0);
2537 mFormatter.format("%.1f%%", perc);
2538 return mFormatBuilder.toString();
2539 }
2540
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002541 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002542 mFormatBuilder.setLength(0);
2543
2544 if (bytes < BYTES_PER_KB) {
2545 return bytes + "B";
2546 } else if (bytes < BYTES_PER_MB) {
2547 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2548 return mFormatBuilder.toString();
2549 } else if (bytes < BYTES_PER_GB){
2550 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2551 return mFormatBuilder.toString();
2552 } else {
2553 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2554 return mFormatBuilder.toString();
2555 }
2556 }
2557
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002558 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002559 if (timer != null) {
2560 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002561 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002562 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2563 return totalTimeMillis;
2564 }
2565 return 0;
2566 }
2567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 /**
2569 *
2570 * @param sb a StringBuilder object.
2571 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002572 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002574 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 * @param linePrefix a String to be prepended to each line of output.
2576 * @return the line prefix
2577 */
2578 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002579 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002582 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002583
Evan Millarc64edde2009-04-18 12:26:32 -07002584 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 if (totalTimeMillis != 0) {
2586 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002587 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002588 if (name != null) {
2589 sb.append(name);
2590 sb.append(' ');
2591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002592 sb.append('(');
2593 sb.append(count);
2594 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002595 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2596 if (maxDurationMs >= 0) {
2597 sb.append(" max=");
2598 sb.append(maxDurationMs);
2599 }
2600 if (timer.isRunningLocked()) {
2601 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2602 if (currentMs >= 0) {
2603 sb.append(" (running for ");
2604 sb.append(currentMs);
2605 sb.append("ms)");
2606 } else {
2607 sb.append(" (running)");
2608 }
2609 }
2610
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 return ", ";
2612 }
2613 }
2614 return linePrefix;
2615 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002616
2617 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002618 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002619 *
2620 * @param pw a PrintWriter object to print to.
2621 * @param sb a StringBuilder object.
2622 * @param timer a Timer object contining the wakelock times.
2623 * @param rawRealtime the current on-battery time in microseconds.
2624 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2625 * @param prefix a String to be prepended to each line of output.
2626 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002627 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002628 */
2629 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002630 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002631 if (timer != null) {
2632 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002633 final long totalTimeMs = (timer.getTotalTimeLocked(
2634 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002635 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002636 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002637 sb.setLength(0);
2638 sb.append(prefix);
2639 sb.append(" ");
2640 sb.append(type);
2641 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002642 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002643 sb.append("realtime (");
2644 sb.append(count);
2645 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002646 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2647 if (maxDurationMs >= 0) {
2648 sb.append(" max=");
2649 sb.append(maxDurationMs);
2650 }
2651 if (timer.isRunningLocked()) {
2652 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2653 if (currentMs >= 0) {
2654 sb.append(" (running for ");
2655 sb.append(currentMs);
2656 sb.append("ms)");
2657 } else {
2658 sb.append(" (running)");
2659 }
2660 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002661 pw.println(sb.toString());
2662 return true;
2663 }
2664 }
2665 return false;
2666 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667
2668 /**
2669 * Checkin version of wakelock printer. Prints simple comma-separated list.
2670 *
2671 * @param sb a StringBuilder object.
2672 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002673 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002674 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002675 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002676 * @param linePrefix a String to be prepended to each line of output.
2677 * @return the line prefix
2678 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002679 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2680 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002681 long totalTimeMicros = 0;
2682 int count = 0;
Joe Onorato92fd23f2016-07-25 11:18:42 -07002683 long max = -1;
2684 long current = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002686 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002687 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002688 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2689 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 }
2691 sb.append(linePrefix);
2692 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2693 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002694 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002696 sb.append(',');
2697 sb.append(current);
2698 sb.append(',');
2699 sb.append(max);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 return ",";
2701 }
2702
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002703 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2704 String type) {
2705 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2706 pw.print(',');
2707 pw.print(uid);
2708 pw.print(',');
2709 pw.print(category);
2710 pw.print(',');
2711 pw.print(type);
2712 }
2713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002714 /**
2715 * Dump a comma-separated line of values for terse checkin mode.
2716 *
2717 * @param pw the PageWriter to dump log to
2718 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2719 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2720 * @param args type-dependent data arguments
2721 */
2722 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2723 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002724 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002725 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002726 pw.print(',');
2727 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002728 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002729 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002731
2732 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002733 * Dump a given timer stat for terse checkin mode.
2734 *
2735 * @param pw the PageWriter to dump log to
2736 * @param uid the UID to log
2737 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2738 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2739 * @param timer a {@link Timer} to dump stats for
2740 * @param rawRealtime the current elapsed realtime of the system in microseconds
2741 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2742 */
2743 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2744 Timer timer, long rawRealtime, int which) {
2745 if (timer != null) {
2746 // Convert from microseconds to milliseconds with rounding
2747 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2748 / 1000;
2749 final int count = timer.getCountLocked(which);
2750 if (totalTime != 0) {
2751 dumpLine(pw, uid, category, type, totalTime, count);
2752 }
2753 }
2754 }
2755
2756 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002757 * Checks if the ControllerActivityCounter has any data worth dumping.
2758 */
2759 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2760 if (counter == null) {
2761 return false;
2762 }
2763
2764 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2765 || counter.getRxTimeCounter().getCountLocked(which) != 0
2766 || counter.getPowerCounter().getCountLocked(which) != 0) {
2767 return true;
2768 }
2769
2770 for (LongCounter c : counter.getTxTimeCounters()) {
2771 if (c.getCountLocked(which) != 0) {
2772 return true;
2773 }
2774 }
2775 return false;
2776 }
2777
2778 /**
2779 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2780 * The order of the arguments in the final check in line is:
2781 *
2782 * idle, rx, power, tx...
2783 *
2784 * where tx... is one or more transmit level times.
2785 */
2786 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2787 String type,
2788 ControllerActivityCounter counter,
2789 int which) {
2790 if (!controllerActivityHasData(counter, which)) {
2791 return;
2792 }
2793
2794 dumpLineHeader(pw, uid, category, type);
2795 pw.print(",");
2796 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2797 pw.print(",");
2798 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2799 pw.print(",");
2800 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2801 for (LongCounter c : counter.getTxTimeCounters()) {
2802 pw.print(",");
2803 pw.print(c.getCountLocked(which));
2804 }
2805 pw.println();
2806 }
2807
2808 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2809 String prefix, String controllerName,
2810 ControllerActivityCounter counter,
2811 int which) {
2812 if (controllerActivityHasData(counter, which)) {
2813 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2814 }
2815 }
2816
2817 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2818 String controllerName,
2819 ControllerActivityCounter counter, int which) {
2820 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2821 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2822 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2823 long totalTxTimeMs = 0;
2824 for (LongCounter txState : counter.getTxTimeCounters()) {
2825 totalTxTimeMs += txState.getCountLocked(which);
2826 }
2827
2828 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2829
2830 sb.setLength(0);
2831 sb.append(prefix);
2832 sb.append(" ");
2833 sb.append(controllerName);
2834 sb.append(" Idle time: ");
2835 formatTimeMs(sb, idleTimeMs);
2836 sb.append("(");
2837 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2838 sb.append(")");
2839 pw.println(sb.toString());
2840
2841 sb.setLength(0);
2842 sb.append(prefix);
2843 sb.append(" ");
2844 sb.append(controllerName);
2845 sb.append(" Rx time: ");
2846 formatTimeMs(sb, rxTimeMs);
2847 sb.append("(");
2848 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
2849 sb.append(")");
2850 pw.println(sb.toString());
2851
2852 sb.setLength(0);
2853 sb.append(prefix);
2854 sb.append(" ");
2855 sb.append(controllerName);
2856 sb.append(" Tx time: ");
2857 formatTimeMs(sb, totalTxTimeMs);
2858 sb.append("(");
2859 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
2860 sb.append(")");
2861 pw.println(sb.toString());
2862
2863 final int numTxLvls = counter.getTxTimeCounters().length;
2864 if (numTxLvls > 1) {
2865 for (int lvl = 0; lvl < numTxLvls; lvl++) {
2866 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
2867 sb.setLength(0);
2868 sb.append(prefix);
2869 sb.append(" [");
2870 sb.append(lvl);
2871 sb.append("] ");
2872 formatTimeMs(sb, txLvlTimeMs);
2873 sb.append("(");
2874 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
2875 sb.append(")");
2876 pw.println(sb.toString());
2877 }
2878 }
2879
2880 sb.setLength(0);
2881 sb.append(prefix);
2882 sb.append(" ");
2883 sb.append(controllerName);
2884 sb.append(" Power drain: ").append(
2885 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
2886 sb.append("mAh");
2887 pw.println(sb.toString());
2888 }
2889
2890 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07002891 * Temporary for settings.
2892 */
2893 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2894 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2895 }
2896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 /**
2898 * Checkin server version of dump to produce more compact, computer-readable log.
2899 *
2900 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002902 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2903 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2905 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2906 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2908 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002909 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2910 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2911 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002912 final long totalRealtime = computeRealtime(rawRealtime, which);
2913 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002914 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002915 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002916 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002917 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
2918 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002919 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002920 rawRealtime, which);
2921 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
2922 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002923 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002924 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002925 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002926 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002927 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
2928 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
2929 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002930
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002931 final StringBuilder sb = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002933 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07002934 final int NU = uidStats.size();
2935
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002936 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 // Dump "battery" stat
2939 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002940 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002941 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002942 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002943 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002944 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
2945 getEstimatedBatteryCapacity());
Adam Lesinski67c134f2016-06-10 15:15:08 -07002946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002948 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002949 long fullWakeLockTimeTotal = 0;
2950 long partialWakeLockTimeTotal = 0;
2951
2952 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002953 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002954
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002955 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
2956 = u.getWakelockStats();
2957 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2958 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07002959
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002960 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2961 if (fullWakeTimer != null) {
2962 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2963 which);
2964 }
2965
2966 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2967 if (partialWakeTimer != null) {
2968 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
2969 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002970 }
2971 }
2972 }
Adam Lesinskie283d332015-04-16 12:29:25 -07002973
2974 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002975 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2976 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2977 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2978 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2979 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2980 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2981 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2982 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002983 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
2984 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002985 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2986 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002987 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
2988 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002989
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002990 // Dump Modem controller stats
2991 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
2992 getModemControllerActivity(), which);
2993
Adam Lesinskie283d332015-04-16 12:29:25 -07002994 // Dump Wifi controller stats
2995 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2996 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002997 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08002998 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002999
3000 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3001 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003002
3003 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003004 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3005 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 // Dump misc stats
3008 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003009 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003010 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003011 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003012 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003013 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003014 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3015 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003016 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003017 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3018 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3019 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3020 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003021 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003022
3023 // Dump screen brightness stats
3024 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3025 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003026 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003027 }
3028 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07003029
Dianne Hackborn627bba72009-03-24 22:32:56 -07003030 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003031 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3032 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003033 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003034 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003035 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003036 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003037 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003038 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003039 args[i] = getPhoneSignalStrengthCount(i, which);
3040 }
3041 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003042
Dianne Hackborn627bba72009-03-24 22:32:56 -07003043 // Dump network type stats
3044 args = new Object[NUM_DATA_CONNECTION_TYPES];
3045 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003046 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003047 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003048 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3049 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3050 args[i] = getPhoneDataConnectionCount(i, which);
3051 }
3052 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003053
3054 // Dump wifi state stats
3055 args = new Object[NUM_WIFI_STATES];
3056 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003057 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003058 }
3059 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3060 for (int i=0; i<NUM_WIFI_STATES; i++) {
3061 args[i] = getWifiStateCount(i, which);
3062 }
3063 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3064
Dianne Hackborn3251b902014-06-20 14:40:53 -07003065 // Dump wifi suppl state stats
3066 args = new Object[NUM_WIFI_SUPPL_STATES];
3067 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3068 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3069 }
3070 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3071 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3072 args[i] = getWifiSupplStateCount(i, which);
3073 }
3074 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3075
3076 // Dump wifi signal strength stats
3077 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3078 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3079 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3080 }
3081 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3082 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3083 args[i] = getWifiSignalStrengthCount(i, which);
3084 }
3085 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3086
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003087 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003088 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003089 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003090 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003091
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003092 if (which == STATS_SINCE_UNPLUGGED) {
3093 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3094 getDischargeStartLevel()-getDischargeCurrentLevel(),
3095 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003096 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
3097 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003098 } else {
3099 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3100 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003101 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003102 getDischargeAmountScreenOffSinceCharge(),
3103 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003104 }
3105
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003106 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003107 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003108 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003109 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003110 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003111 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003112 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003113 sb.toString());
3114 }
Evan Millarc64edde2009-04-18 12:26:32 -07003115 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003116 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003117 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003118 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3119 // Not doing the regular wake lock formatting to remain compatible
3120 // with the old checkin format.
3121 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3122 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003123 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003124 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003125 }
3126 }
Evan Millarc64edde2009-04-18 12:26:32 -07003127 }
3128
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003129 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003130 helper.create(this);
3131 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003132 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003133 if (sippers != null && sippers.size() > 0) {
3134 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3135 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003136 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003137 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3138 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3139 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003140 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003141 int uid = 0;
3142 String label;
3143 switch (bs.drainType) {
3144 case IDLE:
3145 label="idle";
3146 break;
3147 case CELL:
3148 label="cell";
3149 break;
3150 case PHONE:
3151 label="phone";
3152 break;
3153 case WIFI:
3154 label="wifi";
3155 break;
3156 case BLUETOOTH:
3157 label="blue";
3158 break;
3159 case SCREEN:
3160 label="scrn";
3161 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003162 case FLASHLIGHT:
3163 label="flashlight";
3164 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003165 case APP:
3166 uid = bs.uidObj.getUid();
3167 label = "uid";
3168 break;
3169 case USER:
3170 uid = UserHandle.getUid(bs.userId, 0);
3171 label = "user";
3172 break;
3173 case UNACCOUNTED:
3174 label = "unacc";
3175 break;
3176 case OVERCOUNTED:
3177 label = "over";
3178 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003179 case CAMERA:
3180 label = "camera";
3181 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003182 default:
3183 label = "???";
3184 }
3185 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07003186 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003187 }
3188 }
3189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190 for (int iu = 0; iu < NU; iu++) {
3191 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003192 if (reqUid >= 0 && uid != reqUid) {
3193 continue;
3194 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003195 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003198 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3199 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3200 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3201 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3202 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3203 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3204 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3205 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003206 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003207 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3208 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003209 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003210 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3211 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003212 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3213 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003214 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Adam Lesinski5f056f62016-07-14 16:56:08 -07003215 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003216 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3217 wifiBytesRx, wifiBytesTx,
3218 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003219 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003220 mobileActiveTime, mobileActiveCount,
Adam Lesinski5f056f62016-07-14 16:56:08 -07003221 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003222 }
3223
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003224 // Dump modem controller data, per UID.
3225 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3226 u.getModemControllerActivity(), which);
3227
3228 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003229 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3230 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3231 final int wifiScanCount = u.getWifiScanCount(which);
3232 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003233 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003234 || uidWifiRunningTime != 0) {
3235 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3236 uidWifiRunningTime, wifiScanCount,
Kweku Adams5b2747e2016-04-25 10:44:05 -07003237 /* legacy fields follow, keep at 0 */ 0, 0, 0);
The Android Open Source Project10592532009-03-18 17:39:46 -07003238 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003240 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3241 u.getWifiControllerActivity(), which);
3242
Adam Lesinskiba9d8932016-04-12 12:06:03 -07003243 dumpTimer(pw, uid, category, BLUETOOTH_MISC_DATA, u.getBluetoothScanTimer(),
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003244 rawRealtime, which);
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003245
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003246 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3247 u.getBluetoothControllerActivity(), which);
3248
Dianne Hackborn617f8772009-03-31 15:04:46 -07003249 if (u.hasUserActivity()) {
3250 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3251 boolean hasData = false;
3252 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3253 int val = u.getUserActivityCount(i, which);
3254 args[i] = val;
3255 if (val != 0) hasData = true;
3256 }
3257 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003258 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003259 }
3260 }
3261
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003262 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3263 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3264 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3265 String linePrefix = "";
3266 sb.setLength(0);
3267 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3268 rawRealtime, "f", which, linePrefix);
3269 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
3270 rawRealtime, "p", which, linePrefix);
3271 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3272 rawRealtime, "w", which, linePrefix);
3273
3274 // Only log if we had at lease one wakelock...
3275 if (sb.length() > 0) {
3276 String name = wakelocks.keyAt(iw);
3277 if (name.indexOf(',') >= 0) {
3278 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003280 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 }
3282 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003283
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003284 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3285 for (int isy=syncs.size()-1; isy>=0; isy--) {
3286 final Timer timer = syncs.valueAt(isy);
3287 // Convert from microseconds to milliseconds with rounding
3288 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3289 final int count = timer.getCountLocked(which);
3290 if (totalTime != 0) {
3291 dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003292 }
3293 }
3294
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003295 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3296 for (int ij=jobs.size()-1; ij>=0; ij--) {
3297 final Timer timer = jobs.valueAt(ij);
3298 // Convert from microseconds to milliseconds with rounding
3299 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3300 final int count = timer.getCountLocked(which);
3301 if (totalTime != 0) {
3302 dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003303 }
3304 }
3305
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003306 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3307 rawRealtime, which);
3308 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3309 rawRealtime, which);
3310 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3311 rawRealtime, which);
3312 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3313 rawRealtime, which);
3314
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003315 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3316 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003317 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003318 final Uid.Sensor se = sensors.valueAt(ise);
3319 final int sensorNumber = sensors.keyAt(ise);
3320 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003321 if (timer != null) {
3322 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003323 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3324 / 1000;
3325 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003326 if (totalTime != 0) {
3327 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
3328 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 }
3330 }
3331
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003332 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3333 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003334
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003335 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3336 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003337
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003338 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003339 long totalStateTime = 0;
3340 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003341 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3342 totalStateTime += time;
3343 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003344 }
3345 if (totalStateTime > 0) {
3346 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3347 }
3348
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003349 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3350 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
3351 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
3352 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
3353 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
3354 powerCpuMaUs / 1000);
3355 }
3356
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003357 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3358 = u.getProcessStats();
3359 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3360 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003361
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003362 final long userMillis = ps.getUserTime(which);
3363 final long systemMillis = ps.getSystemTime(which);
3364 final long foregroundMillis = ps.getForegroundTime(which);
3365 final int starts = ps.getStarts(which);
3366 final int numCrashes = ps.getNumCrashes(which);
3367 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003368
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003369 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3370 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
3371 dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis,
3372 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003373 }
3374 }
3375
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003376 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3377 = u.getPackageStats();
3378 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3379 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3380 int wakeups = 0;
3381 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3382 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003383 int count = alarms.valueAt(iwa).getCountLocked(which);
3384 wakeups += count;
3385 String name = alarms.keyAt(iwa).replace(',', '_');
3386 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003387 }
3388 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3389 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3390 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3391 final long startTime = ss.getStartTime(batteryUptime, which);
3392 final int starts = ss.getStarts(which);
3393 final int launches = ss.getLaunches(which);
3394 if (startTime != 0 || starts != 0 || launches != 0) {
3395 dumpLine(pw, uid, category, APK_DATA,
3396 wakeups, // wakeup alarms
3397 packageStats.keyAt(ipkg), // Apk
3398 serviceStats.keyAt(isvc), // service
3399 startTime / 1000, // time spent started, in ms
3400 starts,
3401 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402 }
3403 }
3404 }
3405 }
3406 }
3407
Dianne Hackborn81038902012-11-26 17:04:09 -08003408 static final class TimerEntry {
3409 final String mName;
3410 final int mId;
3411 final BatteryStats.Timer mTimer;
3412 final long mTime;
3413 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3414 mName = name;
3415 mId = id;
3416 mTimer = timer;
3417 mTime = time;
3418 }
3419 }
3420
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003421 private void printmAh(PrintWriter printer, double power) {
3422 printer.print(BatteryStatsHelper.makemAh(power));
3423 }
3424
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003425 private void printmAh(StringBuilder sb, double power) {
3426 sb.append(BatteryStatsHelper.makemAh(power));
3427 }
3428
Dianne Hackbornd953c532014-08-16 18:17:38 -07003429 /**
3430 * Temporary for settings.
3431 */
3432 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3433 int reqUid) {
3434 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3435 }
3436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003437 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003438 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003439 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3441 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3442 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003443
3444 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3445 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3446 final long totalRealtime = computeRealtime(rawRealtime, which);
3447 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003448 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3449 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3450 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003451 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3452 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003453
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003454 final StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07003455
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003456 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003457 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003458
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003459 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3460 if (estimatedBatteryCapacity > 0) {
3461 sb.setLength(0);
3462 sb.append(prefix);
3463 sb.append(" Estimated battery capacity: ");
3464 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3465 sb.append(" mAh");
3466 pw.println(sb.toString());
3467 }
3468
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003469 sb.setLength(0);
3470 sb.append(prefix);
3471 sb.append(" Time on battery: ");
3472 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3473 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3474 sb.append(") realtime, ");
3475 formatTimeMs(sb, whichBatteryUptime / 1000);
3476 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3477 sb.append(") uptime");
3478 pw.println(sb.toString());
3479 sb.setLength(0);
3480 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003481 sb.append(" Time on battery screen off: ");
3482 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3483 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3484 sb.append(") realtime, ");
3485 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3486 sb.append("(");
3487 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3488 sb.append(") uptime");
3489 pw.println(sb.toString());
3490 sb.setLength(0);
3491 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003492 sb.append(" Total run time: ");
3493 formatTimeMs(sb, totalRealtime / 1000);
3494 sb.append("realtime, ");
3495 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003496 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003497 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003498 if (batteryTimeRemaining >= 0) {
3499 sb.setLength(0);
3500 sb.append(prefix);
3501 sb.append(" Battery time remaining: ");
3502 formatTimeMs(sb, batteryTimeRemaining / 1000);
3503 pw.println(sb.toString());
3504 }
3505 if (chargeTimeRemaining >= 0) {
3506 sb.setLength(0);
3507 sb.append(prefix);
3508 sb.append(" Charge time remaining: ");
3509 formatTimeMs(sb, chargeTimeRemaining / 1000);
3510 pw.println(sb.toString());
3511 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003512
3513 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3514 final long dischargeCount = dischargeCounter.getCountLocked(which);
3515 if (dischargeCount >= 0) {
3516 sb.setLength(0);
3517 sb.append(prefix);
3518 sb.append(" Discharge: ");
3519 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3520 sb.append(" mAh");
3521 pw.println(sb.toString());
3522 }
3523
3524 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3525 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3526 if (dischargeScreenOffCount >= 0) {
3527 sb.setLength(0);
3528 sb.append(prefix);
3529 sb.append(" Screen off discharge: ");
3530 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3531 sb.append(" mAh");
3532 pw.println(sb.toString());
3533 }
3534
3535 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3536 if (dischargeScreenOnCount >= 0) {
3537 sb.setLength(0);
3538 sb.append(prefix);
3539 sb.append(" Screen on discharge: ");
3540 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3541 sb.append(" mAh");
3542 pw.println(sb.toString());
3543 }
3544
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003545 pw.print(" Start clock time: ");
3546 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3547
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003548 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003549 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003550 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003551 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3552 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003553 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003554 rawRealtime, which);
3555 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3556 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003557 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003558 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003559 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3560 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3561 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003562 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003563 sb.append(prefix);
3564 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3565 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003566 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003567 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3568 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003569 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003570 pw.println(sb.toString());
3571 sb.setLength(0);
3572 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003573 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003574 boolean didOne = false;
3575 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003576 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003577 if (time == 0) {
3578 continue;
3579 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003580 sb.append("\n ");
3581 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003582 didOne = true;
3583 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3584 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003585 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003586 sb.append("(");
3587 sb.append(formatRatioLocked(time, screenOnTime));
3588 sb.append(")");
3589 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003590 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003591 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003592 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003593 sb.setLength(0);
3594 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003595 sb.append(" Power save mode enabled: ");
3596 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003597 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003598 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003599 sb.append(")");
3600 pw.println(sb.toString());
3601 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003602 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003603 sb.setLength(0);
3604 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003605 sb.append(" Device light idling: ");
3606 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003607 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003608 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3609 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003610 sb.append("x");
3611 pw.println(sb.toString());
3612 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003613 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003614 sb.setLength(0);
3615 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003616 sb.append(" Idle mode light time: ");
3617 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003618 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003619 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3620 sb.append(") ");
3621 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003622 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003623 sb.append(" -- longest ");
3624 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3625 pw.println(sb.toString());
3626 }
3627 if (deviceIdlingTime != 0) {
3628 sb.setLength(0);
3629 sb.append(prefix);
3630 sb.append(" Device full idling: ");
3631 formatTimeMs(sb, deviceIdlingTime / 1000);
3632 sb.append("(");
3633 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003634 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003635 sb.append("x");
3636 pw.println(sb.toString());
3637 }
3638 if (deviceIdleModeFullTime != 0) {
3639 sb.setLength(0);
3640 sb.append(prefix);
3641 sb.append(" Idle mode full time: ");
3642 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3643 sb.append("(");
3644 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3645 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003646 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003647 sb.append("x");
3648 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003649 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003650 pw.println(sb.toString());
3651 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003652 if (phoneOnTime != 0) {
3653 sb.setLength(0);
3654 sb.append(prefix);
3655 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3656 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003657 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003658 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003659 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003660 if (connChanges != 0) {
3661 pw.print(prefix);
3662 pw.print(" Connectivity changes: "); pw.println(connChanges);
3663 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003664
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003665 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003666 long fullWakeLockTimeTotalMicros = 0;
3667 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003668
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003669 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003670
Evan Millar22ac0432009-03-31 11:33:18 -07003671 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003672 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003673
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003674 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3675 = u.getWakelockStats();
3676 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3677 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003678
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003679 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3680 if (fullWakeTimer != null) {
3681 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3682 rawRealtime, which);
3683 }
3684
3685 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3686 if (partialWakeTimer != null) {
3687 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3688 rawRealtime, which);
3689 if (totalTimeMicros > 0) {
3690 if (reqUid < 0) {
3691 // Only show the ordered list of all wake
3692 // locks if the caller is not asking for data
3693 // about a specific uid.
3694 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3695 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003696 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003697 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003698 }
3699 }
3700 }
3701 }
3702
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003703 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3704 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3705 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3706 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3707 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3708 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3709 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3710 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08003711 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3712 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003713
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003714 if (fullWakeLockTimeTotalMicros != 0) {
3715 sb.setLength(0);
3716 sb.append(prefix);
3717 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3718 (fullWakeLockTimeTotalMicros + 500) / 1000);
3719 pw.println(sb.toString());
3720 }
3721
3722 if (partialWakeLockTimeTotalMicros != 0) {
3723 sb.setLength(0);
3724 sb.append(prefix);
3725 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3726 (partialWakeLockTimeTotalMicros + 500) / 1000);
3727 pw.println(sb.toString());
3728 }
3729
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003730 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003731 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3732 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3733 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3734 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003735 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003736 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003737 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003738 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003739 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003740 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003741 if (time == 0) {
3742 continue;
3743 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003744 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003745 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003746 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003747 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003748 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003749 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003750 sb.append("(");
3751 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003752 sb.append(") ");
3753 sb.append(getPhoneSignalStrengthCount(i, which));
3754 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003755 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003756 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003757 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003758
3759 sb.setLength(0);
3760 sb.append(prefix);
3761 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003762 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003763 pw.println(sb.toString());
3764
Dianne Hackborn627bba72009-03-24 22:32:56 -07003765 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003766 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003767 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003768 didOne = false;
3769 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003770 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003771 if (time == 0) {
3772 continue;
3773 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003774 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003775 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003776 didOne = true;
3777 sb.append(DATA_CONNECTION_NAMES[i]);
3778 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003779 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003780 sb.append("(");
3781 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003782 sb.append(") ");
3783 sb.append(getPhoneDataConnectionCount(i, which));
3784 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003785 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003786 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003787 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003788
3789 sb.setLength(0);
3790 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003791 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003792 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003793 formatTimeMs(sb, mobileActiveTime / 1000);
3794 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3795 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3796 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003797 pw.println(sb.toString());
3798
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003799 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3800 if (mobileActiveUnknownTime != 0) {
3801 sb.setLength(0);
3802 sb.append(prefix);
3803 sb.append(" Mobile radio active unknown time: ");
3804 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3805 sb.append("(");
3806 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3807 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3808 sb.append("x");
3809 pw.println(sb.toString());
3810 }
3811
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003812 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3813 if (mobileActiveAdjustedTime != 0) {
3814 sb.setLength(0);
3815 sb.append(prefix);
3816 sb.append(" Mobile radio active adjusted time: ");
3817 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3818 sb.append("(");
3819 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3820 sb.append(")");
3821 pw.println(sb.toString());
3822 }
3823
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003824 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
3825
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003826 pw.print(prefix);
3827 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3828 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3829 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3830 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003831 sb.setLength(0);
3832 sb.append(prefix);
3833 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3834 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3835 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3836 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003837 sb.append(")");
3838 pw.println(sb.toString());
3839
3840 sb.setLength(0);
3841 sb.append(prefix);
3842 sb.append(" Wifi states:");
3843 didOne = false;
3844 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003845 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003846 if (time == 0) {
3847 continue;
3848 }
3849 sb.append("\n ");
3850 didOne = true;
3851 sb.append(WIFI_STATE_NAMES[i]);
3852 sb.append(" ");
3853 formatTimeMs(sb, time/1000);
3854 sb.append("(");
3855 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3856 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003857 sb.append(getWifiStateCount(i, which));
3858 sb.append("x");
3859 }
3860 if (!didOne) sb.append(" (no activity)");
3861 pw.println(sb.toString());
3862
3863 sb.setLength(0);
3864 sb.append(prefix);
3865 sb.append(" Wifi supplicant states:");
3866 didOne = false;
3867 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3868 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3869 if (time == 0) {
3870 continue;
3871 }
3872 sb.append("\n ");
3873 didOne = true;
3874 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3875 sb.append(" ");
3876 formatTimeMs(sb, time/1000);
3877 sb.append("(");
3878 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3879 sb.append(") ");
3880 sb.append(getWifiSupplStateCount(i, which));
3881 sb.append("x");
3882 }
3883 if (!didOne) sb.append(" (no activity)");
3884 pw.println(sb.toString());
3885
3886 sb.setLength(0);
3887 sb.append(prefix);
3888 sb.append(" Wifi signal levels:");
3889 didOne = false;
3890 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3891 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3892 if (time == 0) {
3893 continue;
3894 }
3895 sb.append("\n ");
3896 sb.append(prefix);
3897 didOne = true;
3898 sb.append("level(");
3899 sb.append(i);
3900 sb.append(") ");
3901 formatTimeMs(sb, time/1000);
3902 sb.append("(");
3903 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3904 sb.append(") ");
3905 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003906 sb.append("x");
3907 }
3908 if (!didOne) sb.append(" (no activity)");
3909 pw.println(sb.toString());
3910
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003911 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07003912
Adam Lesinski50e47602015-12-04 17:04:54 -08003913 pw.print(prefix);
3914 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
3915 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
3916
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003917 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
3918 sb.setLength(0);
3919 sb.append(prefix);
3920 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
3921 pw.println(sb.toString());
3922
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003923 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
3924 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003925
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003926 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003927
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003928 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003929 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003930 pw.print(prefix); pw.println(" Device is currently unplugged");
3931 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3932 pw.println(getDischargeStartLevel());
3933 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3934 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003935 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003936 pw.print(prefix); pw.println(" Device is currently plugged into power");
3937 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3938 pw.println(getDischargeStartLevel());
3939 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3940 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003941 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003942 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3943 pw.println(getDischargeAmountScreenOn());
3944 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3945 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003946 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003947 } else {
3948 pw.print(prefix); pw.println(" Device battery use since last full charge");
3949 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3950 pw.println(getLowDischargeAmountSinceCharge());
3951 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3952 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003953 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3954 pw.println(getDischargeAmountScreenOnSinceCharge());
3955 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3956 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003957 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003958 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003959
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003960 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003961 helper.create(this);
3962 helper.refreshStats(which, UserHandle.USER_ALL);
3963 List<BatterySipper> sippers = helper.getUsageList();
3964 if (sippers != null && sippers.size() > 0) {
3965 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3966 pw.print(prefix); pw.print(" Capacity: ");
3967 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003968 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003969 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3970 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3971 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3972 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003973 pw.println();
3974 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003975 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003976 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003977 switch (bs.drainType) {
3978 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003979 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003980 break;
3981 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003982 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003983 break;
3984 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003985 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003986 break;
3987 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003988 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003989 break;
3990 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003991 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003992 break;
3993 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003994 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003995 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003996 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003997 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003998 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003999 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004000 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004001 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004002 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004003 break;
4004 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004005 pw.print(" User "); pw.print(bs.userId);
4006 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004007 break;
4008 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004009 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004010 break;
4011 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004012 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004013 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004014 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004015 pw.print(" Camera: ");
4016 break;
4017 default:
4018 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004019 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004020 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004021 printmAh(pw, bs.totalPowerMah);
4022
Adam Lesinski57123002015-06-12 16:12:07 -07004023 if (bs.usagePowerMah != bs.totalPowerMah) {
4024 // If the usage (generic power) isn't the whole amount, we list out
4025 // what components are involved in the calculation.
4026
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004027 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004028 if (bs.usagePowerMah != 0) {
4029 pw.print(" usage=");
4030 printmAh(pw, bs.usagePowerMah);
4031 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004032 if (bs.cpuPowerMah != 0) {
4033 pw.print(" cpu=");
4034 printmAh(pw, bs.cpuPowerMah);
4035 }
4036 if (bs.wakeLockPowerMah != 0) {
4037 pw.print(" wake=");
4038 printmAh(pw, bs.wakeLockPowerMah);
4039 }
4040 if (bs.mobileRadioPowerMah != 0) {
4041 pw.print(" radio=");
4042 printmAh(pw, bs.mobileRadioPowerMah);
4043 }
4044 if (bs.wifiPowerMah != 0) {
4045 pw.print(" wifi=");
4046 printmAh(pw, bs.wifiPowerMah);
4047 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004048 if (bs.bluetoothPowerMah != 0) {
4049 pw.print(" bt=");
4050 printmAh(pw, bs.bluetoothPowerMah);
4051 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004052 if (bs.gpsPowerMah != 0) {
4053 pw.print(" gps=");
4054 printmAh(pw, bs.gpsPowerMah);
4055 }
4056 if (bs.sensorPowerMah != 0) {
4057 pw.print(" sensor=");
4058 printmAh(pw, bs.sensorPowerMah);
4059 }
4060 if (bs.cameraPowerMah != 0) {
4061 pw.print(" camera=");
4062 printmAh(pw, bs.cameraPowerMah);
4063 }
4064 if (bs.flashlightPowerMah != 0) {
4065 pw.print(" flash=");
4066 printmAh(pw, bs.flashlightPowerMah);
4067 }
4068 pw.print(" )");
4069 }
4070 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004071 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004072 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004073 }
4074
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004075 sippers = helper.getMobilemsppList();
4076 if (sippers != null && sippers.size() > 0) {
4077 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004078 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004079 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004080 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004081 sb.setLength(0);
4082 sb.append(prefix); sb.append(" Uid ");
4083 UserHandle.formatUid(sb, bs.uidObj.getUid());
4084 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4085 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4086 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004087 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004088 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004089 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004090 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004091 sb.setLength(0);
4092 sb.append(prefix);
4093 sb.append(" TOTAL TIME: ");
4094 formatTimeMs(sb, totalTime);
4095 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4096 sb.append(")");
4097 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004098 pw.println();
4099 }
4100
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004101 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4102 @Override
4103 public int compare(TimerEntry lhs, TimerEntry rhs) {
4104 long lhsTime = lhs.mTime;
4105 long rhsTime = rhs.mTime;
4106 if (lhsTime < rhsTime) {
4107 return 1;
4108 }
4109 if (lhsTime > rhsTime) {
4110 return -1;
4111 }
4112 return 0;
4113 }
4114 };
4115
4116 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004117 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4118 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004119 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004120 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4121 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4122 : kernelWakelocks.entrySet()) {
4123 final BatteryStats.Timer timer = ent.getValue();
4124 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004125 if (totalTimeMillis > 0) {
4126 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4127 }
4128 }
4129 if (ktimers.size() > 0) {
4130 Collections.sort(ktimers, timerComparator);
4131 pw.print(prefix); pw.println(" All kernel wake locks:");
4132 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004133 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004134 String linePrefix = ": ";
4135 sb.setLength(0);
4136 sb.append(prefix);
4137 sb.append(" Kernel Wake lock ");
4138 sb.append(timer.mName);
4139 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4140 which, linePrefix);
4141 if (!linePrefix.equals(": ")) {
4142 sb.append(" realtime");
4143 // Only print out wake locks that were held
4144 pw.println(sb.toString());
4145 }
4146 }
4147 pw.println();
4148 }
4149 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004150
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004151 if (timers.size() > 0) {
4152 Collections.sort(timers, timerComparator);
4153 pw.print(prefix); pw.println(" All partial wake locks:");
4154 for (int i=0; i<timers.size(); i++) {
4155 TimerEntry timer = timers.get(i);
4156 sb.setLength(0);
4157 sb.append(" Wake lock ");
4158 UserHandle.formatUid(sb, timer.mId);
4159 sb.append(" ");
4160 sb.append(timer.mName);
4161 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4162 sb.append(" realtime");
4163 pw.println(sb.toString());
4164 }
4165 timers.clear();
4166 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004167 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004168
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004169 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004170 if (wakeupReasons.size() > 0) {
4171 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004172 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004173 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004174 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004175 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4176 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004177 }
4178 Collections.sort(reasons, timerComparator);
4179 for (int i=0; i<reasons.size(); i++) {
4180 TimerEntry timer = reasons.get(i);
4181 String linePrefix = ": ";
4182 sb.setLength(0);
4183 sb.append(prefix);
4184 sb.append(" Wakeup reason ");
4185 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004186 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4187 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004188 pw.println(sb.toString());
4189 }
4190 pw.println();
4191 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004192 }
Evan Millar22ac0432009-03-31 11:33:18 -07004193
James Carr2dd7e5e2016-07-20 18:48:39 -07004194 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
4195 pw.println("Memory Stats");
4196 for (int i = 0; i < mMemoryStats.size(); i++) {
4197 sb.setLength(0);
4198 sb.append("Bandwidth ");
4199 sb.append(mMemoryStats.keyAt(i));
4200 sb.append(" Time ");
4201 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4202 pw.println(sb.toString());
4203 }
4204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 for (int iu=0; iu<NU; iu++) {
4206 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004207 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004208 continue;
4209 }
4210
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004211 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004212
4213 pw.print(prefix);
4214 pw.print(" ");
4215 UserHandle.formatUid(pw, uid);
4216 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004217 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004218
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004219 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4220 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4221 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4222 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004223 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4224 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4225
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004226 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4227 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004228 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4229 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004230
4231 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4232 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4233
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004234 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4235 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4236 final int wifiScanCount = u.getWifiScanCount(which);
4237 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004238
Adam Lesinski5f056f62016-07-14 16:56:08 -07004239 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4240 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4241
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004242 if (mobileRxBytes > 0 || mobileTxBytes > 0
4243 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004244 pw.print(prefix); pw.print(" Mobile network: ");
4245 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004246 pw.print(formatBytesLocked(mobileTxBytes));
4247 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4248 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004249 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004250 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4251 sb.setLength(0);
4252 sb.append(prefix); sb.append(" Mobile radio active: ");
4253 formatTimeMs(sb, uidMobileActiveTime / 1000);
4254 sb.append("(");
4255 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4256 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4257 long packets = mobileRxPackets + mobileTxPackets;
4258 if (packets == 0) {
4259 packets = 1;
4260 }
4261 sb.append(" @ ");
4262 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4263 sb.append(" mspp");
4264 pw.println(sb.toString());
4265 }
4266
Adam Lesinski5f056f62016-07-14 16:56:08 -07004267 if (mobileWakeup > 0) {
4268 sb.setLength(0);
4269 sb.append(prefix);
4270 sb.append(" Mobile radio AP wakeups: ");
4271 sb.append(mobileWakeup);
4272 pw.println(sb.toString());
4273 }
4274
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004275 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4276 u.getModemControllerActivity(), which);
4277
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004278 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004279 pw.print(prefix); pw.print(" Wi-Fi network: ");
4280 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004281 pw.print(formatBytesLocked(wifiTxBytes));
4282 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4283 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004284 }
4285
Dianne Hackborn62793e42015-03-09 11:15:41 -07004286 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004287 || uidWifiRunningTime != 0) {
4288 sb.setLength(0);
4289 sb.append(prefix); sb.append(" Wifi Running: ");
4290 formatTimeMs(sb, uidWifiRunningTime / 1000);
4291 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4292 whichBatteryRealtime)); sb.append(")\n");
4293 sb.append(prefix); sb.append(" Full Wifi Lock: ");
4294 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4295 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4296 whichBatteryRealtime)); sb.append(")\n");
4297 sb.append(prefix); sb.append(" Wifi Scan: ");
4298 formatTimeMs(sb, wifiScanTime / 1000);
4299 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004300 whichBatteryRealtime)); sb.append(") ");
4301 sb.append(wifiScanCount);
4302 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004303 pw.println(sb.toString());
4304 }
4305
Adam Lesinski5f056f62016-07-14 16:56:08 -07004306 if (wifiWakeup > 0) {
4307 sb.setLength(0);
4308 sb.append(prefix);
4309 sb.append(" WiFi AP wakeups: ");
4310 sb.append(wifiWakeup);
4311 pw.println(sb.toString());
4312 }
4313
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004314 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4315 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004316
Adam Lesinski50e47602015-12-04 17:04:54 -08004317 if (btRxBytes > 0 || btTxBytes > 0) {
4318 pw.print(prefix); pw.print(" Bluetooth network: ");
4319 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4320 pw.print(formatBytesLocked(btTxBytes));
4321 pw.println(" sent");
4322 }
4323
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004324 uidActivity |= printTimer(pw, sb, u.getBluetoothScanTimer(), rawRealtime, which, prefix,
4325 "Bluetooth Scan");
4326
Dianne Hackborn617f8772009-03-31 15:04:46 -07004327 if (u.hasUserActivity()) {
4328 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004329 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004330 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004331 if (val != 0) {
4332 if (!hasData) {
4333 sb.setLength(0);
4334 sb.append(" User activity: ");
4335 hasData = true;
4336 } else {
4337 sb.append(", ");
4338 }
4339 sb.append(val);
4340 sb.append(" ");
4341 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4342 }
4343 }
4344 if (hasData) {
4345 pw.println(sb.toString());
4346 }
4347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004348
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004349 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4350 = u.getWakelockStats();
4351 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004352 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004353 int countWakelock = 0;
4354 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4355 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4356 String linePrefix = ": ";
4357 sb.setLength(0);
4358 sb.append(prefix);
4359 sb.append(" Wake lock ");
4360 sb.append(wakelocks.keyAt(iw));
4361 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4362 "full", which, linePrefix);
4363 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
4364 "partial", which, linePrefix);
4365 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4366 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004367 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4368 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004369 sb.append(" realtime");
4370 pw.println(sb.toString());
4371 uidActivity = true;
4372 countWakelock++;
4373
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004374 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4375 rawRealtime, which);
4376 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4377 rawRealtime, which);
4378 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4379 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004380 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004381 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004382 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004383 if (countWakelock > 1) {
4384 if (totalFullWakelock != 0 || totalPartialWakelock != 0
4385 || totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004386 sb.setLength(0);
4387 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004388 sb.append(" TOTAL wake: ");
4389 boolean needComma = false;
4390 if (totalFullWakelock != 0) {
4391 needComma = true;
4392 formatTimeMs(sb, totalFullWakelock);
4393 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004394 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004395 if (totalPartialWakelock != 0) {
4396 if (needComma) {
4397 sb.append(", ");
4398 }
4399 needComma = true;
4400 formatTimeMs(sb, totalPartialWakelock);
4401 sb.append("partial");
4402 }
4403 if (totalWindowWakelock != 0) {
4404 if (needComma) {
4405 sb.append(", ");
4406 }
4407 needComma = true;
4408 formatTimeMs(sb, totalWindowWakelock);
4409 sb.append("window");
4410 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004411 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004412 if (needComma) {
4413 sb.append(",");
4414 }
4415 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004416 formatTimeMs(sb, totalDrawWakelock);
4417 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004418 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004419 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004420 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004421 }
4422 }
4423
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004424 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4425 for (int isy=syncs.size()-1; isy>=0; isy--) {
4426 final Timer timer = syncs.valueAt(isy);
4427 // Convert from microseconds to milliseconds with rounding
4428 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4429 final int count = timer.getCountLocked(which);
4430 sb.setLength(0);
4431 sb.append(prefix);
4432 sb.append(" Sync ");
4433 sb.append(syncs.keyAt(isy));
4434 sb.append(": ");
4435 if (totalTime != 0) {
4436 formatTimeMs(sb, totalTime);
4437 sb.append("realtime (");
4438 sb.append(count);
4439 sb.append(" times)");
4440 } else {
4441 sb.append("(not used)");
4442 }
4443 pw.println(sb.toString());
4444 uidActivity = true;
4445 }
4446
4447 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4448 for (int ij=jobs.size()-1; ij>=0; ij--) {
4449 final Timer timer = jobs.valueAt(ij);
4450 // Convert from microseconds to milliseconds with rounding
4451 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4452 final int count = timer.getCountLocked(which);
4453 sb.setLength(0);
4454 sb.append(prefix);
4455 sb.append(" Job ");
4456 sb.append(jobs.keyAt(ij));
4457 sb.append(": ");
4458 if (totalTime != 0) {
4459 formatTimeMs(sb, totalTime);
4460 sb.append("realtime (");
4461 sb.append(count);
4462 sb.append(" times)");
4463 } else {
4464 sb.append("(not used)");
4465 }
4466 pw.println(sb.toString());
4467 uidActivity = true;
4468 }
4469
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004470 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
4471 prefix, "Flashlight");
4472 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
4473 prefix, "Camera");
4474 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
4475 prefix, "Video");
4476 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
4477 prefix, "Audio");
4478
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004479 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4480 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004481 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004482 final Uid.Sensor se = sensors.valueAt(ise);
4483 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004484 sb.setLength(0);
4485 sb.append(prefix);
4486 sb.append(" Sensor ");
4487 int handle = se.getHandle();
4488 if (handle == Uid.Sensor.GPS) {
4489 sb.append("GPS");
4490 } else {
4491 sb.append(handle);
4492 }
4493 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004495 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004496 if (timer != null) {
4497 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004498 final long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn61659e52014-07-09 16:13:01 -07004499 rawRealtime, which) + 500) / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004500 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004501 //timer.logState();
4502 if (totalTime != 0) {
4503 formatTimeMs(sb, totalTime);
4504 sb.append("realtime (");
4505 sb.append(count);
4506 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004507 } else {
4508 sb.append("(not used)");
4509 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004510 } else {
4511 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004513
4514 pw.println(sb.toString());
4515 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 }
4517
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004518 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4519 "Vibrator");
4520 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4521 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004522
Dianne Hackborn61659e52014-07-09 16:13:01 -07004523 long totalStateTime = 0;
4524 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4525 long time = u.getProcessStateTime(ips, rawRealtime, which);
4526 if (time > 0) {
4527 totalStateTime += time;
4528 sb.setLength(0);
4529 sb.append(prefix);
4530 sb.append(" ");
4531 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4532 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08004533 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004534 pw.println(sb.toString());
4535 uidActivity = true;
4536 }
4537 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08004538 if (totalStateTime > 0) {
4539 sb.setLength(0);
4540 sb.append(prefix);
4541 sb.append(" Total running: ");
4542 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4543 pw.println(sb.toString());
4544 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004545
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004546 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4547 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004548 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
4549 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004550 sb.setLength(0);
4551 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004552 sb.append(" Total cpu time: u=");
4553 formatTimeMs(sb, userCpuTimeUs / 1000);
4554 sb.append("s=");
4555 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004556 sb.append("p=");
4557 printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0));
4558 sb.append("mAh");
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004559 pw.println(sb.toString());
4560 }
4561
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004562 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4563 = u.getProcessStats();
4564 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4565 final Uid.Proc ps = processStats.valueAt(ipr);
4566 long userTime;
4567 long systemTime;
4568 long foregroundTime;
4569 int starts;
4570 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004572 userTime = ps.getUserTime(which);
4573 systemTime = ps.getSystemTime(which);
4574 foregroundTime = ps.getForegroundTime(which);
4575 starts = ps.getStarts(which);
4576 final int numCrashes = ps.getNumCrashes(which);
4577 final int numAnrs = ps.getNumAnrs(which);
4578 numExcessive = which == STATS_SINCE_CHARGED
4579 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004580
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004581 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
4582 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
4583 sb.setLength(0);
4584 sb.append(prefix); sb.append(" Proc ");
4585 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
4586 sb.append(prefix); sb.append(" CPU: ");
4587 formatTimeMs(sb, userTime); sb.append("usr + ");
4588 formatTimeMs(sb, systemTime); sb.append("krn ; ");
4589 formatTimeMs(sb, foregroundTime); sb.append("fg");
4590 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
4591 sb.append("\n"); sb.append(prefix); sb.append(" ");
4592 boolean hasOne = false;
4593 if (starts != 0) {
4594 hasOne = true;
4595 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07004596 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004597 if (numCrashes != 0) {
4598 if (hasOne) {
4599 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004600 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004601 hasOne = true;
4602 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004603 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004604 if (numAnrs != 0) {
4605 if (hasOne) {
4606 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004607 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004608 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004609 }
4610 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004611 pw.println(sb.toString());
4612 for (int e=0; e<numExcessive; e++) {
4613 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
4614 if (ew != null) {
4615 pw.print(prefix); pw.print(" * Killed for ");
4616 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
4617 pw.print("wake lock");
4618 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
4619 pw.print("cpu");
4620 } else {
4621 pw.print("unknown");
4622 }
4623 pw.print(" use: ");
4624 TimeUtils.formatDuration(ew.usedTime, pw);
4625 pw.print(" over ");
4626 TimeUtils.formatDuration(ew.overTime, pw);
4627 if (ew.overTime != 0) {
4628 pw.print(" (");
4629 pw.print((ew.usedTime*100)/ew.overTime);
4630 pw.println("%)");
4631 }
4632 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004633 }
4634 uidActivity = true;
4635 }
4636 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004637
4638 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4639 = u.getPackageStats();
4640 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4641 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
4642 pw.println(":");
4643 boolean apkActivity = false;
4644 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4645 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4646 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
4647 pw.print(prefix); pw.print(" Wakeup alarm ");
4648 pw.print(alarms.keyAt(iwa)); pw.print(": ");
4649 pw.print(alarms.valueAt(iwa).getCountLocked(which));
4650 pw.println(" times");
4651 apkActivity = true;
4652 }
4653 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4654 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4655 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4656 final long startTime = ss.getStartTime(batteryUptime, which);
4657 final int starts = ss.getStarts(which);
4658 final int launches = ss.getLaunches(which);
4659 if (startTime != 0 || starts != 0 || launches != 0) {
4660 sb.setLength(0);
4661 sb.append(prefix); sb.append(" Service ");
4662 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
4663 sb.append(prefix); sb.append(" Created for: ");
4664 formatTimeMs(sb, startTime / 1000);
4665 sb.append("uptime\n");
4666 sb.append(prefix); sb.append(" Starts: ");
4667 sb.append(starts);
4668 sb.append(", launches: "); sb.append(launches);
4669 pw.println(sb.toString());
4670 apkActivity = true;
4671 }
4672 }
4673 if (!apkActivity) {
4674 pw.print(prefix); pw.println(" (nothing executed)");
4675 }
4676 uidActivity = true;
4677 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004678 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004679 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004680 }
4681 }
4682 }
4683
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004684 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004685 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004686 int diff = oldval ^ newval;
4687 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004688 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004689 for (int i=0; i<descriptions.length; i++) {
4690 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004691 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004692 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004693 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004694 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004695 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004696 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
4697 didWake = true;
4698 pw.print("=");
4699 if (longNames) {
4700 UserHandle.formatUid(pw, wakelockTag.uid);
4701 pw.print(":\"");
4702 pw.print(wakelockTag.string);
4703 pw.print("\"");
4704 } else {
4705 pw.print(wakelockTag.poolIdx);
4706 }
4707 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004708 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004709 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004710 pw.print("=");
4711 int val = (newval&bd.mask)>>bd.shift;
4712 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004713 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004714 } else {
4715 pw.print(val);
4716 }
4717 }
4718 }
4719 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004720 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07004721 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004722 if (longNames) {
4723 UserHandle.formatUid(pw, wakelockTag.uid);
4724 pw.print(":\"");
4725 pw.print(wakelockTag.string);
4726 pw.print("\"");
4727 } else {
4728 pw.print(wakelockTag.poolIdx);
4729 }
4730 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004731 }
4732
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004733 public void prepareForDumpLocked() {
4734 }
4735
4736 public static class HistoryPrinter {
4737 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004738 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004739 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004740 int oldStatus = -1;
4741 int oldHealth = -1;
4742 int oldPlug = -1;
4743 int oldTemp = -1;
4744 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004745 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004746 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004747
Dianne Hackborn3251b902014-06-20 14:40:53 -07004748 void reset() {
4749 oldState = oldState2 = 0;
4750 oldLevel = -1;
4751 oldStatus = -1;
4752 oldHealth = -1;
4753 oldPlug = -1;
4754 oldTemp = -1;
4755 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004756 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07004757 }
4758
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004759 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004760 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004761 if (!checkin) {
4762 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004763 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004764 pw.print(" (");
4765 pw.print(rec.numReadInts);
4766 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004767 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004768 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4769 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004770 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004771 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004772 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004773 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004774 }
4775 lastTime = rec.time;
4776 }
4777 if (rec.cmd == HistoryItem.CMD_START) {
4778 if (checkin) {
4779 pw.print(":");
4780 }
4781 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004782 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004783 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4784 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004785 if (checkin) {
4786 pw.print(":");
4787 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004788 if (rec.cmd == HistoryItem.CMD_RESET) {
4789 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004790 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004791 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004792 pw.print("TIME:");
4793 if (checkin) {
4794 pw.println(rec.currentTime);
4795 } else {
4796 pw.print(" ");
4797 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4798 rec.currentTime).toString());
4799 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004800 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4801 if (checkin) {
4802 pw.print(":");
4803 }
4804 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004805 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4806 if (checkin) {
4807 pw.print(":");
4808 }
4809 pw.println("*OVERFLOW*");
4810 } else {
4811 if (!checkin) {
4812 if (rec.batteryLevel < 10) pw.print("00");
4813 else if (rec.batteryLevel < 100) pw.print("0");
4814 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004815 if (verbose) {
4816 pw.print(" ");
4817 if (rec.states < 0) ;
4818 else if (rec.states < 0x10) pw.print("0000000");
4819 else if (rec.states < 0x100) pw.print("000000");
4820 else if (rec.states < 0x1000) pw.print("00000");
4821 else if (rec.states < 0x10000) pw.print("0000");
4822 else if (rec.states < 0x100000) pw.print("000");
4823 else if (rec.states < 0x1000000) pw.print("00");
4824 else if (rec.states < 0x10000000) pw.print("0");
4825 pw.print(Integer.toHexString(rec.states));
4826 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004827 } else {
4828 if (oldLevel != rec.batteryLevel) {
4829 oldLevel = rec.batteryLevel;
4830 pw.print(",Bl="); pw.print(rec.batteryLevel);
4831 }
4832 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004833 if (oldStatus != rec.batteryStatus) {
4834 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004835 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004836 switch (oldStatus) {
4837 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004838 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004839 break;
4840 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004841 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004842 break;
4843 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004844 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004845 break;
4846 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004847 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004848 break;
4849 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004850 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004851 break;
4852 default:
4853 pw.print(oldStatus);
4854 break;
4855 }
4856 }
4857 if (oldHealth != rec.batteryHealth) {
4858 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004859 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004860 switch (oldHealth) {
4861 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004862 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004863 break;
4864 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004865 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004866 break;
4867 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004868 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004869 break;
4870 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004871 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004872 break;
4873 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004874 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004875 break;
4876 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004877 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004878 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004879 case BatteryManager.BATTERY_HEALTH_COLD:
4880 pw.print(checkin ? "c" : "cold");
4881 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004882 default:
4883 pw.print(oldHealth);
4884 break;
4885 }
4886 }
4887 if (oldPlug != rec.batteryPlugType) {
4888 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004889 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004890 switch (oldPlug) {
4891 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004892 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004893 break;
4894 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004895 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004896 break;
4897 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004898 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004899 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004900 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004901 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004902 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004903 default:
4904 pw.print(oldPlug);
4905 break;
4906 }
4907 }
4908 if (oldTemp != rec.batteryTemperature) {
4909 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004910 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004911 pw.print(oldTemp);
4912 }
4913 if (oldVolt != rec.batteryVoltage) {
4914 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004915 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004916 pw.print(oldVolt);
4917 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004918 final int chargeMAh = rec.batteryChargeUAh / 1000;
4919 if (oldChargeMAh != chargeMAh) {
4920 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07004921 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004922 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07004923 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004924 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004925 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004926 printBitDescriptions(pw, oldState2, rec.states2, null,
4927 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004928 if (rec.wakeReasonTag != null) {
4929 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004930 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004931 pw.print(rec.wakeReasonTag.poolIdx);
4932 } else {
4933 pw.print(" wake_reason=");
4934 pw.print(rec.wakeReasonTag.uid);
4935 pw.print(":\"");
4936 pw.print(rec.wakeReasonTag.string);
4937 pw.print("\"");
4938 }
4939 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004940 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004941 pw.print(checkin ? "," : " ");
4942 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4943 pw.print("+");
4944 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4945 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004946 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004947 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4948 : HISTORY_EVENT_NAMES;
4949 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4950 | HistoryItem.EVENT_FLAG_FINISH);
4951 if (idx >= 0 && idx < eventNames.length) {
4952 pw.print(eventNames[idx]);
4953 } else {
4954 pw.print(checkin ? "Ev" : "event");
4955 pw.print(idx);
4956 }
4957 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004958 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004959 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004960 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004961 UserHandle.formatUid(pw, rec.eventTag.uid);
4962 pw.print(":\"");
4963 pw.print(rec.eventTag.string);
4964 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004965 }
4966 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004967 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004968 if (rec.stepDetails != null) {
4969 if (!checkin) {
4970 pw.print(" Details: cpu=");
4971 pw.print(rec.stepDetails.userTime);
4972 pw.print("u+");
4973 pw.print(rec.stepDetails.systemTime);
4974 pw.print("s");
4975 if (rec.stepDetails.appCpuUid1 >= 0) {
4976 pw.print(" (");
4977 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4978 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4979 if (rec.stepDetails.appCpuUid2 >= 0) {
4980 pw.print(", ");
4981 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4982 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4983 }
4984 if (rec.stepDetails.appCpuUid3 >= 0) {
4985 pw.print(", ");
4986 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4987 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4988 }
4989 pw.print(')');
4990 }
4991 pw.println();
4992 pw.print(" /proc/stat=");
4993 pw.print(rec.stepDetails.statUserTime);
4994 pw.print(" usr, ");
4995 pw.print(rec.stepDetails.statSystemTime);
4996 pw.print(" sys, ");
4997 pw.print(rec.stepDetails.statIOWaitTime);
4998 pw.print(" io, ");
4999 pw.print(rec.stepDetails.statIrqTime);
5000 pw.print(" irq, ");
5001 pw.print(rec.stepDetails.statSoftIrqTime);
5002 pw.print(" sirq, ");
5003 pw.print(rec.stepDetails.statIdlTime);
5004 pw.print(" idle");
5005 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
5006 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
5007 + rec.stepDetails.statSoftIrqTime;
5008 int total = totalRun + rec.stepDetails.statIdlTime;
5009 if (total > 0) {
5010 pw.print(" (");
5011 float perc = ((float)totalRun) / ((float)total) * 100;
5012 pw.print(String.format("%.1f%%", perc));
5013 pw.print(" of ");
5014 StringBuilder sb = new StringBuilder(64);
5015 formatTimeMsNoSpace(sb, total*10);
5016 pw.print(sb);
5017 pw.print(")");
5018 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005019 pw.print(", PlatformIdleStat ");
5020 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005021 pw.println();
5022 } else {
5023 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5024 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
5025 pw.print(rec.stepDetails.userTime);
5026 pw.print(":");
5027 pw.print(rec.stepDetails.systemTime);
5028 if (rec.stepDetails.appCpuUid1 >= 0) {
5029 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
5030 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5031 if (rec.stepDetails.appCpuUid2 >= 0) {
5032 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
5033 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5034 }
5035 if (rec.stepDetails.appCpuUid3 >= 0) {
5036 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
5037 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5038 }
5039 }
5040 pw.println();
5041 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5042 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
5043 pw.print(rec.stepDetails.statUserTime);
5044 pw.print(',');
5045 pw.print(rec.stepDetails.statSystemTime);
5046 pw.print(',');
5047 pw.print(rec.stepDetails.statIOWaitTime);
5048 pw.print(',');
5049 pw.print(rec.stepDetails.statIrqTime);
5050 pw.print(',');
5051 pw.print(rec.stepDetails.statSoftIrqTime);
5052 pw.print(',');
5053 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005054 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005055 if (rec.stepDetails.statPlatformIdleState != null) {
5056 pw.print(rec.stepDetails.statPlatformIdleState);
5057 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005058 pw.println();
5059 }
5060 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005061 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005062 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005063 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005064 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005065
5066 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
5067 UserHandle.formatUid(pw, uid);
5068 pw.print("=");
5069 pw.print(utime);
5070 pw.print("u+");
5071 pw.print(stime);
5072 pw.print("s");
5073 }
5074
5075 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5076 pw.print('/');
5077 pw.print(uid);
5078 pw.print(":");
5079 pw.print(utime);
5080 pw.print(":");
5081 pw.print(stime);
5082 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005083 }
5084
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005085 private void printSizeValue(PrintWriter pw, long size) {
5086 float result = size;
5087 String suffix = "";
5088 if (result >= 10*1024) {
5089 suffix = "KB";
5090 result = result / 1024;
5091 }
5092 if (result >= 10*1024) {
5093 suffix = "MB";
5094 result = result / 1024;
5095 }
5096 if (result >= 10*1024) {
5097 suffix = "GB";
5098 result = result / 1024;
5099 }
5100 if (result >= 10*1024) {
5101 suffix = "TB";
5102 result = result / 1024;
5103 }
5104 if (result >= 10*1024) {
5105 suffix = "PB";
5106 result = result / 1024;
5107 }
5108 pw.print((int)result);
5109 pw.print(suffix);
5110 }
5111
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005112 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5113 String label3, long estimatedTime) {
5114 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005115 return false;
5116 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005117 pw.print(label1);
5118 pw.print(label2);
5119 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005120 StringBuilder sb = new StringBuilder(64);
5121 formatTimeMs(sb, estimatedTime);
5122 pw.print(sb);
5123 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005124 return true;
5125 }
5126
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005127 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5128 LevelStepTracker steps, boolean checkin) {
5129 if (steps == null) {
5130 return false;
5131 }
5132 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005133 if (count <= 0) {
5134 return false;
5135 }
5136 if (!checkin) {
5137 pw.println(header);
5138 }
Kweku Adams030980a2015-04-01 16:07:48 -07005139 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005140 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005141 long duration = steps.getDurationAt(i);
5142 int level = steps.getLevelAt(i);
5143 long initMode = steps.getInitModeAt(i);
5144 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005145 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005146 lineArgs[0] = Long.toString(duration);
5147 lineArgs[1] = Integer.toString(level);
5148 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5149 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5150 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5151 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5152 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5153 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005154 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005155 }
5156 } else {
5157 lineArgs[2] = "";
5158 }
5159 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5160 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5161 } else {
5162 lineArgs[3] = "";
5163 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005164 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005165 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005166 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005167 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005168 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005169 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5170 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005171 pw.print(prefix);
5172 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005173 TimeUtils.formatDuration(duration, pw);
5174 pw.print(" to "); pw.print(level);
5175 boolean haveModes = false;
5176 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5177 pw.print(" (");
5178 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5179 case Display.STATE_OFF: pw.print("screen-off"); break;
5180 case Display.STATE_ON: pw.print("screen-on"); break;
5181 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5182 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005183 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005184 }
5185 haveModes = true;
5186 }
5187 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5188 pw.print(haveModes ? ", " : " (");
5189 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5190 ? "power-save-on" : "power-save-off");
5191 haveModes = true;
5192 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005193 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5194 pw.print(haveModes ? ", " : " (");
5195 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5196 ? "device-idle-on" : "device-idle-off");
5197 haveModes = true;
5198 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005199 if (haveModes) {
5200 pw.print(")");
5201 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005202 pw.println();
5203 }
5204 }
5205 return true;
5206 }
5207
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005208 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005209 public static final int DUMP_DAILY_ONLY = 1<<2;
5210 public static final int DUMP_HISTORY_ONLY = 1<<3;
5211 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5212 public static final int DUMP_VERBOSE = 1<<5;
5213 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005214
Dianne Hackborn37de0982014-05-09 09:32:18 -07005215 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5216 final HistoryPrinter hprinter = new HistoryPrinter();
5217 final HistoryItem rec = new HistoryItem();
5218 long lastTime = -1;
5219 long baseTime = -1;
5220 boolean printed = false;
5221 HistoryEventTracker tracker = null;
5222 while (getNextHistoryLocked(rec)) {
5223 lastTime = rec.time;
5224 if (baseTime < 0) {
5225 baseTime = lastTime;
5226 }
5227 if (rec.time >= histStart) {
5228 if (histStart >= 0 && !printed) {
5229 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005230 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005231 || rec.cmd == HistoryItem.CMD_START
5232 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005233 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005234 hprinter.printNextItem(pw, rec, baseTime, checkin,
5235 (flags&DUMP_VERBOSE) != 0);
5236 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005237 } else if (rec.currentTime != 0) {
5238 printed = true;
5239 byte cmd = rec.cmd;
5240 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005241 hprinter.printNextItem(pw, rec, baseTime, checkin,
5242 (flags&DUMP_VERBOSE) != 0);
5243 rec.cmd = cmd;
5244 }
5245 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005246 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5247 hprinter.printNextItem(pw, rec, baseTime, checkin,
5248 (flags&DUMP_VERBOSE) != 0);
5249 rec.cmd = HistoryItem.CMD_UPDATE;
5250 }
5251 int oldEventCode = rec.eventCode;
5252 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005253 rec.eventTag = new HistoryTag();
5254 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5255 HashMap<String, SparseIntArray> active
5256 = tracker.getStateForEvent(i);
5257 if (active == null) {
5258 continue;
5259 }
5260 for (HashMap.Entry<String, SparseIntArray> ent
5261 : active.entrySet()) {
5262 SparseIntArray uids = ent.getValue();
5263 for (int j=0; j<uids.size(); j++) {
5264 rec.eventCode = i;
5265 rec.eventTag.string = ent.getKey();
5266 rec.eventTag.uid = uids.keyAt(j);
5267 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005268 hprinter.printNextItem(pw, rec, baseTime, checkin,
5269 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005270 rec.wakeReasonTag = null;
5271 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005272 }
5273 }
5274 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005275 rec.eventCode = oldEventCode;
5276 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005277 tracker = null;
5278 }
5279 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005280 hprinter.printNextItem(pw, rec, baseTime, checkin,
5281 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005282 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5283 // This is an attempt to aggregate the previous state and generate
5284 // fake events to reflect that state at the point where we start
5285 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005286 if (tracker == null) {
5287 tracker = new HistoryEventTracker();
5288 }
5289 tracker.updateState(rec.eventCode, rec.eventTag.string,
5290 rec.eventTag.uid, rec.eventTag.poolIdx);
5291 }
5292 }
5293 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005294 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005295 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5296 }
5297 }
5298
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005299 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5300 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5301 if (steps == null) {
5302 return;
5303 }
5304 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5305 if (timeRemaining >= 0) {
5306 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5307 tmpSb.setLength(0);
5308 formatTimeMs(tmpSb, timeRemaining);
5309 pw.print(tmpSb);
5310 pw.print(" (from "); pw.print(tmpOutInt[0]);
5311 pw.println(" steps)");
5312 }
5313 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5314 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5315 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5316 if (estimatedTime > 0) {
5317 pw.print(prefix); pw.print(label); pw.print(" ");
5318 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5319 pw.print(" time: ");
5320 tmpSb.setLength(0);
5321 formatTimeMs(tmpSb, estimatedTime);
5322 pw.print(tmpSb);
5323 pw.print(" (from "); pw.print(tmpOutInt[0]);
5324 pw.println(" steps)");
5325 }
5326 }
5327 }
5328
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005329 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5330 ArrayList<PackageChange> changes) {
5331 if (changes == null) {
5332 return;
5333 }
5334 pw.print(prefix); pw.println("Package changes:");
5335 for (int i=0; i<changes.size(); i++) {
5336 PackageChange pc = changes.get(i);
5337 if (pc.mUpdate) {
5338 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5339 pw.print(" vers="); pw.println(pc.mVersionCode);
5340 } else {
5341 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5342 }
5343 }
5344 }
5345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005346 /**
5347 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5348 *
5349 * @param pw a Printer to receive the dump output.
5350 */
5351 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005352 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005353 prepareForDumpLocked();
5354
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005355 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005356 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005357
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005358 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005359 final long historyTotalSize = getHistoryTotalSize();
5360 final long historyUsedSize = getHistoryUsedSize();
5361 if (startIteratingHistoryLocked()) {
5362 try {
5363 pw.print("Battery History (");
5364 pw.print((100*historyUsedSize)/historyTotalSize);
5365 pw.print("% used, ");
5366 printSizeValue(pw, historyUsedSize);
5367 pw.print(" used of ");
5368 printSizeValue(pw, historyTotalSize);
5369 pw.print(", ");
5370 pw.print(getHistoryStringPoolSize());
5371 pw.print(" strings using ");
5372 printSizeValue(pw, getHistoryStringPoolBytes());
5373 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005374 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005375 pw.println();
5376 } finally {
5377 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005378 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005379 }
5380
5381 if (startIteratingOldHistoryLocked()) {
5382 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005383 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005384 pw.println("Old battery History:");
5385 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005386 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005387 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005388 if (baseTime < 0) {
5389 baseTime = rec.time;
5390 }
5391 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005392 }
5393 pw.println();
5394 } finally {
5395 finishIteratingOldHistoryLocked();
5396 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005397 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005398 }
5399
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005400 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005401 return;
5402 }
5403
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005404 if (!filtering) {
5405 SparseArray<? extends Uid> uidStats = getUidStats();
5406 final int NU = uidStats.size();
5407 boolean didPid = false;
5408 long nowRealtime = SystemClock.elapsedRealtime();
5409 for (int i=0; i<NU; i++) {
5410 Uid uid = uidStats.valueAt(i);
5411 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
5412 if (pids != null) {
5413 for (int j=0; j<pids.size(); j++) {
5414 Uid.Pid pid = pids.valueAt(j);
5415 if (!didPid) {
5416 pw.println("Per-PID Stats:");
5417 didPid = true;
5418 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005419 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
5420 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005421 pw.print(" PID "); pw.print(pids.keyAt(j));
5422 pw.print(" wake time: ");
5423 TimeUtils.formatDuration(time, pw);
5424 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005425 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005426 }
5427 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005428 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005429 pw.println();
5430 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005431 }
5432
5433 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005434 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
5435 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005436 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5437 if (timeRemaining >= 0) {
5438 pw.print(" Estimated discharge time remaining: ");
5439 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5440 pw.println();
5441 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005442 final LevelStepTracker steps = getDischargeLevelStepTracker();
5443 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5444 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
5445 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5446 STEP_LEVEL_MODE_VALUES[i], null));
5447 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005448 pw.println();
5449 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005450 if (dumpDurationSteps(pw, " ", "Charge step durations:",
5451 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005452 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5453 if (timeRemaining >= 0) {
5454 pw.print(" Estimated charge time remaining: ");
5455 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5456 pw.println();
5457 }
5458 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005459 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005460 }
5461 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
5462 pw.println("Daily stats:");
5463 pw.print(" Current start time: ");
5464 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5465 getCurrentDailyStartTime()).toString());
5466 pw.print(" Next min deadline: ");
5467 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5468 getNextMinDailyDeadline()).toString());
5469 pw.print(" Next max deadline: ");
5470 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5471 getNextMaxDailyDeadline()).toString());
5472 StringBuilder sb = new StringBuilder(64);
5473 int[] outInt = new int[1];
5474 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
5475 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005476 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
5477 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005478 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005479 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
5480 dsteps, false)) {
5481 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5482 sb, outInt);
5483 }
5484 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
5485 csteps, false)) {
5486 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5487 sb, outInt);
5488 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005489 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005490 } else {
5491 pw.println(" Current daily steps:");
5492 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5493 sb, outInt);
5494 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5495 sb, outInt);
5496 }
5497 }
5498 DailyItem dit;
5499 int curIndex = 0;
5500 while ((dit=getDailyItemLocked(curIndex)) != null) {
5501 curIndex++;
5502 if ((flags&DUMP_DAILY_ONLY) != 0) {
5503 pw.println();
5504 }
5505 pw.print(" Daily from ");
5506 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
5507 pw.print(" to ");
5508 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
5509 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005510 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005511 if (dumpDurationSteps(pw, " ",
5512 " Discharge step durations:", dit.mDischargeSteps, false)) {
5513 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5514 sb, outInt);
5515 }
5516 if (dumpDurationSteps(pw, " ",
5517 " Charge step durations:", dit.mChargeSteps, false)) {
5518 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5519 sb, outInt);
5520 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005521 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005522 } else {
5523 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5524 sb, outInt);
5525 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5526 sb, outInt);
5527 }
5528 }
5529 pw.println();
5530 }
5531 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005532 pw.println("Statistics since last charge:");
5533 pw.println(" System starts: " + getStartCount()
5534 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005535 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5536 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005537 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005538 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005539 }
5540
5541 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005542 public void dumpCheckinLocked(Context context, PrintWriter pw,
5543 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005544 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005545
5546 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005547 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5548 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005549
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005550 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5551
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005552 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005553 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005554
5555 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005556 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005557 try {
5558 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5559 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5560 pw.print(HISTORY_STRING_POOL); pw.print(',');
5561 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005562 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005563 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005564 pw.print(",\"");
5565 String str = getHistoryTagPoolString(i);
5566 str = str.replace("\\", "\\\\");
5567 str = str.replace("\"", "\\\"");
5568 pw.print(str);
5569 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005570 pw.println();
5571 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005572 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005573 } finally {
5574 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08005575 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005576 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005577 }
5578
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005579 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005580 return;
5581 }
5582
Dianne Hackborne4a59512010-12-07 11:08:07 -08005583 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005584 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08005585 for (int i=0; i<apps.size(); i++) {
5586 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005587 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
5588 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08005589 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005590 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
5591 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005592 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005593 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005594 }
5595 SparseArray<? extends Uid> uidStats = getUidStats();
5596 final int NU = uidStats.size();
5597 String[] lineArgs = new String[2];
5598 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005599 int uid = UserHandle.getAppId(uidStats.keyAt(i));
5600 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
5601 if (pkgs != null && !pkgs.second.value) {
5602 pkgs.second.value = true;
5603 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08005604 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005605 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005606 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
5607 (Object[])lineArgs);
5608 }
5609 }
5610 }
5611 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005612 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005613 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005614 String[] lineArgs = new String[1];
5615 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5616 if (timeRemaining >= 0) {
5617 lineArgs[0] = Long.toString(timeRemaining);
5618 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
5619 (Object[])lineArgs);
5620 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005621 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005622 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5623 if (timeRemaining >= 0) {
5624 lineArgs[0] = Long.toString(timeRemaining);
5625 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
5626 (Object[])lineArgs);
5627 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07005628 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
5629 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005630 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005631 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005632}