blob: cea5715d89e7a3c15709e26c2a3ea96fd1fd5b7f [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
Dianne Hackborn94326cb2017-06-28 16:17:20 -070019import android.app.job.JobParameters;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080020import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080021import android.content.pm.ApplicationInfo;
Wink Saville52840902011-02-18 12:40:47 -080022import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080023import android.text.format.DateFormat;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070024import android.util.ArrayMap;
James Carr2dd7e5e2016-07-20 18:48:39 -070025import android.util.LongSparseArray;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070026import android.util.MutableBoolean;
27import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.util.Printer;
29import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070030import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070031import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070032import android.view.Display;
Amith Yamasaniab9ad192016-12-06 12:46:59 -080033
Dianne Hackborna7c837f2014-01-15 16:20:44 -080034import com.android.internal.os.BatterySipper;
35import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -070037import java.io.PrintWriter;
38import java.util.ArrayList;
39import java.util.Collections;
40import java.util.Comparator;
41import java.util.Formatter;
42import java.util.HashMap;
43import java.util.List;
44import java.util.Map;
45
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046/**
47 * A class providing access to battery usage statistics, including information on
48 * wakelocks, processes, packages, and services. All times are represented in microseconds
49 * except where indicated otherwise.
50 * @hide
51 */
52public abstract class BatteryStats implements Parcelable {
Joe Onorato92fd23f2016-07-25 11:18:42 -070053 private static final String TAG = "BatteryStats";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
55 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070056
57 /** @hide */
58 public static final String SERVICE_NAME = "batterystats";
59
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 /**
61 * A constant indicating a partial wake lock timer.
62 */
63 public static final int WAKE_TYPE_PARTIAL = 0;
64
65 /**
66 * A constant indicating a full wake lock timer.
67 */
68 public static final int WAKE_TYPE_FULL = 1;
69
70 /**
71 * A constant indicating a window wake lock timer.
72 */
73 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 /**
76 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 */
78 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070079
80 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070081 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070082 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070083 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070084
85 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070086 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070087 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070088 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070089
90 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070091 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070092 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070093 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094
Dianne Hackborn62793e42015-03-09 11:15:41 -070095 /**
96 * A constant indicating a wifi multicast timer
97 */
98 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700101 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700102 */
103 public static final int VIDEO_TURNED_ON = 8;
104
105 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800106 * A constant indicating a vibrator on timer
107 */
108 public static final int VIBRATOR_ON = 9;
109
110 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700111 * A constant indicating a foreground activity timer
112 */
113 public static final int FOREGROUND_ACTIVITY = 10;
114
115 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700116 * A constant indicating a wifi batched scan is active
117 */
118 public static final int WIFI_BATCHED_SCAN = 11;
119
120 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700121 * A constant indicating a process state timer
122 */
123 public static final int PROCESS_STATE = 12;
124
125 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700126 * A constant indicating a sync timer
127 */
128 public static final int SYNC = 13;
129
130 /**
131 * A constant indicating a job timer
132 */
133 public static final int JOB = 14;
134
135 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800136 * A constant indicating an audio turn on timer
137 */
138 public static final int AUDIO_TURNED_ON = 15;
139
140 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700141 * A constant indicating a flashlight turn on timer
142 */
143 public static final int FLASHLIGHT_TURNED_ON = 16;
144
145 /**
146 * A constant indicating a camera turn on timer
147 */
148 public static final int CAMERA_TURNED_ON = 17;
149
150 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700151 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700152 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700153 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700154
155 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800156 * A constant indicating a bluetooth scan timer.
157 */
158 public static final int BLUETOOTH_SCAN_ON = 19;
159
160 /**
Bookatzc8c44962017-05-11 12:12:54 -0700161 * A constant indicating an aggregated partial wake lock timer.
162 */
163 public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20;
164
165 /**
Bookatzb1f04f32017-05-19 13:57:32 -0700166 * A constant indicating a bluetooth scan timer for unoptimized scans.
167 */
168 public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21;
169
170 /**
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700171 * A constant indicating a foreground service timer
172 */
173 public static final int FOREGROUND_SERVICE = 22;
174
175 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 * Include all of the data in the stats, including previously saved data.
177 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700178 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179
180 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 * Include only the current run in the stats.
182 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700183 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184
185 /**
186 * Include only the run since the last time the device was unplugged in the stats.
187 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700188 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700189
190 // NOTE: Update this list if you add/change any stats above.
191 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700192 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700193 private static final String[] STAT_NAMES = { "l", "c", "u" };
194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700196 * Current version of checkin data format.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700197 *
198 * New in version 19:
199 * - Wakelock data (wl) gets current and max times.
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800200 * New in version 20:
Bookatz2bffb5b2017-04-13 11:59:33 -0700201 * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs.
Bookatz506a8182017-05-01 14:18:42 -0700202 * New in version 21:
203 * - Actual (not just apportioned) Wakelock time is also recorded.
Bookatzc8c44962017-05-11 12:12:54 -0700204 * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded.
Bookatzb1f04f32017-05-19 13:57:32 -0700205 * - BLE scan result count
206 * - CPU frequency time per uid
207 * New in version 22:
208 * - BLE scan result background count, BLE unoptimized scan time
Bookatz98d4d5c2017-08-01 19:07:54 -0700209 * - Background partial wakelock time & count
210 * New in version 23:
211 * - Logging smeared power model values
212 * New in version 24:
213 * - Fixed bugs in background timers and BLE scan time
214 * New in version 25:
215 * - Package wakeup alarms are now on screen-off timebase
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700216 */
Bookatz98d4d5c2017-08-01 19:07:54 -0700217 static final String CHECKIN_VERSION = "25";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700218
219 /**
220 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700222 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700223
Evan Millar22ac0432009-03-31 11:33:18 -0700224 private static final long BYTES_PER_KB = 1024;
225 private static final long BYTES_PER_MB = 1048576; // 1024^2
226 private static final long BYTES_PER_GB = 1073741824; //1024^3
Bookatz506a8182017-05-01 14:18:42 -0700227
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700228 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800229 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700230 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700232 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700233 private static final String CPU_DATA = "cpu";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700234 private static final String GLOBAL_CPU_FREQ_DATA = "gcf";
235 private static final String CPU_TIMES_AT_FREQ_DATA = "ctf";
Evan Millare84de8d2009-04-02 22:16:12 -0700236 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800237 private static final String VIBRATOR_DATA = "vib";
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700238 private static final String FOREGROUND_ACTIVITY_DATA = "fg";
239 // fgs line is:
240 // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs",
241 // foreground service time, count
242 private static final String FOREGROUND_SERVICE_DATA = "fgs";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700243 private static final String STATE_TIME_DATA = "st";
Bookatz506a8182017-05-01 14:18:42 -0700244 // wl line is:
245 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
Bookatz5b5ec322017-05-26 09:40:38 -0700246 // full totalTime, 'f', count, current duration, max duration, total duration,
247 // partial totalTime, 'p', count, current duration, max duration, total duration,
248 // bg partial totalTime, 'bp', count, current duration, max duration, total duration,
249 // window totalTime, 'w', count, current duration, max duration, total duration
Bookatz506a8182017-05-01 14:18:42 -0700250 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700251 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700252 // awl line is:
253 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
254 // cumulative partial wakelock duration, cumulative background partial wakelock duration
255 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700256 private static final String SYNC_DATA = "sy";
257 private static final String JOB_DATA = "jb";
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700258 private static final String JOB_COMPLETION_DATA = "jbc";
Evan Millarc64edde2009-04-18 12:26:32 -0700259 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700260 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700261 private static final String NETWORK_DATA = "nt";
262 private static final String USER_ACTIVITY_DATA = "ua";
263 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800264 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700265 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700266 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700267 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800268 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
269 private static final String WIFI_CONTROLLER_DATA = "wfcd";
270 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
271 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700272 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700273 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800274 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800275 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
276 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800277 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700278 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700279 private static final String SCREEN_BRIGHTNESS_DATA = "br";
280 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700281 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700282 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
283 private static final String DATA_CONNECTION_TIME_DATA = "dct";
284 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800285 private static final String WIFI_STATE_TIME_DATA = "wst";
286 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700287 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
288 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
289 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
290 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800291 private static final String POWER_USE_SUMMARY_DATA = "pws";
292 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700293 private static final String DISCHARGE_STEP_DATA = "dsd";
294 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700295 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
296 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700297 private static final String FLASHLIGHT_DATA = "fla";
298 private static final String CAMERA_DATA = "cam";
299 private static final String VIDEO_DATA = "vid";
300 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301
Adam Lesinski010bf372016-04-11 12:18:18 -0700302 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
303
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700304 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 private final Formatter mFormatter = new Formatter(mFormatBuilder);
306
307 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700308 * Indicates times spent by the uid at each cpu frequency in all process states.
309 *
310 * Other types might include times spent in foreground, background etc.
311 */
312 private final String UID_TIMES_TYPE_ALL = "A";
313
314 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700315 * State for keeping track of counting information.
316 */
317 public static abstract class Counter {
318
319 /**
320 * Returns the count associated with this Counter for the
321 * selected type of statistics.
322 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700323 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700324 */
Evan Millarc64edde2009-04-18 12:26:32 -0700325 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700326
327 /**
328 * Temporary for debugging.
329 */
330 public abstract void logState(Printer pw, String prefix);
331 }
332
333 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700334 * State for keeping track of long counting information.
335 */
336 public static abstract class LongCounter {
337
338 /**
339 * Returns the count associated with this Counter for the
340 * selected type of statistics.
341 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700342 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700343 */
344 public abstract long getCountLocked(int which);
345
346 /**
347 * Temporary for debugging.
348 */
349 public abstract void logState(Printer pw, String prefix);
350 }
351
352 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700353 * State for keeping track of array of long counting information.
354 */
355 public static abstract class LongCounterArray {
356 /**
357 * Returns the counts associated with this Counter for the
358 * selected type of statistics.
359 *
360 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
361 */
362 public abstract long[] getCountsLocked(int which);
363
364 /**
365 * Temporary for debugging.
366 */
367 public abstract void logState(Printer pw, String prefix);
368 }
369
370 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800371 * Container class that aggregates counters for transmit, receive, and idle state of a
372 * radio controller.
373 */
374 public static abstract class ControllerActivityCounter {
375 /**
376 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
377 * idle state.
378 */
379 public abstract LongCounter getIdleTimeCounter();
380
381 /**
382 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
383 * receive state.
384 */
385 public abstract LongCounter getRxTimeCounter();
386
387 /**
388 * An array of {@link LongCounter}, representing various transmit levels, where each level
389 * may draw a different amount of power. The levels themselves are controller-specific.
390 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
391 * various transmit level states.
392 */
393 public abstract LongCounter[] getTxTimeCounters();
394
395 /**
396 * @return a non-null {@link LongCounter} representing the power consumed by the controller
397 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
398 * yield a value of 0 if the device doesn't support power calculations.
399 */
400 public abstract LongCounter getPowerCounter();
401 }
402
403 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 * State for keeping track of timing information.
405 */
406 public static abstract class Timer {
407
408 /**
409 * Returns the count associated with this Timer for the
410 * selected type of statistics.
411 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700412 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 */
Evan Millarc64edde2009-04-18 12:26:32 -0700414 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415
416 /**
417 * Returns the total time in microseconds associated with this Timer for the
418 * selected type of statistics.
419 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800420 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700421 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 * @return a time in microseconds
423 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800424 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700427 * Returns the total time in microseconds associated with this Timer since the
428 * 'mark' was last set.
429 *
430 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
431 * @return a time in microseconds
432 */
433 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
434
435 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700436 * Returns the max duration if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800437 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700438
439 */
440 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
441 return -1;
442 }
443
444 /**
445 * Returns the current time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800446 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700447 */
448 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
449 return -1;
450 }
451
452 /**
Bookatz867c0d72017-03-07 18:23:42 -0800453 * Returns the current time the timer has been active, if it is being tracked.
454 *
455 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
456 * been on since reset.
457 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
458 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
459 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
460 * the actual total time.
461 * Not all Timer subclasses track the max, total, current durations.
462 */
463 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
464 return -1;
465 }
466
467 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700468 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
469 * used, for example, for tracking background usage. Secondary timers are never pooled.
470 *
471 * Not all Timer subclasses have a secondary timer; those that don't return null.
472 */
473 public Timer getSubTimer() {
474 return null;
475 }
476
477 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700478 * Returns whether the timer is currently running. Some types of timers
479 * (e.g. BatchTimers) don't know whether the event is currently active,
480 * and report false.
481 */
482 public boolean isRunningLocked() {
483 return false;
484 }
485
486 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 * Temporary for debugging.
488 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700489 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 }
491
492 /**
493 * The statistics associated with a particular uid.
494 */
495 public static abstract class Uid {
496
497 /**
498 * Returns a mapping containing wakelock statistics.
499 *
500 * @return a Map from Strings to Uid.Wakelock objects.
501 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700502 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503
504 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700505 * Returns a mapping containing sync statistics.
506 *
507 * @return a Map from Strings to Timer objects.
508 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700509 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700510
511 /**
512 * Returns a mapping containing scheduled job statistics.
513 *
514 * @return a Map from Strings to Timer objects.
515 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700516 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700517
518 /**
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700519 * Returns statistics about how jobs have completed.
520 *
521 * @return A Map of String job names to completion type -> count mapping.
522 */
523 public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats();
524
525 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 * The statistics associated with a particular wake lock.
527 */
528 public static abstract class Wakelock {
529 public abstract Timer getWakeTime(int type);
530 }
531
532 /**
Bookatzc8c44962017-05-11 12:12:54 -0700533 * The cumulative time the uid spent holding any partial wakelocks. This will generally
534 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
535 * wakelocks that overlap in time (and therefore over-counts).
536 */
537 public abstract Timer getAggregatedPartialWakelockTimer();
538
539 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 * Returns a mapping containing sensor statistics.
541 *
542 * @return a Map from Integer sensor ids to Uid.Sensor objects.
543 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700544 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545
546 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700547 * Returns a mapping containing active process data.
548 */
549 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700550
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700551 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 * Returns a mapping containing process statistics.
553 *
554 * @return a Map from Strings to Uid.Proc objects.
555 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700556 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557
558 /**
559 * Returns a mapping containing package statistics.
560 *
561 * @return a Map from Strings to Uid.Pkg objects.
562 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700563 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700564
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800565 public abstract ControllerActivityCounter getWifiControllerActivity();
566 public abstract ControllerActivityCounter getBluetoothControllerActivity();
567 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800568
569 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 * {@hide}
571 */
572 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700573
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800574 public abstract void noteWifiRunningLocked(long elapsedRealtime);
575 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
576 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
577 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
578 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
579 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
580 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
581 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
582 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
583 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800584 public abstract void noteActivityResumedLocked(long elapsedRealtime);
585 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800586 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
587 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
588 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700589 public abstract int getWifiScanCount(int which);
Bookatz867c0d72017-03-07 18:23:42 -0800590 public abstract int getWifiScanBackgroundCount(int which);
591 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
592 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800593 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700594 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800595 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700596 public abstract Timer getAudioTurnedOnTimer();
597 public abstract Timer getVideoTurnedOnTimer();
598 public abstract Timer getFlashlightTurnedOnTimer();
599 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700600 public abstract Timer getForegroundActivityTimer();
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700601
602 /**
603 * Returns the timer keeping track of Foreground Service time
604 */
605 public abstract Timer getForegroundServiceTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800606 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800607 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatzb1f04f32017-05-19 13:57:32 -0700608 public abstract Timer getBluetoothUnoptimizedScanTimer();
609 public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700610 public abstract Counter getBluetoothScanResultCounter();
Bookatzb1f04f32017-05-19 13:57:32 -0700611 public abstract Counter getBluetoothScanResultBgCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700612
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700613 public abstract long[] getCpuFreqTimes(int which);
614 public abstract long[] getScreenOffCpuFreqTimes(int which);
615
Dianne Hackborna0200e32016-03-30 18:01:41 -0700616 // Note: the following times are disjoint. They can be added together to find the
617 // total time a uid has had any processes running at all.
618
619 /**
620 * Time this uid has any processes in the top state (or above such as persistent).
621 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800622 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700623 /**
624 * Time this uid has any process with a started out bound foreground service, but
625 * none in the "top" state.
626 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800627 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700628 /**
629 * Time this uid has any process that is top while the device is sleeping, but none
630 * in the "foreground service" or better state.
631 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800632 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700633 /**
634 * Time this uid has any process in an active foreground state, but none in the
635 * "top sleeping" or better state.
636 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800637 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700638 /**
639 * Time this uid has any process in an active background state, but none in the
640 * "foreground" or better state.
641 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800642 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700643 /**
644 * Time this uid has any processes that are sitting around cached, not in one of the
645 * other active states.
646 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800647 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700648 /**
649 * Total number of process states we track.
650 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800651 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700652
653 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800654 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700655 };
656
657 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800658 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700659
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800660 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661
Robert Greenwalta029ea12013-09-25 16:38:12 -0700662 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
663
Dianne Hackborn617f8772009-03-31 15:04:46 -0700664 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700665 * Note that these must match the constants in android.os.PowerManager.
666 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
667 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700668 */
669 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700670 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700671 };
Bookatzc8c44962017-05-11 12:12:54 -0700672
Phil Weaverda80d672016-03-15 16:25:46 -0700673 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700674
Dianne Hackborn617f8772009-03-31 15:04:46 -0700675 public abstract void noteUserActivityLocked(int type);
676 public abstract boolean hasUserActivity();
677 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700678
679 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800680 public abstract long getNetworkActivityBytes(int type, int which);
681 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800682 public abstract long getMobileRadioActiveTime(int which);
683 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700684
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700685 /**
686 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
687 */
688 public abstract long getUserCpuTimeUs(int which);
689
690 /**
691 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
692 */
693 public abstract long getSystemCpuTimeUs(int which);
694
695 /**
Sudheer Shanka71f34b32017-07-21 00:14:24 -0700696 * Returns the approximate cpu time (in microseconds) spent at a certain CPU speed for a
Adam Lesinski6832f392015-09-05 18:05:40 -0700697 * given CPU cluster.
698 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700699 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700700 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700701 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
702 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700703 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700704 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700705
Adam Lesinski5f056f62016-07-14 16:56:08 -0700706 /**
707 * Returns the number of times this UID woke up the Application Processor to
708 * process a mobile radio packet.
709 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
710 */
711 public abstract long getMobileRadioApWakeupCount(int which);
712
713 /**
714 * Returns the number of times this UID woke up the Application Processor to
715 * process a WiFi packet.
716 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
717 */
718 public abstract long getWifiRadioApWakeupCount(int which);
719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800721 /*
722 * FIXME: it's not correct to use this magic value because it
723 * could clash with a sensor handle (which are defined by
724 * the sensor HAL, and therefore out of our control
725 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 // Magic sensor number for the GPS.
727 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800730
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800732
Bookatz867c0d72017-03-07 18:23:42 -0800733 /** Returns a Timer for sensor usage when app is in the background. */
734 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 }
736
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700737 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800738 public int mWakeNesting;
739 public long mWakeSumMs;
740 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700741 }
742
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 /**
744 * The statistics associated with a particular process.
745 */
746 public static abstract class Proc {
747
Dianne Hackborn287952c2010-09-22 22:34:31 -0700748 public static class ExcessivePower {
749 public static final int TYPE_WAKE = 1;
750 public static final int TYPE_CPU = 2;
751
752 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700753 public long overTime;
754 public long usedTime;
755 }
756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800758 * Returns true if this process is still active in the battery stats.
759 */
760 public abstract boolean isActive();
761
762 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700763 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700765 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 */
767 public abstract long getUserTime(int which);
768
769 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700770 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700772 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 */
774 public abstract long getSystemTime(int which);
775
776 /**
777 * Returns the number of times the process has been started.
778 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700779 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 */
781 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700782
783 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800784 * Returns the number of times the process has crashed.
785 *
786 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
787 */
788 public abstract int getNumCrashes(int which);
789
790 /**
791 * Returns the number of times the process has ANRed.
792 *
793 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
794 */
795 public abstract int getNumAnrs(int which);
796
797 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700798 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700799 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700800 * @return foreground cpu time in microseconds
801 */
802 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700803
Dianne Hackborn287952c2010-09-22 22:34:31 -0700804 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700805
Dianne Hackborn287952c2010-09-22 22:34:31 -0700806 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 }
808
809 /**
810 * The statistics associated with a particular package.
811 */
812 public static abstract class Pkg {
813
814 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700815 * Returns information about all wakeup alarms that have been triggered for this
816 * package. The mapping keys are tag names for the alarms, the counter contains
817 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700819 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820
821 /**
822 * Returns a mapping containing service statistics.
823 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700824 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825
826 /**
827 * The statistics associated with a particular service.
828 */
Joe Onoratoabded112016-02-08 16:49:39 -0800829 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830
831 /**
832 * Returns the amount of time spent started.
833 *
834 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700835 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 * @return
837 */
838 public abstract long getStartTime(long batteryUptime, int which);
839
840 /**
841 * Returns the total number of times startService() has been called.
842 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700843 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 */
845 public abstract int getStarts(int which);
846
847 /**
848 * Returns the total number times the service has been launched.
849 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700850 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800851 */
852 public abstract int getLaunches(int which);
853 }
854 }
855 }
856
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800857 public static final class LevelStepTracker {
858 public long mLastStepTime = -1;
859 public int mNumStepDurations;
860 public final long[] mStepDurations;
861
862 public LevelStepTracker(int maxLevelSteps) {
863 mStepDurations = new long[maxLevelSteps];
864 }
865
866 public LevelStepTracker(int numSteps, long[] steps) {
867 mNumStepDurations = numSteps;
868 mStepDurations = new long[numSteps];
869 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
870 }
871
872 public long getDurationAt(int index) {
873 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
874 }
875
876 public int getLevelAt(int index) {
877 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
878 >> STEP_LEVEL_LEVEL_SHIFT);
879 }
880
881 public int getInitModeAt(int index) {
882 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
883 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
884 }
885
886 public int getModModeAt(int index) {
887 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
888 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
889 }
890
891 private void appendHex(long val, int topOffset, StringBuilder out) {
892 boolean hasData = false;
893 while (topOffset >= 0) {
894 int digit = (int)( (val>>topOffset) & 0xf );
895 topOffset -= 4;
896 if (!hasData && digit == 0) {
897 continue;
898 }
899 hasData = true;
900 if (digit >= 0 && digit <= 9) {
901 out.append((char)('0' + digit));
902 } else {
903 out.append((char)('a' + digit - 10));
904 }
905 }
906 }
907
908 public void encodeEntryAt(int index, StringBuilder out) {
909 long item = mStepDurations[index];
910 long duration = item & STEP_LEVEL_TIME_MASK;
911 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
912 >> STEP_LEVEL_LEVEL_SHIFT);
913 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
914 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
915 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
916 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
917 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
918 case Display.STATE_OFF: out.append('f'); break;
919 case Display.STATE_ON: out.append('o'); break;
920 case Display.STATE_DOZE: out.append('d'); break;
921 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
922 }
923 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
924 out.append('p');
925 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700926 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
927 out.append('i');
928 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800929 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
930 case Display.STATE_OFF: out.append('F'); break;
931 case Display.STATE_ON: out.append('O'); break;
932 case Display.STATE_DOZE: out.append('D'); break;
933 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
934 }
935 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
936 out.append('P');
937 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700938 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
939 out.append('I');
940 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800941 out.append('-');
942 appendHex(level, 4, out);
943 out.append('-');
944 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
945 }
946
947 public void decodeEntryAt(int index, String value) {
948 final int N = value.length();
949 int i = 0;
950 char c;
951 long out = 0;
952 while (i < N && (c=value.charAt(i)) != '-') {
953 i++;
954 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800955 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800956 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800957 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800958 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800959 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800960 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800961 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
962 << STEP_LEVEL_INITIAL_MODE_SHIFT);
963 break;
964 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
965 << STEP_LEVEL_INITIAL_MODE_SHIFT);
966 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700967 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
968 << STEP_LEVEL_INITIAL_MODE_SHIFT);
969 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800970 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
971 break;
972 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
973 break;
974 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
975 break;
976 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
977 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
978 break;
979 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
980 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800981 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700982 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
983 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
984 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800985 }
986 }
987 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800988 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800989 while (i < N && (c=value.charAt(i)) != '-') {
990 i++;
991 level <<= 4;
992 if (c >= '0' && c <= '9') {
993 level += c - '0';
994 } else if (c >= 'a' && c <= 'f') {
995 level += c - 'a' + 10;
996 } else if (c >= 'A' && c <= 'F') {
997 level += c - 'A' + 10;
998 }
999 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001000 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001001 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
1002 long duration = 0;
1003 while (i < N && (c=value.charAt(i)) != '-') {
1004 i++;
1005 duration <<= 4;
1006 if (c >= '0' && c <= '9') {
1007 duration += c - '0';
1008 } else if (c >= 'a' && c <= 'f') {
1009 duration += c - 'a' + 10;
1010 } else if (c >= 'A' && c <= 'F') {
1011 duration += c - 'A' + 10;
1012 }
1013 }
1014 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
1015 }
1016
1017 public void init() {
1018 mLastStepTime = -1;
1019 mNumStepDurations = 0;
1020 }
1021
1022 public void clearTime() {
1023 mLastStepTime = -1;
1024 }
1025
1026 public long computeTimePerLevel() {
1027 final long[] steps = mStepDurations;
1028 final int numSteps = mNumStepDurations;
1029
1030 // For now we'll do a simple average across all steps.
1031 if (numSteps <= 0) {
1032 return -1;
1033 }
1034 long total = 0;
1035 for (int i=0; i<numSteps; i++) {
1036 total += steps[i] & STEP_LEVEL_TIME_MASK;
1037 }
1038 return total / numSteps;
1039 /*
1040 long[] buckets = new long[numSteps];
1041 int numBuckets = 0;
1042 int numToAverage = 4;
1043 int i = 0;
1044 while (i < numSteps) {
1045 long totalTime = 0;
1046 int num = 0;
1047 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1048 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1049 num++;
1050 }
1051 buckets[numBuckets] = totalTime / num;
1052 numBuckets++;
1053 numToAverage *= 2;
1054 i += num;
1055 }
1056 if (numBuckets < 1) {
1057 return -1;
1058 }
1059 long averageTime = buckets[numBuckets-1];
1060 for (i=numBuckets-2; i>=0; i--) {
1061 averageTime = (averageTime + buckets[i]) / 2;
1062 }
1063 return averageTime;
1064 */
1065 }
1066
1067 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1068 int[] outNumOfInterest) {
1069 final long[] steps = mStepDurations;
1070 final int count = mNumStepDurations;
1071 if (count <= 0) {
1072 return -1;
1073 }
1074 long total = 0;
1075 int numOfInterest = 0;
1076 for (int i=0; i<count; i++) {
1077 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1078 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1079 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1080 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1081 // If the modes of interest didn't change during this step period...
1082 if ((modMode&modesOfInterest) == 0) {
1083 // And the mode values during this period match those we are measuring...
1084 if ((initMode&modesOfInterest) == modeValues) {
1085 // Then this can be used to estimate the total time!
1086 numOfInterest++;
1087 total += steps[i] & STEP_LEVEL_TIME_MASK;
1088 }
1089 }
1090 }
1091 if (numOfInterest <= 0) {
1092 return -1;
1093 }
1094
1095 if (outNumOfInterest != null) {
1096 outNumOfInterest[0] = numOfInterest;
1097 }
1098
1099 // The estimated time is the average time we spend in each level, multipled
1100 // by 100 -- the total number of battery levels
1101 return (total / numOfInterest) * 100;
1102 }
1103
1104 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1105 int stepCount = mNumStepDurations;
1106 final long lastStepTime = mLastStepTime;
1107 if (lastStepTime >= 0 && numStepLevels > 0) {
1108 final long[] steps = mStepDurations;
1109 long duration = elapsedRealtime - lastStepTime;
1110 for (int i=0; i<numStepLevels; i++) {
1111 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1112 long thisDuration = duration / (numStepLevels-i);
1113 duration -= thisDuration;
1114 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1115 thisDuration = STEP_LEVEL_TIME_MASK;
1116 }
1117 steps[0] = thisDuration | modeBits;
1118 }
1119 stepCount += numStepLevels;
1120 if (stepCount > steps.length) {
1121 stepCount = steps.length;
1122 }
1123 }
1124 mNumStepDurations = stepCount;
1125 mLastStepTime = elapsedRealtime;
1126 }
1127
1128 public void readFromParcel(Parcel in) {
1129 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001130 if (N > mStepDurations.length) {
1131 throw new ParcelFormatException("more step durations than available: " + N);
1132 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001133 mNumStepDurations = N;
1134 for (int i=0; i<N; i++) {
1135 mStepDurations[i] = in.readLong();
1136 }
1137 }
1138
1139 public void writeToParcel(Parcel out) {
1140 final int N = mNumStepDurations;
1141 out.writeInt(N);
1142 for (int i=0; i<N; i++) {
1143 out.writeLong(mStepDurations[i]);
1144 }
1145 }
1146 }
1147
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001148 public static final class PackageChange {
1149 public String mPackageName;
1150 public boolean mUpdate;
1151 public int mVersionCode;
1152 }
1153
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001154 public static final class DailyItem {
1155 public long mStartTime;
1156 public long mEndTime;
1157 public LevelStepTracker mDischargeSteps;
1158 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001159 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001160 }
1161
1162 public abstract DailyItem getDailyItemLocked(int daysAgo);
1163
1164 public abstract long getCurrentDailyStartTime();
1165
1166 public abstract long getNextMinDailyDeadline();
1167
1168 public abstract long getNextMaxDailyDeadline();
1169
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001170 public abstract long[] getCpuFreqs();
1171
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001172 public final static class HistoryTag {
1173 public String string;
1174 public int uid;
1175
1176 public int poolIdx;
1177
1178 public void setTo(HistoryTag o) {
1179 string = o.string;
1180 uid = o.uid;
1181 poolIdx = o.poolIdx;
1182 }
1183
1184 public void setTo(String _string, int _uid) {
1185 string = _string;
1186 uid = _uid;
1187 poolIdx = -1;
1188 }
1189
1190 public void writeToParcel(Parcel dest, int flags) {
1191 dest.writeString(string);
1192 dest.writeInt(uid);
1193 }
1194
1195 public void readFromParcel(Parcel src) {
1196 string = src.readString();
1197 uid = src.readInt();
1198 poolIdx = -1;
1199 }
1200
1201 @Override
1202 public boolean equals(Object o) {
1203 if (this == o) return true;
1204 if (o == null || getClass() != o.getClass()) return false;
1205
1206 HistoryTag that = (HistoryTag) o;
1207
1208 if (uid != that.uid) return false;
1209 if (!string.equals(that.string)) return false;
1210
1211 return true;
1212 }
1213
1214 @Override
1215 public int hashCode() {
1216 int result = string.hashCode();
1217 result = 31 * result + uid;
1218 return result;
1219 }
1220 }
1221
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001222 /**
1223 * Optional detailed information that can go into a history step. This is typically
1224 * generated each time the battery level changes.
1225 */
1226 public final static class HistoryStepDetails {
1227 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1228 public int userTime;
1229 public int systemTime;
1230
1231 // Top three apps using CPU in the last step, with times in 1/100 second.
1232 public int appCpuUid1;
1233 public int appCpuUTime1;
1234 public int appCpuSTime1;
1235 public int appCpuUid2;
1236 public int appCpuUTime2;
1237 public int appCpuSTime2;
1238 public int appCpuUid3;
1239 public int appCpuUTime3;
1240 public int appCpuSTime3;
1241
1242 // Information from /proc/stat
1243 public int statUserTime;
1244 public int statSystemTime;
1245 public int statIOWaitTime;
1246 public int statIrqTime;
1247 public int statSoftIrqTime;
1248 public int statIdlTime;
1249
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001250 // Platform-level low power state stats
1251 public String statPlatformIdleState;
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001252 public String statSubsystemPowerState;
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001253
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001254 public HistoryStepDetails() {
1255 clear();
1256 }
1257
1258 public void clear() {
1259 userTime = systemTime = 0;
1260 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1261 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1262 = appCpuUTime3 = appCpuSTime3 = 0;
1263 }
1264
1265 public void writeToParcel(Parcel out) {
1266 out.writeInt(userTime);
1267 out.writeInt(systemTime);
1268 out.writeInt(appCpuUid1);
1269 out.writeInt(appCpuUTime1);
1270 out.writeInt(appCpuSTime1);
1271 out.writeInt(appCpuUid2);
1272 out.writeInt(appCpuUTime2);
1273 out.writeInt(appCpuSTime2);
1274 out.writeInt(appCpuUid3);
1275 out.writeInt(appCpuUTime3);
1276 out.writeInt(appCpuSTime3);
1277 out.writeInt(statUserTime);
1278 out.writeInt(statSystemTime);
1279 out.writeInt(statIOWaitTime);
1280 out.writeInt(statIrqTime);
1281 out.writeInt(statSoftIrqTime);
1282 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001283 out.writeString(statPlatformIdleState);
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001284 out.writeString(statSubsystemPowerState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001285 }
1286
1287 public void readFromParcel(Parcel in) {
1288 userTime = in.readInt();
1289 systemTime = in.readInt();
1290 appCpuUid1 = in.readInt();
1291 appCpuUTime1 = in.readInt();
1292 appCpuSTime1 = in.readInt();
1293 appCpuUid2 = in.readInt();
1294 appCpuUTime2 = in.readInt();
1295 appCpuSTime2 = in.readInt();
1296 appCpuUid3 = in.readInt();
1297 appCpuUTime3 = in.readInt();
1298 appCpuSTime3 = in.readInt();
1299 statUserTime = in.readInt();
1300 statSystemTime = in.readInt();
1301 statIOWaitTime = in.readInt();
1302 statIrqTime = in.readInt();
1303 statSoftIrqTime = in.readInt();
1304 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001305 statPlatformIdleState = in.readString();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001306 statSubsystemPowerState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001307 }
1308 }
1309
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001310 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001311 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001312
1313 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001314 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001315
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001316 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001317 public static final byte CMD_NULL = -1;
1318 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001319 public static final byte CMD_CURRENT_TIME = 5;
1320 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001321 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001322 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001323
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001324 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001325
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001326 /**
1327 * Return whether the command code is a delta data update.
1328 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001329 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001330 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001331 }
1332
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001333 public byte batteryLevel;
1334 public byte batteryStatus;
1335 public byte batteryHealth;
1336 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001337
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001338 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001339 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001340
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001341 // The charge of the battery in micro-Ampere-hours.
1342 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001343
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001344 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001345 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001346 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001347 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001348 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1349 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001350 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001351 public static final int STATE_PHONE_STATE_SHIFT = 6;
1352 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001353 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001354 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001355 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001356
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001357 // These states always appear directly in the first int token
1358 // of a delta change; they should be ones that change relatively
1359 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001360 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1361 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001362 public static final int STATE_GPS_ON_FLAG = 1<<29;
1363 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001364 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001365 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001366 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001367 // Do not use, this is used for coulomb delta count.
1368 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001369 // These are on the lower bits used for the command; if they change
1370 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001371 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001372 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001373 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001374 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1375 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1376 // empty slot
1377 // empty slot
1378 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001379
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001380 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001381 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1382
1383 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001384
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001385 public int states;
1386
Dianne Hackborn3251b902014-06-20 14:40:53 -07001387 // Constants from WIFI_SUPPL_STATE_*
1388 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1389 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1390 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1391 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1392 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1393 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1394
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001395 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001396 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1397 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1398 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001399 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001400 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1401 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1402 public static final int STATE2_CHARGING_FLAG = 1<<24;
1403 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1404 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1405 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001406 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001407
1408 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001409 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001410 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1411
1412 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001413
Dianne Hackborn40c87252014-03-19 16:55:40 -07001414 public int states2;
1415
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001416 // The wake lock that was acquired at this point.
1417 public HistoryTag wakelockTag;
1418
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001419 // Kernel wakeup reason at this point.
1420 public HistoryTag wakeReasonTag;
1421
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001422 // Non-null when there is more detailed information at this step.
1423 public HistoryStepDetails stepDetails;
1424
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001425 public static final int EVENT_FLAG_START = 0x8000;
1426 public static final int EVENT_FLAG_FINISH = 0x4000;
1427
1428 // No event in this item.
1429 public static final int EVENT_NONE = 0x0000;
1430 // Event is about a process that is running.
1431 public static final int EVENT_PROC = 0x0001;
1432 // Event is about an application package that is in the foreground.
1433 public static final int EVENT_FOREGROUND = 0x0002;
1434 // Event is about an application package that is at the top of the screen.
1435 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001436 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001437 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001438 // Events for all additional wake locks aquired/release within a wake block.
1439 // These are not generated by default.
1440 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001441 // Event is about an application executing a scheduled job.
1442 public static final int EVENT_JOB = 0x0006;
1443 // Events for users running.
1444 public static final int EVENT_USER_RUNNING = 0x0007;
1445 // Events for foreground user.
1446 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001447 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001448 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001449 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001450 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001451 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001452 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001453 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001454 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001455 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001456 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001457 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001458 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001459 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001460 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001461 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001462 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001463 // Event for a package being on the temporary whitelist.
1464 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001465 // Event for the screen waking up.
1466 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001467 // Event for the UID that woke up the application processor.
1468 // Used for wakeups coming from WiFi, modem, etc.
1469 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001470 // Event for reporting that a specific partial wake lock has been held for a long duration.
1471 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001472
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001473 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001474 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001475 // Mask to extract out only the type part of the event.
1476 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001477
1478 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1479 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1480 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1481 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1482 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1483 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001484 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1485 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001486 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1487 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001488 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1489 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1490 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1491 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1492 public static final int EVENT_USER_FOREGROUND_START =
1493 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1494 public static final int EVENT_USER_FOREGROUND_FINISH =
1495 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001496 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1497 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001498 public static final int EVENT_TEMP_WHITELIST_START =
1499 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1500 public static final int EVENT_TEMP_WHITELIST_FINISH =
1501 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001502 public static final int EVENT_LONG_WAKE_LOCK_START =
1503 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1504 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1505 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001506
1507 // For CMD_EVENT.
1508 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001509 public HistoryTag eventTag;
1510
Dianne Hackborn9a755432014-05-15 17:05:22 -07001511 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001512 public long currentTime;
1513
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001514 // Meta-data when reading.
1515 public int numReadInts;
1516
1517 // Pre-allocated objects.
1518 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001519 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001520 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001521
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001522 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001523 }
Bookatzc8c44962017-05-11 12:12:54 -07001524
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001525 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001526 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001527 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001528 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001529 }
Bookatzc8c44962017-05-11 12:12:54 -07001530
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001531 public int describeContents() {
1532 return 0;
1533 }
1534
1535 public void writeToParcel(Parcel dest, int flags) {
1536 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001537 int bat = (((int)cmd)&0xff)
1538 | ((((int)batteryLevel)<<8)&0xff00)
1539 | ((((int)batteryStatus)<<16)&0xf0000)
1540 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001541 | ((((int)batteryPlugType)<<24)&0xf000000)
1542 | (wakelockTag != null ? 0x10000000 : 0)
1543 | (wakeReasonTag != null ? 0x20000000 : 0)
1544 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001545 dest.writeInt(bat);
1546 bat = (((int)batteryTemperature)&0xffff)
1547 | ((((int)batteryVoltage)<<16)&0xffff0000);
1548 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001549 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001550 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001551 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001552 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001553 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001554 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001555 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001556 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001557 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001558 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001559 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001560 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001561 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001562 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001563 dest.writeLong(currentTime);
1564 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001565 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001566
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001567 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001568 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001569 int bat = src.readInt();
1570 cmd = (byte)(bat&0xff);
1571 batteryLevel = (byte)((bat>>8)&0xff);
1572 batteryStatus = (byte)((bat>>16)&0xf);
1573 batteryHealth = (byte)((bat>>20)&0xf);
1574 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001575 int bat2 = src.readInt();
1576 batteryTemperature = (short)(bat2&0xffff);
1577 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001578 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001579 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001580 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001581 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001582 wakelockTag = localWakelockTag;
1583 wakelockTag.readFromParcel(src);
1584 } else {
1585 wakelockTag = null;
1586 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001587 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001588 wakeReasonTag = localWakeReasonTag;
1589 wakeReasonTag.readFromParcel(src);
1590 } else {
1591 wakeReasonTag = null;
1592 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001593 if ((bat&0x40000000) != 0) {
1594 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001595 eventTag = localEventTag;
1596 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001597 } else {
1598 eventCode = EVENT_NONE;
1599 eventTag = null;
1600 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001601 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001602 currentTime = src.readLong();
1603 } else {
1604 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001605 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001606 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001607 }
1608
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001609 public void clear() {
1610 time = 0;
1611 cmd = CMD_NULL;
1612 batteryLevel = 0;
1613 batteryStatus = 0;
1614 batteryHealth = 0;
1615 batteryPlugType = 0;
1616 batteryTemperature = 0;
1617 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001618 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001619 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001620 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001621 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001622 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001623 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001624 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001625 }
Bookatzc8c44962017-05-11 12:12:54 -07001626
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001627 public void setTo(HistoryItem o) {
1628 time = o.time;
1629 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001630 setToCommon(o);
1631 }
1632
1633 public void setTo(long time, byte cmd, HistoryItem o) {
1634 this.time = time;
1635 this.cmd = cmd;
1636 setToCommon(o);
1637 }
1638
1639 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001640 batteryLevel = o.batteryLevel;
1641 batteryStatus = o.batteryStatus;
1642 batteryHealth = o.batteryHealth;
1643 batteryPlugType = o.batteryPlugType;
1644 batteryTemperature = o.batteryTemperature;
1645 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001646 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001647 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001648 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001649 if (o.wakelockTag != null) {
1650 wakelockTag = localWakelockTag;
1651 wakelockTag.setTo(o.wakelockTag);
1652 } else {
1653 wakelockTag = null;
1654 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001655 if (o.wakeReasonTag != null) {
1656 wakeReasonTag = localWakeReasonTag;
1657 wakeReasonTag.setTo(o.wakeReasonTag);
1658 } else {
1659 wakeReasonTag = null;
1660 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001661 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001662 if (o.eventTag != null) {
1663 eventTag = localEventTag;
1664 eventTag.setTo(o.eventTag);
1665 } else {
1666 eventTag = null;
1667 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001668 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001669 }
1670
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001671 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001672 return batteryLevel == o.batteryLevel
1673 && batteryStatus == o.batteryStatus
1674 && batteryHealth == o.batteryHealth
1675 && batteryPlugType == o.batteryPlugType
1676 && batteryTemperature == o.batteryTemperature
1677 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001678 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001679 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001680 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001681 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001682 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001683
1684 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001685 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001686 return false;
1687 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001688 if (wakelockTag != o.wakelockTag) {
1689 if (wakelockTag == null || o.wakelockTag == null) {
1690 return false;
1691 }
1692 if (!wakelockTag.equals(o.wakelockTag)) {
1693 return false;
1694 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001695 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001696 if (wakeReasonTag != o.wakeReasonTag) {
1697 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1698 return false;
1699 }
1700 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1701 return false;
1702 }
1703 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001704 if (eventTag != o.eventTag) {
1705 if (eventTag == null || o.eventTag == null) {
1706 return false;
1707 }
1708 if (!eventTag.equals(o.eventTag)) {
1709 return false;
1710 }
1711 }
1712 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001713 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001714 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001715
1716 public final static class HistoryEventTracker {
1717 private final HashMap<String, SparseIntArray>[] mActiveEvents
1718 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1719
1720 public boolean updateState(int code, String name, int uid, int poolIdx) {
1721 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1722 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1723 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1724 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001725 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001726 mActiveEvents[idx] = active;
1727 }
1728 SparseIntArray uids = active.get(name);
1729 if (uids == null) {
1730 uids = new SparseIntArray();
1731 active.put(name, uids);
1732 }
1733 if (uids.indexOfKey(uid) >= 0) {
1734 // Already set, nothing to do!
1735 return false;
1736 }
1737 uids.put(uid, poolIdx);
1738 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1739 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1740 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1741 if (active == null) {
1742 // not currently active, nothing to do.
1743 return false;
1744 }
1745 SparseIntArray uids = active.get(name);
1746 if (uids == null) {
1747 // not currently active, nothing to do.
1748 return false;
1749 }
1750 idx = uids.indexOfKey(uid);
1751 if (idx < 0) {
1752 // not currently active, nothing to do.
1753 return false;
1754 }
1755 uids.removeAt(idx);
1756 if (uids.size() <= 0) {
1757 active.remove(name);
1758 }
1759 }
1760 return true;
1761 }
1762
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001763 public void removeEvents(int code) {
1764 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1765 mActiveEvents[idx] = null;
1766 }
1767
Dianne Hackborn37de0982014-05-09 09:32:18 -07001768 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1769 return mActiveEvents[code];
1770 }
1771 }
1772
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001773 public static final class BitDescription {
1774 public final int mask;
1775 public final int shift;
1776 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001777 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001778 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001779 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001780
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001781 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001782 this.mask = mask;
1783 this.shift = -1;
1784 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001785 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001786 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001787 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001788 }
Bookatzc8c44962017-05-11 12:12:54 -07001789
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001790 public BitDescription(int mask, int shift, String name, String shortName,
1791 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001792 this.mask = mask;
1793 this.shift = shift;
1794 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001795 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001796 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001797 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001798 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001799 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001800
Dianne Hackbornfc064132014-06-02 12:42:12 -07001801 /**
1802 * Don't allow any more batching in to the current history event. This
1803 * is called when printing partial histories, so to ensure that the next
1804 * history event will go in to a new batch after what was printed in the
1805 * last partial history.
1806 */
1807 public abstract void commitCurrentHistoryBatchLocked();
1808
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001809 public abstract int getHistoryTotalSize();
1810
1811 public abstract int getHistoryUsedSize();
1812
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001813 public abstract boolean startIteratingHistoryLocked();
1814
Dianne Hackborn099bc622014-01-22 13:39:16 -08001815 public abstract int getHistoryStringPoolSize();
1816
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001817 public abstract int getHistoryStringPoolBytes();
1818
1819 public abstract String getHistoryTagPoolString(int index);
1820
1821 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001822
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001823 public abstract boolean getNextHistoryLocked(HistoryItem out);
1824
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001825 public abstract void finishIteratingHistoryLocked();
1826
1827 public abstract boolean startIteratingOldHistoryLocked();
1828
1829 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1830
1831 public abstract void finishIteratingOldHistoryLocked();
1832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001834 * Return the base time offset for the battery history.
1835 */
1836 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001837
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001838 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 * Returns the number of times the device has been started.
1840 */
1841 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001843 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001844 * 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 -08001845 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001846 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 * {@hide}
1848 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001849 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001850
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001851 /**
1852 * Returns the number of times the screen was turned on.
1853 *
1854 * {@hide}
1855 */
1856 public abstract int getScreenOnCount(int which);
1857
Jeff Browne95c3cd2014-05-02 16:59:26 -07001858 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1859
Dianne Hackborn617f8772009-03-31 15:04:46 -07001860 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1861 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1862 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1863 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1864 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001865
Dianne Hackborn617f8772009-03-31 15:04:46 -07001866 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1867 "dark", "dim", "medium", "light", "bright"
1868 };
Bookatzc8c44962017-05-11 12:12:54 -07001869
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001870 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1871 "0", "1", "2", "3", "4"
1872 };
1873
Dianne Hackborn617f8772009-03-31 15:04:46 -07001874 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001875
Dianne Hackborn617f8772009-03-31 15:04:46 -07001876 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001877 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001878 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001879 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001880 * {@hide}
1881 */
1882 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001883 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001886 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001887 * running on battery.
1888 *
1889 * {@hide}
1890 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001891 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001892
1893 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001894 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001895 *
1896 * {@hide}
1897 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001898 public abstract int getPowerSaveModeEnabledCount(int which);
1899
1900 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001901 * Constant for device idle mode: not active.
1902 */
1903 public static final int DEVICE_IDLE_MODE_OFF = 0;
1904
1905 /**
1906 * Constant for device idle mode: active in lightweight mode.
1907 */
1908 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1909
1910 /**
1911 * Constant for device idle mode: active in full mode.
1912 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001913 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001914
1915 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001916 * Returns the time in microseconds that device has been in idle mode while
1917 * running on battery.
1918 *
1919 * {@hide}
1920 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001921 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001922
1923 /**
1924 * Returns the number of times that the devie has gone in to idle mode.
1925 *
1926 * {@hide}
1927 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001928 public abstract int getDeviceIdleModeCount(int mode, int which);
1929
1930 /**
1931 * Return the longest duration we spent in a particular device idle mode (fully in the
1932 * mode, not in idle maintenance etc).
1933 */
1934 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001935
1936 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001937 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001938 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001939 * counts all of the time that we consider the device to be idle, whether or not
1940 * it is currently in the actual device idle mode.
1941 *
1942 * {@hide}
1943 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001944 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001945
1946 /**
1947 * Returns the number of times that the devie has started idling.
1948 *
1949 * {@hide}
1950 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001951 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001952
1953 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001954 * Returns the number of times that connectivity state changed.
1955 *
1956 * {@hide}
1957 */
1958 public abstract int getNumConnectivityChange(int which);
1959
1960 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001961 * 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 -08001962 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001963 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 * {@hide}
1965 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001966 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001967
Dianne Hackborn627bba72009-03-24 22:32:56 -07001968 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001969 * Returns the number of times a phone call was activated.
1970 *
1971 * {@hide}
1972 */
1973 public abstract int getPhoneOnCount(int which);
1974
1975 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001976 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001977 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001978 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07001979 * {@hide}
1980 */
1981 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001982 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001983
Dianne Hackborn617f8772009-03-31 15:04:46 -07001984 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001985 * Returns the time in microseconds that the phone has been trying to
1986 * acquire a signal.
1987 *
1988 * {@hide}
1989 */
1990 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001991 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001992
1993 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001994 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001995 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001996 * {@hide}
1997 */
1998 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1999
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002000 /**
2001 * Returns the time in microseconds that the mobile network has been active
2002 * (in a high power state).
2003 *
2004 * {@hide}
2005 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002006 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002007
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002008 /**
2009 * Returns the number of times that the mobile network has transitioned to the
2010 * active state.
2011 *
2012 * {@hide}
2013 */
2014 public abstract int getMobileRadioActiveCount(int which);
2015
2016 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002017 * Returns the time in microseconds that is the difference between the mobile radio
2018 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
2019 * from the radio.
2020 *
2021 * {@hide}
2022 */
2023 public abstract long getMobileRadioActiveAdjustedTime(int which);
2024
2025 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002026 * Returns the time in microseconds that the mobile network has been active
2027 * (in a high power state) but not being able to blame on an app.
2028 *
2029 * {@hide}
2030 */
2031 public abstract long getMobileRadioActiveUnknownTime(int which);
2032
2033 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002034 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002035 *
2036 * {@hide}
2037 */
2038 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002039
Dianne Hackborn627bba72009-03-24 22:32:56 -07002040 public static final int DATA_CONNECTION_NONE = 0;
2041 public static final int DATA_CONNECTION_GPRS = 1;
2042 public static final int DATA_CONNECTION_EDGE = 2;
2043 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002044 public static final int DATA_CONNECTION_CDMA = 4;
2045 public static final int DATA_CONNECTION_EVDO_0 = 5;
2046 public static final int DATA_CONNECTION_EVDO_A = 6;
2047 public static final int DATA_CONNECTION_1xRTT = 7;
2048 public static final int DATA_CONNECTION_HSDPA = 8;
2049 public static final int DATA_CONNECTION_HSUPA = 9;
2050 public static final int DATA_CONNECTION_HSPA = 10;
2051 public static final int DATA_CONNECTION_IDEN = 11;
2052 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002053 public static final int DATA_CONNECTION_LTE = 13;
2054 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002055 public static final int DATA_CONNECTION_HSPAP = 15;
2056 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002057
Dianne Hackborn627bba72009-03-24 22:32:56 -07002058 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002059 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002060 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002061 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002062 };
Bookatzc8c44962017-05-11 12:12:54 -07002063
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002064 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002065
Dianne Hackborn627bba72009-03-24 22:32:56 -07002066 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002067 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002068 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002069 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002070 * {@hide}
2071 */
2072 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002073 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002076 * Returns the number of times the phone has entered the given data
2077 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002078 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002079 * {@hide}
2080 */
2081 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002082
Dianne Hackborn3251b902014-06-20 14:40:53 -07002083 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2084 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2085 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2086 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2087 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2088 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2089 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2090 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2091 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2092 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2093 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2094 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2095 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2096
2097 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2098
2099 static final String[] WIFI_SUPPL_STATE_NAMES = {
2100 "invalid", "disconn", "disabled", "inactive", "scanning",
2101 "authenticating", "associating", "associated", "4-way-handshake",
2102 "group-handshake", "completed", "dormant", "uninit"
2103 };
2104
2105 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2106 "inv", "dsc", "dis", "inact", "scan",
2107 "auth", "ascing", "asced", "4-way",
2108 "group", "compl", "dorm", "uninit"
2109 };
2110
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002111 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
2112 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002113 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002114 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2115 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002116 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002117 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2118 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2119 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002120 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002121 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002122 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002123 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002124 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2125 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002126 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2127 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2128 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2129 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2130 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2131 new String[] {"in", "out", "emergency", "off"},
2132 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002133 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2134 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2135 SignalStrength.SIGNAL_STRENGTH_NAMES,
2136 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002137 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2138 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2139 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002140 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002141
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002142 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2143 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002144 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002145 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002146 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002147 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002148 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002149 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2150 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2151 new String[] { "off", "light", "full", "???" },
2152 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002153 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2154 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2155 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002156 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2157 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2158 new String[] { "0", "1", "2", "3", "4" },
2159 new String[] { "0", "1", "2", "3", "4" }),
2160 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2161 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2162 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002163 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002164 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002165 };
2166
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002167 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002168 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002169 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2170 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002171 };
2172
2173 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002174 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002175 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002176 "Esw", "Ewa", "Elw", "Eec"
2177 };
2178
2179 @FunctionalInterface
2180 public interface IntToString {
2181 String applyAsString(int val);
2182 }
2183
2184 private static final IntToString sUidToString = UserHandle::formatUid;
2185 private static final IntToString sIntToString = Integer::toString;
2186
2187 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2188 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2189 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2190 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2191 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002192 };
2193
Dianne Hackborn617f8772009-03-31 15:04:46 -07002194 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002195 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002196 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002197 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002198 * {@hide}
2199 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002200 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002201
2202 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002203 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002204 * been in the running state while the device was running on battery.
2205 *
2206 * {@hide}
2207 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002208 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002209
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002210 public static final int WIFI_STATE_OFF = 0;
2211 public static final int WIFI_STATE_OFF_SCANNING = 1;
2212 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2213 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2214 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2215 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2216 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2217 public static final int WIFI_STATE_SOFT_AP = 7;
2218
2219 static final String[] WIFI_STATE_NAMES = {
2220 "off", "scanning", "no_net", "disconn",
2221 "sta", "p2p", "sta_p2p", "soft_ap"
2222 };
2223
2224 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2225
2226 /**
2227 * Returns the time in microseconds that WiFi has been running in the given state.
2228 *
2229 * {@hide}
2230 */
2231 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002232 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002233
2234 /**
2235 * Returns the number of times that WiFi has entered the given state.
2236 *
2237 * {@hide}
2238 */
2239 public abstract int getWifiStateCount(int wifiState, int which);
2240
The Android Open Source Project10592532009-03-18 17:39:46 -07002241 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002242 * Returns the time in microseconds that the wifi supplicant has been
2243 * in a given state.
2244 *
2245 * {@hide}
2246 */
2247 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2248
2249 /**
2250 * Returns the number of times that the wifi supplicant has transitioned
2251 * to a given state.
2252 *
2253 * {@hide}
2254 */
2255 public abstract int getWifiSupplStateCount(int state, int which);
2256
2257 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2258
2259 /**
2260 * Returns the time in microseconds that WIFI has been running with
2261 * the given signal strength.
2262 *
2263 * {@hide}
2264 */
2265 public abstract long getWifiSignalStrengthTime(int strengthBin,
2266 long elapsedRealtimeUs, int which);
2267
2268 /**
2269 * Returns the number of times WIFI has entered the given signal strength.
2270 *
2271 * {@hide}
2272 */
2273 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2274
2275 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002276 * Returns the time in microseconds that the flashlight has been on while the device was
2277 * running on battery.
2278 *
2279 * {@hide}
2280 */
2281 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2282
2283 /**
2284 * Returns the number of times that the flashlight has been turned on while the device was
2285 * running on battery.
2286 *
2287 * {@hide}
2288 */
2289 public abstract long getFlashlightOnCount(int which);
2290
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002291 /**
2292 * Returns the time in microseconds that the camera has been on while the device was
2293 * running on battery.
2294 *
2295 * {@hide}
2296 */
2297 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2298
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002299 /**
2300 * Returns the time in microseconds that bluetooth scans were running while the device was
2301 * on battery.
2302 *
2303 * {@hide}
2304 */
2305 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002306
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002307 public static final int NETWORK_MOBILE_RX_DATA = 0;
2308 public static final int NETWORK_MOBILE_TX_DATA = 1;
2309 public static final int NETWORK_WIFI_RX_DATA = 2;
2310 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002311 public static final int NETWORK_BT_RX_DATA = 4;
2312 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002313 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2314 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2315 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2316 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2317 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002318
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002319 public abstract long getNetworkActivityBytes(int type, int which);
2320 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002321
Adam Lesinskie08af192015-03-25 16:42:59 -07002322 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002323 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002324 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002325 * actual power data.
2326 */
2327 public abstract boolean hasWifiActivityReporting();
2328
2329 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002330 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2331 * in various radio controller states, such as transmit, receive, and idle.
2332 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002333 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002334 public abstract ControllerActivityCounter getWifiControllerActivity();
2335
2336 /**
2337 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2338 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2339 * actual power data.
2340 */
2341 public abstract boolean hasBluetoothActivityReporting();
2342
2343 /**
2344 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2345 * in various radio controller states, such as transmit, receive, and idle.
2346 * @return non-null {@link ControllerActivityCounter}
2347 */
2348 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2349
2350 /**
2351 * Returns true if the BatteryStats object has detailed modem power reports.
2352 * When true, calling {@link #getModemControllerActivity()} will yield the
2353 * actual power data.
2354 */
2355 public abstract boolean hasModemActivityReporting();
2356
2357 /**
2358 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2359 * in various radio controller states, such as transmit, receive, and idle.
2360 * @return non-null {@link ControllerActivityCounter}
2361 */
2362 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002363
The Android Open Source Project10592532009-03-18 17:39:46 -07002364 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002365 * Return the wall clock time when battery stats data collection started.
2366 */
2367 public abstract long getStartClockTime();
2368
2369 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002370 * Return platform version tag that we were running in when the battery stats started.
2371 */
2372 public abstract String getStartPlatformVersion();
2373
2374 /**
2375 * Return platform version tag that we were running in when the battery stats ended.
2376 */
2377 public abstract String getEndPlatformVersion();
2378
2379 /**
2380 * Return the internal version code of the parcelled format.
2381 */
2382 public abstract int getParcelVersion();
2383
2384 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 * Return whether we are currently running on battery.
2386 */
2387 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 /**
2390 * Returns a SparseArray containing the statistics for each uid.
2391 */
2392 public abstract SparseArray<? extends Uid> getUidStats();
2393
2394 /**
2395 * Returns the current battery uptime in microseconds.
2396 *
2397 * @param curTime the amount of elapsed realtime in microseconds.
2398 */
2399 public abstract long getBatteryUptime(long curTime);
2400
2401 /**
2402 * Returns the current battery realtime in microseconds.
2403 *
2404 * @param curTime the amount of elapsed realtime in microseconds.
2405 */
2406 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002407
The Android Open Source Project10592532009-03-18 17:39:46 -07002408 /**
Evan Millar633a1742009-04-02 16:36:33 -07002409 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002410 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002411 */
Evan Millar633a1742009-04-02 16:36:33 -07002412 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002413
The Android Open Source Project10592532009-03-18 17:39:46 -07002414 /**
Evan Millar633a1742009-04-02 16:36:33 -07002415 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2416 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002417 */
Evan Millar633a1742009-04-02 16:36:33 -07002418 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419
2420 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002421 * Get the amount the battery has discharged since the stats were
2422 * last reset after charging, as a lower-end approximation.
2423 */
2424 public abstract int getLowDischargeAmountSinceCharge();
2425
2426 /**
2427 * Get the amount the battery has discharged since the stats were
2428 * last reset after charging, as an upper-end approximation.
2429 */
2430 public abstract int getHighDischargeAmountSinceCharge();
2431
2432 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002433 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2434 */
2435 public abstract int getDischargeAmount(int which);
2436
2437 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002438 * Get the amount the battery has discharged while the screen was on,
2439 * since the last time power was unplugged.
2440 */
2441 public abstract int getDischargeAmountScreenOn();
2442
2443 /**
2444 * Get the amount the battery has discharged while the screen was on,
2445 * since the last time the device was charged.
2446 */
2447 public abstract int getDischargeAmountScreenOnSinceCharge();
2448
2449 /**
2450 * Get the amount the battery has discharged while the screen was off,
2451 * since the last time power was unplugged.
2452 */
2453 public abstract int getDischargeAmountScreenOff();
2454
2455 /**
2456 * Get the amount the battery has discharged while the screen was off,
2457 * since the last time the device was charged.
2458 */
2459 public abstract int getDischargeAmountScreenOffSinceCharge();
2460
2461 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 * Returns the total, last, or current battery uptime in microseconds.
2463 *
2464 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002465 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 */
2467 public abstract long computeBatteryUptime(long curTime, int which);
2468
2469 /**
2470 * Returns the total, last, or current battery realtime in microseconds.
2471 *
2472 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002473 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002474 */
2475 public abstract long computeBatteryRealtime(long curTime, int which);
2476
2477 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002478 * Returns the total, last, or current battery screen off uptime in microseconds.
2479 *
2480 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002481 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002482 */
2483 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2484
2485 /**
2486 * Returns the total, last, or current battery screen off realtime in microseconds.
2487 *
2488 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002489 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002490 */
2491 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2492
2493 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 * Returns the total, last, or current uptime in microseconds.
2495 *
2496 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002497 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002498 */
2499 public abstract long computeUptime(long curTime, int which);
2500
2501 /**
2502 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002503 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002505 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 */
2507 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002508
2509 /**
2510 * Compute an approximation for how much run time (in microseconds) is remaining on
2511 * the battery. Returns -1 if no time can be computed: either there is not
2512 * enough current data to make a decision, or the battery is currently
2513 * charging.
2514 *
2515 * @param curTime The current elepsed realtime in microseconds.
2516 */
2517 public abstract long computeBatteryTimeRemaining(long curTime);
2518
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002519 // The part of a step duration that is the actual time.
2520 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2521
2522 // Bits in a step duration that are the new battery level we are at.
2523 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002524 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002525
2526 // Bits in a step duration that are the initial mode we were in at that step.
2527 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002528 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002529
2530 // Bits in a step duration that indicate which modes changed during that step.
2531 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002532 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002533
2534 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2535 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2536
Santos Cordone94f0502017-02-24 12:31:20 -08002537 // The largest value for screen state that is tracked in battery states. Any values above
2538 // this should be mapped back to one of the tracked values before being tracked here.
2539 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2540
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002541 // Step duration mode: power save is on.
2542 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2543
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002544 // Step duration mode: device is currently in idle mode.
2545 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2546
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002547 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2548 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002549 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2550 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002551 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2552 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2553 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2554 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2555 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002556 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2557 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002558 };
2559 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2560 (Display.STATE_OFF-1),
2561 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002562 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002563 (Display.STATE_ON-1),
2564 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2565 (Display.STATE_DOZE-1),
2566 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2567 (Display.STATE_DOZE_SUSPEND-1),
2568 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002569 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002570 };
2571 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2572 "screen off",
2573 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002574 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002575 "screen on",
2576 "screen on power save",
2577 "screen doze",
2578 "screen doze power save",
2579 "screen doze-suspend",
2580 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002581 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002582 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002583
2584 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002585 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2586 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2587 * a coulomb counter.
2588 */
2589 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2590
2591 /**
2592 * Return the counter keeping track of the amount of battery discharge measured in
2593 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2594 * a coulomb counter.
2595 */
2596 public abstract LongCounter getDischargeCoulombCounter();
2597
2598 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002599 * Returns the estimated real battery capacity, which may be less than the capacity
2600 * declared by the PowerProfile.
2601 * @return The estimated battery capacity in mAh.
2602 */
2603 public abstract int getEstimatedBatteryCapacity();
2604
2605 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002606 * @return The minimum learned battery capacity in uAh.
2607 */
2608 public abstract int getMinLearnedBatteryCapacity();
2609
2610 /**
2611 * @return The maximum learned battery capacity in uAh.
2612 */
2613 public abstract int getMaxLearnedBatteryCapacity() ;
2614
2615 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002616 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002617 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002618 public abstract LevelStepTracker getDischargeLevelStepTracker();
2619
2620 /**
2621 * Return the array of daily discharge step durations.
2622 */
2623 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002624
2625 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002626 * Compute an approximation for how much time (in microseconds) remains until the battery
2627 * is fully charged. Returns -1 if no time can be computed: either there is not
2628 * enough current data to make a decision, or the battery is currently
2629 * discharging.
2630 *
2631 * @param curTime The current elepsed realtime in microseconds.
2632 */
2633 public abstract long computeChargeTimeRemaining(long curTime);
2634
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002635 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002636 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002637 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002638 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002639
2640 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002641 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002642 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002643 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002644
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002645 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2646
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002647 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002648
Evan Millarc64edde2009-04-18 12:26:32 -07002649 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002650
James Carr2dd7e5e2016-07-20 18:48:39 -07002651 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2652
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002653 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2654
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002655 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002656 long days = seconds / (60 * 60 * 24);
2657 if (days != 0) {
2658 out.append(days);
2659 out.append("d ");
2660 }
2661 long used = days * 60 * 60 * 24;
2662
2663 long hours = (seconds - used) / (60 * 60);
2664 if (hours != 0 || used != 0) {
2665 out.append(hours);
2666 out.append("h ");
2667 }
2668 used += hours * 60 * 60;
2669
2670 long mins = (seconds-used) / 60;
2671 if (mins != 0 || used != 0) {
2672 out.append(mins);
2673 out.append("m ");
2674 }
2675 used += mins * 60;
2676
2677 if (seconds != 0 || used != 0) {
2678 out.append(seconds-used);
2679 out.append("s ");
2680 }
2681 }
2682
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002683 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002684 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002685 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686 sb.append(time - (sec * 1000));
2687 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 }
2689
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002690 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002691 long sec = time / 1000;
2692 formatTimeRaw(sb, sec);
2693 sb.append(time - (sec * 1000));
2694 sb.append("ms");
2695 }
2696
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002697 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002699 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 }
2701 float perc = ((float)num) / ((float)den) * 100;
2702 mFormatBuilder.setLength(0);
2703 mFormatter.format("%.1f%%", perc);
2704 return mFormatBuilder.toString();
2705 }
2706
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002707 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002708 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002709
Evan Millar22ac0432009-03-31 11:33:18 -07002710 if (bytes < BYTES_PER_KB) {
2711 return bytes + "B";
2712 } else if (bytes < BYTES_PER_MB) {
2713 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2714 return mFormatBuilder.toString();
2715 } else if (bytes < BYTES_PER_GB){
2716 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2717 return mFormatBuilder.toString();
2718 } else {
2719 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2720 return mFormatBuilder.toString();
2721 }
2722 }
2723
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002724 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002725 if (timer != null) {
2726 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002727 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002728 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2729 return totalTimeMillis;
2730 }
2731 return 0;
2732 }
2733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002734 /**
2735 *
2736 * @param sb a StringBuilder object.
2737 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002738 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002739 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002740 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002741 * @param linePrefix a String to be prepended to each line of output.
2742 * @return the line prefix
2743 */
2744 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002745 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002748 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002749
Evan Millarc64edde2009-04-18 12:26:32 -07002750 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 if (totalTimeMillis != 0) {
2752 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002753 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002754 if (name != null) {
2755 sb.append(name);
2756 sb.append(' ');
2757 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002758 sb.append('(');
2759 sb.append(count);
2760 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002761 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2762 if (maxDurationMs >= 0) {
2763 sb.append(" max=");
2764 sb.append(maxDurationMs);
2765 }
Bookatz506a8182017-05-01 14:18:42 -07002766 // Put actual time if it is available and different from totalTimeMillis.
2767 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2768 if (totalDurMs > totalTimeMillis) {
2769 sb.append(" actual=");
2770 sb.append(totalDurMs);
2771 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002772 if (timer.isRunningLocked()) {
2773 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2774 if (currentMs >= 0) {
2775 sb.append(" (running for ");
2776 sb.append(currentMs);
2777 sb.append("ms)");
2778 } else {
2779 sb.append(" (running)");
2780 }
2781 }
2782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 return ", ";
2784 }
2785 }
2786 return linePrefix;
2787 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002788
2789 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002790 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002791 *
2792 * @param pw a PrintWriter object to print to.
2793 * @param sb a StringBuilder object.
2794 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002795 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002796 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2797 * @param prefix a String to be prepended to each line of output.
2798 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002799 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002800 */
2801 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002802 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002803 if (timer != null) {
2804 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002805 final long totalTimeMs = (timer.getTotalTimeLocked(
2806 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002807 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002808 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002809 sb.setLength(0);
2810 sb.append(prefix);
2811 sb.append(" ");
2812 sb.append(type);
2813 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002814 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002815 sb.append("realtime (");
2816 sb.append(count);
2817 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002818 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2819 if (maxDurationMs >= 0) {
2820 sb.append(" max=");
2821 sb.append(maxDurationMs);
2822 }
2823 if (timer.isRunningLocked()) {
2824 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2825 if (currentMs >= 0) {
2826 sb.append(" (running for ");
2827 sb.append(currentMs);
2828 sb.append("ms)");
2829 } else {
2830 sb.append(" (running)");
2831 }
2832 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002833 pw.println(sb.toString());
2834 return true;
2835 }
2836 }
2837 return false;
2838 }
Bookatzc8c44962017-05-11 12:12:54 -07002839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 /**
2841 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002842 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 * @param sb a StringBuilder object.
2844 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002845 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002847 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002848 * @param linePrefix a String to be prepended to each line of output.
2849 * @return the line prefix
2850 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002851 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2852 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 long totalTimeMicros = 0;
2854 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07002855 long max = 0;
2856 long current = 0;
2857 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002859 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07002860 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002861 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2862 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07002863 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 }
2865 sb.append(linePrefix);
2866 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2867 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002868 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002870 sb.append(',');
2871 sb.append(current);
2872 sb.append(',');
2873 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07002874 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
2875 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
2876 // totalDuration independent of totalTimeMicros (since they are not pooled).
2877 if (name != null) {
2878 sb.append(',');
2879 sb.append(totalDuration);
2880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 return ",";
2882 }
Bookatz506a8182017-05-01 14:18:42 -07002883
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002884 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2885 String type) {
2886 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2887 pw.print(',');
2888 pw.print(uid);
2889 pw.print(',');
2890 pw.print(category);
2891 pw.print(',');
2892 pw.print(type);
2893 }
2894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002895 /**
2896 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07002897 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898 * @param pw the PageWriter to dump log to
2899 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2900 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2901 * @param args type-dependent data arguments
2902 */
Bookatzc8c44962017-05-11 12:12:54 -07002903 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002905 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002906 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002907 pw.print(',');
2908 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002910 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002912
2913 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002914 * Dump a given timer stat for terse checkin mode.
2915 *
2916 * @param pw the PageWriter to dump log to
2917 * @param uid the UID to log
2918 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2919 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2920 * @param timer a {@link Timer} to dump stats for
2921 * @param rawRealtime the current elapsed realtime of the system in microseconds
2922 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2923 */
2924 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2925 Timer timer, long rawRealtime, int which) {
2926 if (timer != null) {
2927 // Convert from microseconds to milliseconds with rounding
2928 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2929 / 1000;
2930 final int count = timer.getCountLocked(which);
2931 if (totalTime != 0) {
2932 dumpLine(pw, uid, category, type, totalTime, count);
2933 }
2934 }
2935 }
2936
2937 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002938 * Checks if the ControllerActivityCounter has any data worth dumping.
2939 */
2940 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2941 if (counter == null) {
2942 return false;
2943 }
2944
2945 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2946 || counter.getRxTimeCounter().getCountLocked(which) != 0
2947 || counter.getPowerCounter().getCountLocked(which) != 0) {
2948 return true;
2949 }
2950
2951 for (LongCounter c : counter.getTxTimeCounters()) {
2952 if (c.getCountLocked(which) != 0) {
2953 return true;
2954 }
2955 }
2956 return false;
2957 }
2958
2959 /**
2960 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2961 * The order of the arguments in the final check in line is:
2962 *
2963 * idle, rx, power, tx...
2964 *
2965 * where tx... is one or more transmit level times.
2966 */
2967 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2968 String type,
2969 ControllerActivityCounter counter,
2970 int which) {
2971 if (!controllerActivityHasData(counter, which)) {
2972 return;
2973 }
2974
2975 dumpLineHeader(pw, uid, category, type);
2976 pw.print(",");
2977 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2978 pw.print(",");
2979 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2980 pw.print(",");
2981 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2982 for (LongCounter c : counter.getTxTimeCounters()) {
2983 pw.print(",");
2984 pw.print(c.getCountLocked(which));
2985 }
2986 pw.println();
2987 }
2988
2989 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2990 String prefix, String controllerName,
2991 ControllerActivityCounter counter,
2992 int which) {
2993 if (controllerActivityHasData(counter, which)) {
2994 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2995 }
2996 }
2997
2998 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2999 String controllerName,
3000 ControllerActivityCounter counter, int which) {
3001 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
3002 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
3003 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
3004 long totalTxTimeMs = 0;
3005 for (LongCounter txState : counter.getTxTimeCounters()) {
3006 totalTxTimeMs += txState.getCountLocked(which);
3007 }
3008
3009 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
3010
3011 sb.setLength(0);
3012 sb.append(prefix);
3013 sb.append(" ");
3014 sb.append(controllerName);
3015 sb.append(" Idle time: ");
3016 formatTimeMs(sb, idleTimeMs);
3017 sb.append("(");
3018 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
3019 sb.append(")");
3020 pw.println(sb.toString());
3021
3022 sb.setLength(0);
3023 sb.append(prefix);
3024 sb.append(" ");
3025 sb.append(controllerName);
3026 sb.append(" Rx time: ");
3027 formatTimeMs(sb, rxTimeMs);
3028 sb.append("(");
3029 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
3030 sb.append(")");
3031 pw.println(sb.toString());
3032
3033 sb.setLength(0);
3034 sb.append(prefix);
3035 sb.append(" ");
3036 sb.append(controllerName);
3037 sb.append(" Tx time: ");
3038 formatTimeMs(sb, totalTxTimeMs);
3039 sb.append("(");
3040 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
3041 sb.append(")");
3042 pw.println(sb.toString());
3043
3044 final int numTxLvls = counter.getTxTimeCounters().length;
3045 if (numTxLvls > 1) {
3046 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3047 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3048 sb.setLength(0);
3049 sb.append(prefix);
3050 sb.append(" [");
3051 sb.append(lvl);
3052 sb.append("] ");
3053 formatTimeMs(sb, txLvlTimeMs);
3054 sb.append("(");
3055 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
3056 sb.append(")");
3057 pw.println(sb.toString());
3058 }
3059 }
3060
3061 sb.setLength(0);
3062 sb.append(prefix);
3063 sb.append(" ");
3064 sb.append(controllerName);
3065 sb.append(" Power drain: ").append(
3066 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
3067 sb.append("mAh");
3068 pw.println(sb.toString());
3069 }
3070
3071 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003072 * Temporary for settings.
3073 */
3074 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3075 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3076 }
3077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 /**
3079 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003080 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003081 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003083 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3084 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003085 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3086 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07003087 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003088 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3090 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003091 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3092 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3093 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003094 final long totalRealtime = computeRealtime(rawRealtime, which);
3095 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003096 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003097 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003098 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003099 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3100 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003101 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003102 rawRealtime, which);
3103 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3104 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003105 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003106 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003107 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003108 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003109 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
3110 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
3111 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003112
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003113 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003114
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003115 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003116 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003117
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003118 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003121 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003122 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003123 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003124 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003125 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003126 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003127 getEstimatedBatteryCapacity(),
3128 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity());
Adam Lesinski67c134f2016-06-10 15:15:08 -07003129
Bookatzc8c44962017-05-11 12:12:54 -07003130
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003131 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003132 long fullWakeLockTimeTotal = 0;
3133 long partialWakeLockTimeTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003134
Evan Millar22ac0432009-03-31 11:33:18 -07003135 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003136 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003137
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003138 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3139 = u.getWakelockStats();
3140 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3141 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003142
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003143 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3144 if (fullWakeTimer != null) {
3145 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3146 which);
3147 }
3148
3149 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3150 if (partialWakeTimer != null) {
3151 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3152 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003153 }
3154 }
3155 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003156
3157 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003158 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3159 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3160 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3161 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3162 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3163 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3164 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3165 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003166 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3167 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003168 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3169 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003170 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3171 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003172
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003173 // Dump Modem controller stats
3174 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3175 getModemControllerActivity(), which);
3176
Adam Lesinskie283d332015-04-16 12:29:25 -07003177 // Dump Wifi controller stats
3178 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3179 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003180 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003181 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003182
3183 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3184 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003185
3186 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003187 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3188 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190 // Dump misc stats
3191 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003192 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003193 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003194 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003195 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003196 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003197 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3198 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003199 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003200 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3201 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3202 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3203 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003204 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003205
Dianne Hackborn617f8772009-03-31 15:04:46 -07003206 // Dump screen brightness stats
3207 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3208 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003209 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003210 }
3211 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003212
Dianne Hackborn627bba72009-03-24 22:32:56 -07003213 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003214 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3215 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003216 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003217 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003218 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003219 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003220 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003221 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003222 args[i] = getPhoneSignalStrengthCount(i, which);
3223 }
3224 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003225
Dianne Hackborn627bba72009-03-24 22:32:56 -07003226 // Dump network type stats
3227 args = new Object[NUM_DATA_CONNECTION_TYPES];
3228 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003229 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003230 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003231 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3232 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3233 args[i] = getPhoneDataConnectionCount(i, which);
3234 }
3235 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003236
3237 // Dump wifi state stats
3238 args = new Object[NUM_WIFI_STATES];
3239 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003240 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003241 }
3242 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3243 for (int i=0; i<NUM_WIFI_STATES; i++) {
3244 args[i] = getWifiStateCount(i, which);
3245 }
3246 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3247
Dianne Hackborn3251b902014-06-20 14:40:53 -07003248 // Dump wifi suppl state stats
3249 args = new Object[NUM_WIFI_SUPPL_STATES];
3250 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3251 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3252 }
3253 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3254 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3255 args[i] = getWifiSupplStateCount(i, which);
3256 }
3257 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3258
3259 // Dump wifi signal strength stats
3260 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3261 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3262 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3263 }
3264 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3265 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3266 args[i] = getWifiSignalStrengthCount(i, which);
3267 }
3268 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3269
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003270 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003271 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003272 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003273 }
Bookatzc8c44962017-05-11 12:12:54 -07003274
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003275 if (which == STATS_SINCE_UNPLUGGED) {
3276 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3277 getDischargeStartLevel()-getDischargeCurrentLevel(),
3278 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003279 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
3280 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003281 } else {
3282 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3283 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003284 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003285 getDischargeAmountScreenOffSinceCharge(),
3286 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003287 }
Bookatzc8c44962017-05-11 12:12:54 -07003288
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003289 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003290 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003291 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003292 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003293 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003294 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003295 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3296 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003297 }
Evan Millarc64edde2009-04-18 12:26:32 -07003298 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003299 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003300 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003301 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3302 // Not doing the regular wake lock formatting to remain compatible
3303 // with the old checkin format.
3304 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3305 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003306 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003307 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003308 }
3309 }
Evan Millarc64edde2009-04-18 12:26:32 -07003310 }
Bookatzc8c44962017-05-11 12:12:54 -07003311
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003312 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003313 helper.create(this);
3314 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003315 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003316 if (sippers != null && sippers.size() > 0) {
3317 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3318 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003319 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003320 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3321 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3322 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003323 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003324 int uid = 0;
3325 String label;
3326 switch (bs.drainType) {
3327 case IDLE:
3328 label="idle";
3329 break;
3330 case CELL:
3331 label="cell";
3332 break;
3333 case PHONE:
3334 label="phone";
3335 break;
3336 case WIFI:
3337 label="wifi";
3338 break;
3339 case BLUETOOTH:
3340 label="blue";
3341 break;
3342 case SCREEN:
3343 label="scrn";
3344 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003345 case FLASHLIGHT:
3346 label="flashlight";
3347 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003348 case APP:
3349 uid = bs.uidObj.getUid();
3350 label = "uid";
3351 break;
3352 case USER:
3353 uid = UserHandle.getUid(bs.userId, 0);
3354 label = "user";
3355 break;
3356 case UNACCOUNTED:
3357 label = "unacc";
3358 break;
3359 case OVERCOUNTED:
3360 label = "over";
3361 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003362 case CAMERA:
3363 label = "camera";
3364 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003365 default:
3366 label = "???";
3367 }
3368 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Bookatz17d7d9d2017-06-08 14:50:46 -07003369 BatteryStatsHelper.makemAh(bs.totalPowerMah),
3370 bs.shouldHide ? 1 : 0,
3371 BatteryStatsHelper.makemAh(bs.screenPowerMah),
3372 BatteryStatsHelper.makemAh(bs.proportionalSmearMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003373 }
3374 }
3375
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003376 final long[] cpuFreqs = getCpuFreqs();
3377 if (cpuFreqs != null) {
3378 sb.setLength(0);
3379 for (int i = 0; i < cpuFreqs.length; ++i) {
3380 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3381 }
3382 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3383 }
3384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003385 for (int iu = 0; iu < NU; iu++) {
3386 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003387 if (reqUid >= 0 && uid != reqUid) {
3388 continue;
3389 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003390 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003393 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3394 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3395 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3396 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3397 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3398 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3399 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3400 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003401 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003402 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3403 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003404 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003405 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3406 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003407 // Background data transfers
3408 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3409 which);
3410 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3411 which);
3412 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3413 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3414 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3415 which);
3416 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3417 which);
3418 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3419 which);
3420 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3421 which);
3422
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003423 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3424 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003425 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003426 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3427 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3428 || wifiBytesBgTx > 0
3429 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3430 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003431 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3432 wifiBytesRx, wifiBytesTx,
3433 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003434 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003435 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003436 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3437 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3438 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3439 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003440 }
3441
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003442 // Dump modem controller data, per UID.
3443 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3444 u.getModemControllerActivity(), which);
3445
3446 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003447 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3448 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3449 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003450 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3451 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003452 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3453 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3454 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003455 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003456 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003457 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3458 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003459 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3460 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003461 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003462 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003463 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003464
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003465 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3466 u.getWifiControllerActivity(), which);
3467
Bookatz867c0d72017-03-07 18:23:42 -08003468 final Timer bleTimer = u.getBluetoothScanTimer();
3469 if (bleTimer != null) {
3470 // Convert from microseconds to milliseconds with rounding
3471 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3472 / 1000;
3473 if (totalTime != 0) {
3474 final int count = bleTimer.getCountLocked(which);
3475 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3476 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003477 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3478 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3479 final long actualTimeBg = bleTimerBg != null ?
3480 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003481 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07003482 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3483 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003484 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
3485 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
3486 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
3487 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
3488 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
3489 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3490 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
3491 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3492 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
3493 final Timer unoptimizedScanTimerBg =
3494 u.getBluetoothUnoptimizedScanBackgroundTimer();
3495 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
3496 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3497 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
3498 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3499
Bookatz867c0d72017-03-07 18:23:42 -08003500 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatzb1f04f32017-05-19 13:57:32 -07003501 countBg, actualTime, actualTimeBg, resultCount, resultCountBg,
3502 unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg,
3503 unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg);
Bookatz867c0d72017-03-07 18:23:42 -08003504 }
3505 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003506
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003507 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3508 u.getBluetoothControllerActivity(), which);
3509
Dianne Hackborn617f8772009-03-31 15:04:46 -07003510 if (u.hasUserActivity()) {
3511 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3512 boolean hasData = false;
3513 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3514 int val = u.getUserActivityCount(i, which);
3515 args[i] = val;
3516 if (val != 0) hasData = true;
3517 }
3518 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003519 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003520 }
3521 }
Bookatzc8c44962017-05-11 12:12:54 -07003522
3523 if (u.getAggregatedPartialWakelockTimer() != null) {
3524 final Timer timer = u.getAggregatedPartialWakelockTimer();
Bookatz6d799932017-06-07 12:30:07 -07003525 // Times are since reset (regardless of 'which')
3526 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07003527 final Timer bgTimer = timer.getSubTimer();
3528 final long bgTimeMs = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003529 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07003530 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3531 }
3532
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003533 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3534 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3535 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3536 String linePrefix = "";
3537 sb.setLength(0);
3538 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3539 rawRealtime, "f", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003540 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3541 linePrefix = printWakeLockCheckin(sb, pTimer,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003542 rawRealtime, "p", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003543 linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null,
3544 rawRealtime, "bp", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003545 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3546 rawRealtime, "w", which, linePrefix);
3547
3548 // Only log if we had at lease one wakelock...
3549 if (sb.length() > 0) {
3550 String name = wakelocks.keyAt(iw);
3551 if (name.indexOf(',') >= 0) {
3552 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 }
Yi Jin02483362017-08-04 11:30:44 -07003554 if (name.indexOf('\n') >= 0) {
3555 name = name.replace('\n', '_');
3556 }
3557 if (name.indexOf('\r') >= 0) {
3558 name = name.replace('\r', '_');
3559 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003560 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 }
3562 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003563
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003564 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3565 for (int isy=syncs.size()-1; isy>=0; isy--) {
3566 final Timer timer = syncs.valueAt(isy);
3567 // Convert from microseconds to milliseconds with rounding
3568 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3569 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003570 final Timer bgTimer = timer.getSubTimer();
3571 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003572 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07003573 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003574 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003575 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003576 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003577 }
3578 }
3579
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003580 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3581 for (int ij=jobs.size()-1; ij>=0; ij--) {
3582 final Timer timer = jobs.valueAt(ij);
3583 // Convert from microseconds to milliseconds with rounding
3584 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3585 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003586 final Timer bgTimer = timer.getSubTimer();
3587 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003588 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07003589 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003590 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003591 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003592 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003593 }
3594 }
3595
Dianne Hackborn94326cb2017-06-28 16:17:20 -07003596 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
3597 for (int ic=completions.size()-1; ic>=0; ic--) {
3598 SparseIntArray types = completions.valueAt(ic);
3599 if (types != null) {
3600 dumpLine(pw, uid, category, JOB_COMPLETION_DATA,
3601 "\"" + completions.keyAt(ic) + "\"",
3602 types.get(JobParameters.REASON_CANCELED, 0),
3603 types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0),
3604 types.get(JobParameters.REASON_PREEMPT, 0),
3605 types.get(JobParameters.REASON_TIMEOUT, 0),
3606 types.get(JobParameters.REASON_DEVICE_IDLE, 0));
3607 }
3608 }
3609
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003610 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3611 rawRealtime, which);
3612 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3613 rawRealtime, which);
3614 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3615 rawRealtime, which);
3616 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3617 rawRealtime, which);
3618
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003619 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3620 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003621 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003622 final Uid.Sensor se = sensors.valueAt(ise);
3623 final int sensorNumber = sensors.keyAt(ise);
3624 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003625 if (timer != null) {
3626 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003627 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3628 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003629 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003630 final int count = timer.getCountLocked(which);
3631 final Timer bgTimer = se.getSensorBackgroundTime();
3632 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003633 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3634 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3635 final long bgActualTime = bgTimer != null ?
3636 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3637 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3638 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 }
3641 }
3642
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003643 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3644 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003645
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07003646 dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(),
3647 rawRealtime, which);
3648
3649 dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003650 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003651
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003652 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003653 long totalStateTime = 0;
3654 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003655 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3656 totalStateTime += time;
3657 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003658 }
3659 if (totalStateTime > 0) {
3660 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3661 }
3662
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003663 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3664 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003665 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003666 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003667 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003668 }
3669
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003670 // If the cpuFreqs is null, then don't bother checking for cpu freq times.
3671 if (cpuFreqs != null) {
3672 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3673 // If total cpuFreqTimes is null, then we don't need to check for
3674 // screenOffCpuFreqTimes.
3675 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
3676 sb.setLength(0);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003677 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003678 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003679 }
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003680 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3681 if (screenOffCpuFreqTimeMs != null) {
3682 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3683 sb.append("," + screenOffCpuFreqTimeMs[i]);
3684 }
3685 } else {
3686 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3687 sb.append(",0");
3688 }
3689 }
3690 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
3691 cpuFreqTimeMs.length, sb.toString());
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003692 }
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003693 }
3694
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003695 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3696 = u.getProcessStats();
3697 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3698 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003699
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003700 final long userMillis = ps.getUserTime(which);
3701 final long systemMillis = ps.getSystemTime(which);
3702 final long foregroundMillis = ps.getForegroundTime(which);
3703 final int starts = ps.getStarts(which);
3704 final int numCrashes = ps.getNumCrashes(which);
3705 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003706
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003707 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3708 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003709 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
3710 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 }
3712 }
3713
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003714 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3715 = u.getPackageStats();
3716 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3717 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3718 int wakeups = 0;
3719 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3720 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003721 int count = alarms.valueAt(iwa).getCountLocked(which);
3722 wakeups += count;
3723 String name = alarms.keyAt(iwa).replace(',', '_');
3724 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003725 }
3726 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3727 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3728 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3729 final long startTime = ss.getStartTime(batteryUptime, which);
3730 final int starts = ss.getStarts(which);
3731 final int launches = ss.getLaunches(which);
3732 if (startTime != 0 || starts != 0 || launches != 0) {
3733 dumpLine(pw, uid, category, APK_DATA,
3734 wakeups, // wakeup alarms
3735 packageStats.keyAt(ipkg), // Apk
3736 serviceStats.keyAt(isvc), // service
3737 startTime / 1000, // time spent started, in ms
3738 starts,
3739 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 }
3741 }
3742 }
3743 }
3744 }
3745
Dianne Hackborn81038902012-11-26 17:04:09 -08003746 static final class TimerEntry {
3747 final String mName;
3748 final int mId;
3749 final BatteryStats.Timer mTimer;
3750 final long mTime;
3751 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3752 mName = name;
3753 mId = id;
3754 mTimer = timer;
3755 mTime = time;
3756 }
3757 }
3758
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003759 private void printmAh(PrintWriter printer, double power) {
3760 printer.print(BatteryStatsHelper.makemAh(power));
3761 }
3762
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003763 private void printmAh(StringBuilder sb, double power) {
3764 sb.append(BatteryStatsHelper.makemAh(power));
3765 }
3766
Dianne Hackbornd953c532014-08-16 18:17:38 -07003767 /**
3768 * Temporary for settings.
3769 */
3770 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3771 int reqUid) {
3772 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3773 }
3774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003776 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003777 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003778 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3779 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07003780 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782
3783 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3784 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3785 final long totalRealtime = computeRealtime(rawRealtime, which);
3786 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003787 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3788 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3789 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003790 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3791 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003792
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003793 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003794
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003795 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003796 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003797
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003798 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3799 if (estimatedBatteryCapacity > 0) {
3800 sb.setLength(0);
3801 sb.append(prefix);
3802 sb.append(" Estimated battery capacity: ");
3803 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3804 sb.append(" mAh");
3805 pw.println(sb.toString());
3806 }
3807
Jocelyn Dangc627d102017-04-14 13:15:14 -07003808 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
3809 if (minLearnedBatteryCapacity > 0) {
3810 sb.setLength(0);
3811 sb.append(prefix);
3812 sb.append(" Min learned battery capacity: ");
3813 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
3814 sb.append(" mAh");
3815 pw.println(sb.toString());
3816 }
3817 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
3818 if (maxLearnedBatteryCapacity > 0) {
3819 sb.setLength(0);
3820 sb.append(prefix);
3821 sb.append(" Max learned battery capacity: ");
3822 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
3823 sb.append(" mAh");
3824 pw.println(sb.toString());
3825 }
3826
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003827 sb.setLength(0);
3828 sb.append(prefix);
3829 sb.append(" Time on battery: ");
3830 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3831 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3832 sb.append(") realtime, ");
3833 formatTimeMs(sb, whichBatteryUptime / 1000);
3834 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3835 sb.append(") uptime");
3836 pw.println(sb.toString());
3837 sb.setLength(0);
3838 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003839 sb.append(" Time on battery screen off: ");
3840 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3841 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3842 sb.append(") realtime, ");
3843 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3844 sb.append("(");
3845 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3846 sb.append(") uptime");
3847 pw.println(sb.toString());
3848 sb.setLength(0);
3849 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003850 sb.append(" Total run time: ");
3851 formatTimeMs(sb, totalRealtime / 1000);
3852 sb.append("realtime, ");
3853 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003854 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003855 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003856 if (batteryTimeRemaining >= 0) {
3857 sb.setLength(0);
3858 sb.append(prefix);
3859 sb.append(" Battery time remaining: ");
3860 formatTimeMs(sb, batteryTimeRemaining / 1000);
3861 pw.println(sb.toString());
3862 }
3863 if (chargeTimeRemaining >= 0) {
3864 sb.setLength(0);
3865 sb.append(prefix);
3866 sb.append(" Charge time remaining: ");
3867 formatTimeMs(sb, chargeTimeRemaining / 1000);
3868 pw.println(sb.toString());
3869 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003870
3871 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3872 final long dischargeCount = dischargeCounter.getCountLocked(which);
3873 if (dischargeCount >= 0) {
3874 sb.setLength(0);
3875 sb.append(prefix);
3876 sb.append(" Discharge: ");
3877 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3878 sb.append(" mAh");
3879 pw.println(sb.toString());
3880 }
3881
3882 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3883 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3884 if (dischargeScreenOffCount >= 0) {
3885 sb.setLength(0);
3886 sb.append(prefix);
3887 sb.append(" Screen off discharge: ");
3888 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3889 sb.append(" mAh");
3890 pw.println(sb.toString());
3891 }
3892
3893 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3894 if (dischargeScreenOnCount >= 0) {
3895 sb.setLength(0);
3896 sb.append(prefix);
3897 sb.append(" Screen on discharge: ");
3898 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3899 sb.append(" mAh");
3900 pw.println(sb.toString());
3901 }
3902
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003903 pw.print(" Start clock time: ");
3904 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3905
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003906 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003907 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003908 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003909 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3910 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003911 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003912 rawRealtime, which);
3913 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3914 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003915 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003916 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003917 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3918 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3919 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003920 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003921 sb.append(prefix);
3922 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3923 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003924 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003925 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3926 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003927 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003928 pw.println(sb.toString());
3929 sb.setLength(0);
3930 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003931 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003932 boolean didOne = false;
3933 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003934 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003935 if (time == 0) {
3936 continue;
3937 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003938 sb.append("\n ");
3939 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003940 didOne = true;
3941 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3942 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003943 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003944 sb.append("(");
3945 sb.append(formatRatioLocked(time, screenOnTime));
3946 sb.append(")");
3947 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003948 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003949 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003950 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003951 sb.setLength(0);
3952 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003953 sb.append(" Power save mode enabled: ");
3954 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003955 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003956 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003957 sb.append(")");
3958 pw.println(sb.toString());
3959 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003960 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003961 sb.setLength(0);
3962 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003963 sb.append(" Device light idling: ");
3964 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003965 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003966 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3967 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003968 sb.append("x");
3969 pw.println(sb.toString());
3970 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003971 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003972 sb.setLength(0);
3973 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003974 sb.append(" Idle mode light time: ");
3975 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003976 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003977 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3978 sb.append(") ");
3979 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003980 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003981 sb.append(" -- longest ");
3982 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3983 pw.println(sb.toString());
3984 }
3985 if (deviceIdlingTime != 0) {
3986 sb.setLength(0);
3987 sb.append(prefix);
3988 sb.append(" Device full idling: ");
3989 formatTimeMs(sb, deviceIdlingTime / 1000);
3990 sb.append("(");
3991 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003992 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003993 sb.append("x");
3994 pw.println(sb.toString());
3995 }
3996 if (deviceIdleModeFullTime != 0) {
3997 sb.setLength(0);
3998 sb.append(prefix);
3999 sb.append(" Idle mode full time: ");
4000 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
4001 sb.append("(");
4002 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
4003 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004004 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004005 sb.append("x");
4006 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004007 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004008 pw.println(sb.toString());
4009 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004010 if (phoneOnTime != 0) {
4011 sb.setLength(0);
4012 sb.append(prefix);
4013 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
4014 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004015 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004016 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004017 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08004018 if (connChanges != 0) {
4019 pw.print(prefix);
4020 pw.print(" Connectivity changes: "); pw.println(connChanges);
4021 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004022
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004023 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07004024 long fullWakeLockTimeTotalMicros = 0;
4025 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08004026
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004027 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08004028
Evan Millar22ac0432009-03-31 11:33:18 -07004029 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004030 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004031
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004032 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4033 = u.getWakelockStats();
4034 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4035 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07004036
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004037 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
4038 if (fullWakeTimer != null) {
4039 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
4040 rawRealtime, which);
4041 }
4042
4043 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4044 if (partialWakeTimer != null) {
4045 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
4046 rawRealtime, which);
4047 if (totalTimeMicros > 0) {
4048 if (reqUid < 0) {
4049 // Only show the ordered list of all wake
4050 // locks if the caller is not asking for data
4051 // about a specific uid.
4052 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
4053 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08004054 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004055 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07004056 }
4057 }
4058 }
4059 }
Bookatzc8c44962017-05-11 12:12:54 -07004060
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004061 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4062 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4063 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4064 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
4065 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4066 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
4067 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4068 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004069 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4070 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004071
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004072 if (fullWakeLockTimeTotalMicros != 0) {
4073 sb.setLength(0);
4074 sb.append(prefix);
4075 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
4076 (fullWakeLockTimeTotalMicros + 500) / 1000);
4077 pw.println(sb.toString());
4078 }
4079
4080 if (partialWakeLockTimeTotalMicros != 0) {
4081 sb.setLength(0);
4082 sb.append(prefix);
4083 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
4084 (partialWakeLockTimeTotalMicros + 500) / 1000);
4085 pw.println(sb.toString());
4086 }
4087
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004088 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004089 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
4090 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
4091 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
4092 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004093 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004094 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004095 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004096 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08004097 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004098 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004099 if (time == 0) {
4100 continue;
4101 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004102 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004103 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004104 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08004105 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004106 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004107 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004108 sb.append("(");
4109 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004110 sb.append(") ");
4111 sb.append(getPhoneSignalStrengthCount(i, which));
4112 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004113 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004114 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004115 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004116
4117 sb.setLength(0);
4118 sb.append(prefix);
4119 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004120 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07004121 pw.println(sb.toString());
4122
Dianne Hackborn627bba72009-03-24 22:32:56 -07004123 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004124 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004125 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004126 didOne = false;
4127 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004128 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004129 if (time == 0) {
4130 continue;
4131 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004132 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004133 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004134 didOne = true;
4135 sb.append(DATA_CONNECTION_NAMES[i]);
4136 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004137 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004138 sb.append("(");
4139 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004140 sb.append(") ");
4141 sb.append(getPhoneDataConnectionCount(i, which));
4142 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004143 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004144 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004145 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004146
4147 sb.setLength(0);
4148 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08004149 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004150 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004151 formatTimeMs(sb, mobileActiveTime / 1000);
4152 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4153 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
4154 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004155 pw.println(sb.toString());
4156
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004157 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
4158 if (mobileActiveUnknownTime != 0) {
4159 sb.setLength(0);
4160 sb.append(prefix);
4161 sb.append(" Mobile radio active unknown time: ");
4162 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
4163 sb.append("(");
4164 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
4165 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
4166 sb.append("x");
4167 pw.println(sb.toString());
4168 }
4169
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004170 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
4171 if (mobileActiveAdjustedTime != 0) {
4172 sb.setLength(0);
4173 sb.append(prefix);
4174 sb.append(" Mobile radio active adjusted time: ");
4175 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
4176 sb.append("(");
4177 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
4178 sb.append(")");
4179 pw.println(sb.toString());
4180 }
4181
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004182 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
4183
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004184 pw.print(prefix);
4185 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
4186 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
4187 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
4188 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004189 sb.setLength(0);
4190 sb.append(prefix);
4191 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
4192 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
4193 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
4194 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004195 sb.append(")");
4196 pw.println(sb.toString());
4197
4198 sb.setLength(0);
4199 sb.append(prefix);
4200 sb.append(" Wifi states:");
4201 didOne = false;
4202 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004203 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004204 if (time == 0) {
4205 continue;
4206 }
4207 sb.append("\n ");
4208 didOne = true;
4209 sb.append(WIFI_STATE_NAMES[i]);
4210 sb.append(" ");
4211 formatTimeMs(sb, time/1000);
4212 sb.append("(");
4213 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4214 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004215 sb.append(getWifiStateCount(i, which));
4216 sb.append("x");
4217 }
4218 if (!didOne) sb.append(" (no activity)");
4219 pw.println(sb.toString());
4220
4221 sb.setLength(0);
4222 sb.append(prefix);
4223 sb.append(" Wifi supplicant states:");
4224 didOne = false;
4225 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4226 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4227 if (time == 0) {
4228 continue;
4229 }
4230 sb.append("\n ");
4231 didOne = true;
4232 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4233 sb.append(" ");
4234 formatTimeMs(sb, time/1000);
4235 sb.append("(");
4236 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4237 sb.append(") ");
4238 sb.append(getWifiSupplStateCount(i, which));
4239 sb.append("x");
4240 }
4241 if (!didOne) sb.append(" (no activity)");
4242 pw.println(sb.toString());
4243
4244 sb.setLength(0);
4245 sb.append(prefix);
4246 sb.append(" Wifi signal levels:");
4247 didOne = false;
4248 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
4249 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4250 if (time == 0) {
4251 continue;
4252 }
4253 sb.append("\n ");
4254 sb.append(prefix);
4255 didOne = true;
4256 sb.append("level(");
4257 sb.append(i);
4258 sb.append(") ");
4259 formatTimeMs(sb, time/1000);
4260 sb.append("(");
4261 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4262 sb.append(") ");
4263 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004264 sb.append("x");
4265 }
4266 if (!didOne) sb.append(" (no activity)");
4267 pw.println(sb.toString());
4268
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004269 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004270
Adam Lesinski50e47602015-12-04 17:04:54 -08004271 pw.print(prefix);
4272 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4273 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4274
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004275 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4276 sb.setLength(0);
4277 sb.append(prefix);
4278 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4279 pw.println(sb.toString());
4280
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004281 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4282 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004283
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004284 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004285
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004286 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004287 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004288 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004289 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004290 pw.println(getDischargeStartLevel());
4291 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4292 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004293 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004294 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004295 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004296 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004297 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004298 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004299 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004300 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4301 pw.println(getDischargeAmountScreenOn());
4302 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4303 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004304 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004305 } else {
4306 pw.print(prefix); pw.println(" Device battery use since last full charge");
4307 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
4308 pw.println(getLowDischargeAmountSinceCharge());
4309 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
4310 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004311 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4312 pw.println(getDischargeAmountScreenOnSinceCharge());
4313 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4314 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004315 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004316 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004317
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004318 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004319 helper.create(this);
4320 helper.refreshStats(which, UserHandle.USER_ALL);
4321 List<BatterySipper> sippers = helper.getUsageList();
4322 if (sippers != null && sippers.size() > 0) {
4323 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4324 pw.print(prefix); pw.print(" Capacity: ");
4325 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004326 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004327 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4328 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4329 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4330 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004331 pw.println();
4332 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004333 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004334 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004335 switch (bs.drainType) {
4336 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004337 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004338 break;
4339 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004340 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004341 break;
4342 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004343 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004344 break;
4345 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004346 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004347 break;
4348 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004349 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004350 break;
4351 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004352 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004353 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004354 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004355 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004356 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004357 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004358 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004359 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004360 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004361 break;
4362 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004363 pw.print(" User "); pw.print(bs.userId);
4364 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004365 break;
4366 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004367 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004368 break;
4369 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004370 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004371 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004372 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004373 pw.print(" Camera: ");
4374 break;
4375 default:
4376 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004377 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004378 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004379 printmAh(pw, bs.totalPowerMah);
4380
Adam Lesinski57123002015-06-12 16:12:07 -07004381 if (bs.usagePowerMah != bs.totalPowerMah) {
4382 // If the usage (generic power) isn't the whole amount, we list out
4383 // what components are involved in the calculation.
4384
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004385 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004386 if (bs.usagePowerMah != 0) {
4387 pw.print(" usage=");
4388 printmAh(pw, bs.usagePowerMah);
4389 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004390 if (bs.cpuPowerMah != 0) {
4391 pw.print(" cpu=");
4392 printmAh(pw, bs.cpuPowerMah);
4393 }
4394 if (bs.wakeLockPowerMah != 0) {
4395 pw.print(" wake=");
4396 printmAh(pw, bs.wakeLockPowerMah);
4397 }
4398 if (bs.mobileRadioPowerMah != 0) {
4399 pw.print(" radio=");
4400 printmAh(pw, bs.mobileRadioPowerMah);
4401 }
4402 if (bs.wifiPowerMah != 0) {
4403 pw.print(" wifi=");
4404 printmAh(pw, bs.wifiPowerMah);
4405 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004406 if (bs.bluetoothPowerMah != 0) {
4407 pw.print(" bt=");
4408 printmAh(pw, bs.bluetoothPowerMah);
4409 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004410 if (bs.gpsPowerMah != 0) {
4411 pw.print(" gps=");
4412 printmAh(pw, bs.gpsPowerMah);
4413 }
4414 if (bs.sensorPowerMah != 0) {
4415 pw.print(" sensor=");
4416 printmAh(pw, bs.sensorPowerMah);
4417 }
4418 if (bs.cameraPowerMah != 0) {
4419 pw.print(" camera=");
4420 printmAh(pw, bs.cameraPowerMah);
4421 }
4422 if (bs.flashlightPowerMah != 0) {
4423 pw.print(" flash=");
4424 printmAh(pw, bs.flashlightPowerMah);
4425 }
4426 pw.print(" )");
4427 }
Bookatz17d7d9d2017-06-08 14:50:46 -07004428
4429 // If there is additional smearing information, include it.
4430 if (bs.totalSmearedPowerMah != bs.totalPowerMah) {
4431 pw.print(" Including smearing: ");
4432 printmAh(pw, bs.totalSmearedPowerMah);
4433 pw.print(" (");
4434 if (bs.screenPowerMah != 0) {
4435 pw.print(" screen=");
4436 printmAh(pw, bs.screenPowerMah);
4437 }
4438 if (bs.proportionalSmearMah != 0) {
4439 pw.print(" proportional=");
4440 printmAh(pw, bs.proportionalSmearMah);
4441 }
4442 pw.print(" )");
4443 }
4444 if (bs.shouldHide) {
4445 pw.print(" Excluded from smearing");
4446 }
4447
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004448 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004449 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004450 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004451 }
4452
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004453 sippers = helper.getMobilemsppList();
4454 if (sippers != null && sippers.size() > 0) {
4455 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004456 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004457 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004458 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004459 sb.setLength(0);
4460 sb.append(prefix); sb.append(" Uid ");
4461 UserHandle.formatUid(sb, bs.uidObj.getUid());
4462 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4463 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4464 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004465 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004466 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004467 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004468 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004469 sb.setLength(0);
4470 sb.append(prefix);
4471 sb.append(" TOTAL TIME: ");
4472 formatTimeMs(sb, totalTime);
4473 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4474 sb.append(")");
4475 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004476 pw.println();
4477 }
4478
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004479 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4480 @Override
4481 public int compare(TimerEntry lhs, TimerEntry rhs) {
4482 long lhsTime = lhs.mTime;
4483 long rhsTime = rhs.mTime;
4484 if (lhsTime < rhsTime) {
4485 return 1;
4486 }
4487 if (lhsTime > rhsTime) {
4488 return -1;
4489 }
4490 return 0;
4491 }
4492 };
4493
4494 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004495 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4496 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004497 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004498 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4499 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4500 : kernelWakelocks.entrySet()) {
4501 final BatteryStats.Timer timer = ent.getValue();
4502 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004503 if (totalTimeMillis > 0) {
4504 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4505 }
4506 }
4507 if (ktimers.size() > 0) {
4508 Collections.sort(ktimers, timerComparator);
4509 pw.print(prefix); pw.println(" All kernel wake locks:");
4510 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004511 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004512 String linePrefix = ": ";
4513 sb.setLength(0);
4514 sb.append(prefix);
4515 sb.append(" Kernel Wake lock ");
4516 sb.append(timer.mName);
4517 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4518 which, linePrefix);
4519 if (!linePrefix.equals(": ")) {
4520 sb.append(" realtime");
4521 // Only print out wake locks that were held
4522 pw.println(sb.toString());
4523 }
4524 }
4525 pw.println();
4526 }
4527 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004528
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004529 if (timers.size() > 0) {
4530 Collections.sort(timers, timerComparator);
4531 pw.print(prefix); pw.println(" All partial wake locks:");
4532 for (int i=0; i<timers.size(); i++) {
4533 TimerEntry timer = timers.get(i);
4534 sb.setLength(0);
4535 sb.append(" Wake lock ");
4536 UserHandle.formatUid(sb, timer.mId);
4537 sb.append(" ");
4538 sb.append(timer.mName);
4539 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4540 sb.append(" realtime");
4541 pw.println(sb.toString());
4542 }
4543 timers.clear();
4544 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004545 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004546
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004547 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004548 if (wakeupReasons.size() > 0) {
4549 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004550 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004551 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004552 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004553 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4554 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004555 }
4556 Collections.sort(reasons, timerComparator);
4557 for (int i=0; i<reasons.size(); i++) {
4558 TimerEntry timer = reasons.get(i);
4559 String linePrefix = ": ";
4560 sb.setLength(0);
4561 sb.append(prefix);
4562 sb.append(" Wakeup reason ");
4563 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004564 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4565 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004566 pw.println(sb.toString());
4567 }
4568 pw.println();
4569 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004570 }
Evan Millar22ac0432009-03-31 11:33:18 -07004571
James Carr2dd7e5e2016-07-20 18:48:39 -07004572 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
4573 pw.println("Memory Stats");
4574 for (int i = 0; i < mMemoryStats.size(); i++) {
4575 sb.setLength(0);
4576 sb.append("Bandwidth ");
4577 sb.append(mMemoryStats.keyAt(i));
4578 sb.append(" Time ");
4579 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4580 pw.println(sb.toString());
4581 }
4582
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004583 final long[] cpuFreqs = getCpuFreqs();
4584 if (cpuFreqs != null) {
4585 sb.setLength(0);
4586 sb.append("CPU freqs:");
4587 for (int i = 0; i < cpuFreqs.length; ++i) {
4588 sb.append(" " + cpuFreqs[i]);
4589 }
4590 pw.println(sb.toString());
4591 }
4592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004593 for (int iu=0; iu<NU; iu++) {
4594 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004595 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004596 continue;
4597 }
Bookatzc8c44962017-05-11 12:12:54 -07004598
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004599 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004600
4601 pw.print(prefix);
4602 pw.print(" ");
4603 UserHandle.formatUid(pw, uid);
4604 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004605 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004606
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004607 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4608 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4609 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4610 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004611 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4612 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4613
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004614 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4615 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004616 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4617 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004618
4619 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4620 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4621
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004622 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4623 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4624 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08004625 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
4626 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4627 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
4628 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004629 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004630
Adam Lesinski5f056f62016-07-14 16:56:08 -07004631 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4632 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4633
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004634 if (mobileRxBytes > 0 || mobileTxBytes > 0
4635 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004636 pw.print(prefix); pw.print(" Mobile network: ");
4637 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004638 pw.print(formatBytesLocked(mobileTxBytes));
4639 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4640 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004641 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004642 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4643 sb.setLength(0);
4644 sb.append(prefix); sb.append(" Mobile radio active: ");
4645 formatTimeMs(sb, uidMobileActiveTime / 1000);
4646 sb.append("(");
4647 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4648 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4649 long packets = mobileRxPackets + mobileTxPackets;
4650 if (packets == 0) {
4651 packets = 1;
4652 }
4653 sb.append(" @ ");
4654 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4655 sb.append(" mspp");
4656 pw.println(sb.toString());
4657 }
4658
Adam Lesinski5f056f62016-07-14 16:56:08 -07004659 if (mobileWakeup > 0) {
4660 sb.setLength(0);
4661 sb.append(prefix);
4662 sb.append(" Mobile radio AP wakeups: ");
4663 sb.append(mobileWakeup);
4664 pw.println(sb.toString());
4665 }
4666
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004667 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4668 u.getModemControllerActivity(), which);
4669
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004670 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004671 pw.print(prefix); pw.print(" Wi-Fi network: ");
4672 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004673 pw.print(formatBytesLocked(wifiTxBytes));
4674 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4675 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004676 }
4677
Dianne Hackborn62793e42015-03-09 11:15:41 -07004678 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08004679 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004680 || uidWifiRunningTime != 0) {
4681 sb.setLength(0);
4682 sb.append(prefix); sb.append(" Wifi Running: ");
4683 formatTimeMs(sb, uidWifiRunningTime / 1000);
4684 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4685 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07004686 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004687 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4688 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4689 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08004690 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004691 formatTimeMs(sb, wifiScanTime / 1000);
4692 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004693 whichBatteryRealtime)); sb.append(") ");
4694 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08004695 sb.append("x\n");
4696 // actual and background times are unpooled and since reset (regardless of 'which')
4697 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
4698 formatTimeMs(sb, wifiScanActualTime / 1000);
4699 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
4700 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4701 sb.append(") ");
4702 sb.append(wifiScanCount);
4703 sb.append("x\n");
4704 sb.append(prefix); sb.append(" Background Wifi Scan: ");
4705 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
4706 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
4707 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4708 sb.append(") ");
4709 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07004710 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004711 pw.println(sb.toString());
4712 }
4713
Adam Lesinski5f056f62016-07-14 16:56:08 -07004714 if (wifiWakeup > 0) {
4715 sb.setLength(0);
4716 sb.append(prefix);
4717 sb.append(" WiFi AP wakeups: ");
4718 sb.append(wifiWakeup);
4719 pw.println(sb.toString());
4720 }
4721
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004722 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4723 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004724
Adam Lesinski50e47602015-12-04 17:04:54 -08004725 if (btRxBytes > 0 || btTxBytes > 0) {
4726 pw.print(prefix); pw.print(" Bluetooth network: ");
4727 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4728 pw.print(formatBytesLocked(btTxBytes));
4729 pw.println(" sent");
4730 }
4731
Bookatz867c0d72017-03-07 18:23:42 -08004732 final Timer bleTimer = u.getBluetoothScanTimer();
4733 if (bleTimer != null) {
4734 // Convert from microseconds to milliseconds with rounding
4735 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
4736 / 1000;
4737 if (totalTimeMs != 0) {
4738 final int count = bleTimer.getCountLocked(which);
4739 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
4740 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004741 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4742 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
4743 final long actualTimeMsBg = bleTimerBg != null ?
4744 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004745 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07004746 final int resultCount = u.getBluetoothScanResultCounter() != null ?
4747 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004748 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
4749 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
4750 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
4751 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
4752 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
4753 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4754 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
4755 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
4756 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
4757 final Timer unoptimizedScanTimerBg =
4758 u.getBluetoothUnoptimizedScanBackgroundTimer();
4759 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
4760 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4761 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
4762 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004763
4764 sb.setLength(0);
Bookatz867c0d72017-03-07 18:23:42 -08004765 if (actualTimeMs != totalTimeMs) {
Bookatzb1f04f32017-05-19 13:57:32 -07004766 sb.append(prefix);
4767 sb.append(" Bluetooth Scan (total blamed realtime): ");
Bookatz867c0d72017-03-07 18:23:42 -08004768 formatTimeMs(sb, totalTimeMs);
Bookatzb1f04f32017-05-19 13:57:32 -07004769 sb.append(" (");
4770 sb.append(count);
4771 sb.append(" times)");
4772 if (bleTimer.isRunningLocked()) {
4773 sb.append(" (currently running)");
4774 }
4775 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08004776 }
Bookatzb1f04f32017-05-19 13:57:32 -07004777
4778 sb.append(prefix);
4779 sb.append(" Bluetooth Scan (total actual realtime): ");
4780 formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which'
4781 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08004782 sb.append(count);
4783 sb.append(" times)");
4784 if (bleTimer.isRunningLocked()) {
Bookatzb1f04f32017-05-19 13:57:32 -07004785 sb.append(" (currently running)");
Bookatz867c0d72017-03-07 18:23:42 -08004786 }
Bookatzb1f04f32017-05-19 13:57:32 -07004787 sb.append("\n");
4788 if (actualTimeMsBg > 0 || countBg > 0) {
4789 sb.append(prefix);
4790 sb.append(" Bluetooth Scan (background realtime): ");
4791 formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which'
4792 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08004793 sb.append(countBg);
4794 sb.append(" times)");
Bookatzb1f04f32017-05-19 13:57:32 -07004795 if (bleTimerBg != null && bleTimerBg.isRunningLocked()) {
4796 sb.append(" (currently running in background)");
4797 }
4798 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08004799 }
Bookatzb1f04f32017-05-19 13:57:32 -07004800
4801 sb.append(prefix);
4802 sb.append(" Bluetooth Scan Results: ");
Bookatz956f36bf2017-04-28 09:48:17 -07004803 sb.append(resultCount);
Bookatzb1f04f32017-05-19 13:57:32 -07004804 sb.append(" (");
4805 sb.append(resultCountBg);
4806 sb.append(" in background)");
4807
4808 if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) {
4809 sb.append("\n");
4810 sb.append(prefix);
4811 sb.append(" Unoptimized Bluetooth Scan (realtime): ");
4812 formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which'
4813 sb.append(" (max ");
4814 formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which'
4815 sb.append(")");
4816 if (unoptimizedScanTimer != null
4817 && unoptimizedScanTimer.isRunningLocked()) {
4818 sb.append(" (currently running unoptimized)");
4819 }
4820 if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) {
4821 sb.append("\n");
4822 sb.append(prefix);
4823 sb.append(" Unoptimized Bluetooth Scan (background realtime): ");
4824 formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset
4825 sb.append(" (max ");
4826 formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset
4827 sb.append(")");
4828 if (unoptimizedScanTimerBg.isRunningLocked()) {
4829 sb.append(" (currently running unoptimized in background)");
4830 }
4831 }
4832 }
Bookatz867c0d72017-03-07 18:23:42 -08004833 pw.println(sb.toString());
4834 uidActivity = true;
4835 }
4836 }
4837
4838
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004839
Dianne Hackborn617f8772009-03-31 15:04:46 -07004840 if (u.hasUserActivity()) {
4841 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004842 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004843 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004844 if (val != 0) {
4845 if (!hasData) {
4846 sb.setLength(0);
4847 sb.append(" User activity: ");
4848 hasData = true;
4849 } else {
4850 sb.append(", ");
4851 }
4852 sb.append(val);
4853 sb.append(" ");
4854 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4855 }
4856 }
4857 if (hasData) {
4858 pw.println(sb.toString());
4859 }
4860 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004861
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004862 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4863 = u.getWakelockStats();
4864 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004865 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004866 int countWakelock = 0;
4867 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4868 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4869 String linePrefix = ": ";
4870 sb.setLength(0);
4871 sb.append(prefix);
4872 sb.append(" Wake lock ");
4873 sb.append(wakelocks.keyAt(iw));
4874 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4875 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004876 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4877 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004878 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004879 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
4880 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004881 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4882 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004883 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4884 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004885 sb.append(" realtime");
4886 pw.println(sb.toString());
4887 uidActivity = true;
4888 countWakelock++;
4889
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004890 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4891 rawRealtime, which);
4892 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4893 rawRealtime, which);
4894 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4895 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004896 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004897 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004898 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004899 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07004900 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
4901 // pooled and therefore just a lower bound)
4902 long actualTotalPartialWakelock = 0;
4903 long actualBgPartialWakelock = 0;
4904 if (u.getAggregatedPartialWakelockTimer() != null) {
4905 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
4906 // Convert from microseconds to milliseconds with rounding
4907 actualTotalPartialWakelock =
Bookatz6d799932017-06-07 12:30:07 -07004908 aggTimer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07004909 final Timer bgAggTimer = aggTimer.getSubTimer();
4910 actualBgPartialWakelock = bgAggTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004911 bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07004912 }
4913
4914 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
4915 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
4916 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004917 sb.setLength(0);
4918 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004919 sb.append(" TOTAL wake: ");
4920 boolean needComma = false;
4921 if (totalFullWakelock != 0) {
4922 needComma = true;
4923 formatTimeMs(sb, totalFullWakelock);
4924 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004925 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004926 if (totalPartialWakelock != 0) {
4927 if (needComma) {
4928 sb.append(", ");
4929 }
4930 needComma = true;
4931 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07004932 sb.append("blamed partial");
4933 }
4934 if (actualTotalPartialWakelock != 0) {
4935 if (needComma) {
4936 sb.append(", ");
4937 }
4938 needComma = true;
4939 formatTimeMs(sb, actualTotalPartialWakelock);
4940 sb.append("actual partial");
4941 }
4942 if (actualBgPartialWakelock != 0) {
4943 if (needComma) {
4944 sb.append(", ");
4945 }
4946 needComma = true;
4947 formatTimeMs(sb, actualBgPartialWakelock);
4948 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004949 }
4950 if (totalWindowWakelock != 0) {
4951 if (needComma) {
4952 sb.append(", ");
4953 }
4954 needComma = true;
4955 formatTimeMs(sb, totalWindowWakelock);
4956 sb.append("window");
4957 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004958 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004959 if (needComma) {
4960 sb.append(",");
4961 }
4962 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004963 formatTimeMs(sb, totalDrawWakelock);
4964 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004965 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004966 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004967 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004968 }
4969 }
4970
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004971 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4972 for (int isy=syncs.size()-1; isy>=0; isy--) {
4973 final Timer timer = syncs.valueAt(isy);
4974 // Convert from microseconds to milliseconds with rounding
4975 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4976 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07004977 final Timer bgTimer = timer.getSubTimer();
4978 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004979 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07004980 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004981 sb.setLength(0);
4982 sb.append(prefix);
4983 sb.append(" Sync ");
4984 sb.append(syncs.keyAt(isy));
4985 sb.append(": ");
4986 if (totalTime != 0) {
4987 formatTimeMs(sb, totalTime);
4988 sb.append("realtime (");
4989 sb.append(count);
4990 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07004991 if (bgTime > 0) {
4992 sb.append(", ");
4993 formatTimeMs(sb, bgTime);
4994 sb.append("background (");
4995 sb.append(bgCount);
4996 sb.append(" times)");
4997 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004998 } else {
4999 sb.append("(not used)");
5000 }
5001 pw.println(sb.toString());
5002 uidActivity = true;
5003 }
5004
5005 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
5006 for (int ij=jobs.size()-1; ij>=0; ij--) {
5007 final Timer timer = jobs.valueAt(ij);
5008 // Convert from microseconds to milliseconds with rounding
5009 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5010 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07005011 final Timer bgTimer = timer.getSubTimer();
5012 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005013 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07005014 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005015 sb.setLength(0);
5016 sb.append(prefix);
5017 sb.append(" Job ");
5018 sb.append(jobs.keyAt(ij));
5019 sb.append(": ");
5020 if (totalTime != 0) {
5021 formatTimeMs(sb, totalTime);
5022 sb.append("realtime (");
5023 sb.append(count);
5024 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07005025 if (bgTime > 0) {
5026 sb.append(", ");
5027 formatTimeMs(sb, bgTime);
5028 sb.append("background (");
5029 sb.append(bgCount);
5030 sb.append(" times)");
5031 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005032 } else {
5033 sb.append("(not used)");
5034 }
5035 pw.println(sb.toString());
5036 uidActivity = true;
5037 }
5038
Dianne Hackborn94326cb2017-06-28 16:17:20 -07005039 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
5040 for (int ic=completions.size()-1; ic>=0; ic--) {
5041 SparseIntArray types = completions.valueAt(ic);
5042 if (types != null) {
5043 pw.print(prefix);
5044 pw.print(" Job Completions ");
5045 pw.print(completions.keyAt(ic));
5046 pw.print(":");
5047 for (int it=0; it<types.size(); it++) {
5048 pw.print(" ");
5049 pw.print(JobParameters.getReasonName(types.keyAt(it)));
5050 pw.print("(");
5051 pw.print(types.valueAt(it));
5052 pw.print("x)");
5053 }
5054 pw.println();
5055 }
5056 }
5057
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005058 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
5059 prefix, "Flashlight");
5060 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
5061 prefix, "Camera");
5062 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
5063 prefix, "Video");
5064 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
5065 prefix, "Audio");
5066
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005067 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
5068 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005069 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005070 final Uid.Sensor se = sensors.valueAt(ise);
5071 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005072 sb.setLength(0);
5073 sb.append(prefix);
5074 sb.append(" Sensor ");
5075 int handle = se.getHandle();
5076 if (handle == Uid.Sensor.GPS) {
5077 sb.append("GPS");
5078 } else {
5079 sb.append(handle);
5080 }
5081 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005082
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005083 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005084 if (timer != null) {
5085 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08005086 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
5087 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005088 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08005089 final Timer bgTimer = se.getSensorBackgroundTime();
5090 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005091 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5092 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
5093 final long bgActualTime = bgTimer != null ?
5094 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5095
Dianne Hackborn61659e52014-07-09 16:13:01 -07005096 //timer.logState();
5097 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08005098 if (actualTime != totalTime) {
5099 formatTimeMs(sb, totalTime);
5100 sb.append("blamed realtime, ");
5101 }
5102
5103 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07005104 sb.append("realtime (");
5105 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08005106 sb.append(" times)");
5107
5108 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005109 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08005110 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
5111 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005112 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08005113 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005114 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005115 } else {
5116 sb.append("(not used)");
5117 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005118 } else {
5119 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005120 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005121
5122 pw.println(sb.toString());
5123 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 }
5125
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005126 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
5127 "Vibrator");
5128 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
5129 prefix, "Foreground activities");
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07005130 uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which,
5131 prefix, "Foreground services");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07005132
Dianne Hackborn61659e52014-07-09 16:13:01 -07005133 long totalStateTime = 0;
5134 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
5135 long time = u.getProcessStateTime(ips, rawRealtime, which);
5136 if (time > 0) {
5137 totalStateTime += time;
5138 sb.setLength(0);
5139 sb.append(prefix);
5140 sb.append(" ");
5141 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
5142 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08005143 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005144 pw.println(sb.toString());
5145 uidActivity = true;
5146 }
5147 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08005148 if (totalStateTime > 0) {
5149 sb.setLength(0);
5150 sb.append(prefix);
5151 sb.append(" Total running: ");
5152 formatTimeMs(sb, (totalStateTime + 500) / 1000);
5153 pw.println(sb.toString());
5154 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005155
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005156 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
5157 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07005158 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005159 sb.setLength(0);
5160 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07005161 sb.append(" Total cpu time: u=");
5162 formatTimeMs(sb, userCpuTimeUs / 1000);
5163 sb.append("s=");
5164 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005165 pw.println(sb.toString());
5166 }
5167
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005168 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
5169 if (cpuFreqTimes != null) {
5170 sb.setLength(0);
5171 sb.append(" Total cpu time per freq:");
5172 for (int i = 0; i < cpuFreqTimes.length; ++i) {
5173 sb.append(" " + cpuFreqTimes[i]);
5174 }
5175 pw.println(sb.toString());
5176 }
5177 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
5178 if (screenOffCpuFreqTimes != null) {
5179 sb.setLength(0);
5180 sb.append(" Total screen-off cpu time per freq:");
5181 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
5182 sb.append(" " + screenOffCpuFreqTimes[i]);
5183 }
5184 pw.println(sb.toString());
5185 }
5186
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005187 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
5188 = u.getProcessStats();
5189 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
5190 final Uid.Proc ps = processStats.valueAt(ipr);
5191 long userTime;
5192 long systemTime;
5193 long foregroundTime;
5194 int starts;
5195 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005196
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005197 userTime = ps.getUserTime(which);
5198 systemTime = ps.getSystemTime(which);
5199 foregroundTime = ps.getForegroundTime(which);
5200 starts = ps.getStarts(which);
5201 final int numCrashes = ps.getNumCrashes(which);
5202 final int numAnrs = ps.getNumAnrs(which);
5203 numExcessive = which == STATS_SINCE_CHARGED
5204 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005205
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005206 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5207 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5208 sb.setLength(0);
5209 sb.append(prefix); sb.append(" Proc ");
5210 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5211 sb.append(prefix); sb.append(" CPU: ");
5212 formatTimeMs(sb, userTime); sb.append("usr + ");
5213 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5214 formatTimeMs(sb, foregroundTime); sb.append("fg");
5215 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5216 sb.append("\n"); sb.append(prefix); sb.append(" ");
5217 boolean hasOne = false;
5218 if (starts != 0) {
5219 hasOne = true;
5220 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005221 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005222 if (numCrashes != 0) {
5223 if (hasOne) {
5224 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005225 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005226 hasOne = true;
5227 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005228 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005229 if (numAnrs != 0) {
5230 if (hasOne) {
5231 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005232 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005233 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005234 }
5235 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005236 pw.println(sb.toString());
5237 for (int e=0; e<numExcessive; e++) {
5238 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5239 if (ew != null) {
5240 pw.print(prefix); pw.print(" * Killed for ");
Dianne Hackbornffca58b2017-05-24 16:15:45 -07005241 if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005242 pw.print("cpu");
5243 } else {
5244 pw.print("unknown");
5245 }
5246 pw.print(" use: ");
5247 TimeUtils.formatDuration(ew.usedTime, pw);
5248 pw.print(" over ");
5249 TimeUtils.formatDuration(ew.overTime, pw);
5250 if (ew.overTime != 0) {
5251 pw.print(" (");
5252 pw.print((ew.usedTime*100)/ew.overTime);
5253 pw.println("%)");
5254 }
5255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005256 }
5257 uidActivity = true;
5258 }
5259 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005260
5261 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5262 = u.getPackageStats();
5263 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5264 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5265 pw.println(":");
5266 boolean apkActivity = false;
5267 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5268 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5269 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5270 pw.print(prefix); pw.print(" Wakeup alarm ");
5271 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5272 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5273 pw.println(" times");
5274 apkActivity = true;
5275 }
5276 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5277 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5278 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5279 final long startTime = ss.getStartTime(batteryUptime, which);
5280 final int starts = ss.getStarts(which);
5281 final int launches = ss.getLaunches(which);
5282 if (startTime != 0 || starts != 0 || launches != 0) {
5283 sb.setLength(0);
5284 sb.append(prefix); sb.append(" Service ");
5285 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5286 sb.append(prefix); sb.append(" Created for: ");
5287 formatTimeMs(sb, startTime / 1000);
5288 sb.append("uptime\n");
5289 sb.append(prefix); sb.append(" Starts: ");
5290 sb.append(starts);
5291 sb.append(", launches: "); sb.append(launches);
5292 pw.println(sb.toString());
5293 apkActivity = true;
5294 }
5295 }
5296 if (!apkActivity) {
5297 pw.print(prefix); pw.println(" (nothing executed)");
5298 }
5299 uidActivity = true;
5300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005301 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005302 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005303 }
5304 }
5305 }
5306
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005307 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005308 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005309 int diff = oldval ^ newval;
5310 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005311 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005312 for (int i=0; i<descriptions.length; i++) {
5313 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005314 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005315 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005316 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005317 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005318 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005319 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5320 didWake = true;
5321 pw.print("=");
5322 if (longNames) {
5323 UserHandle.formatUid(pw, wakelockTag.uid);
5324 pw.print(":\"");
5325 pw.print(wakelockTag.string);
5326 pw.print("\"");
5327 } else {
5328 pw.print(wakelockTag.poolIdx);
5329 }
5330 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005331 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005332 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005333 pw.print("=");
5334 int val = (newval&bd.mask)>>bd.shift;
5335 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005336 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005337 } else {
5338 pw.print(val);
5339 }
5340 }
5341 }
5342 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005343 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005344 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005345 if (longNames) {
5346 UserHandle.formatUid(pw, wakelockTag.uid);
5347 pw.print(":\"");
5348 pw.print(wakelockTag.string);
5349 pw.print("\"");
5350 } else {
5351 pw.print(wakelockTag.poolIdx);
5352 }
5353 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005354 }
5355
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005356 public void prepareForDumpLocked() {
5357 }
5358
5359 public static class HistoryPrinter {
5360 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005361 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005362 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005363 int oldStatus = -1;
5364 int oldHealth = -1;
5365 int oldPlug = -1;
5366 int oldTemp = -1;
5367 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005368 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005369 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005370
Dianne Hackborn3251b902014-06-20 14:40:53 -07005371 void reset() {
5372 oldState = oldState2 = 0;
5373 oldLevel = -1;
5374 oldStatus = -1;
5375 oldHealth = -1;
5376 oldPlug = -1;
5377 oldTemp = -1;
5378 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005379 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005380 }
5381
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005382 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005383 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005384 if (!checkin) {
5385 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005386 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005387 pw.print(" (");
5388 pw.print(rec.numReadInts);
5389 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005390 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005391 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5392 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005393 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005394 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005395 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005396 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005397 }
5398 lastTime = rec.time;
5399 }
5400 if (rec.cmd == HistoryItem.CMD_START) {
5401 if (checkin) {
5402 pw.print(":");
5403 }
5404 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005405 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005406 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5407 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005408 if (checkin) {
5409 pw.print(":");
5410 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005411 if (rec.cmd == HistoryItem.CMD_RESET) {
5412 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005413 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005414 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005415 pw.print("TIME:");
5416 if (checkin) {
5417 pw.println(rec.currentTime);
5418 } else {
5419 pw.print(" ");
5420 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5421 rec.currentTime).toString());
5422 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005423 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5424 if (checkin) {
5425 pw.print(":");
5426 }
5427 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005428 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5429 if (checkin) {
5430 pw.print(":");
5431 }
5432 pw.println("*OVERFLOW*");
5433 } else {
5434 if (!checkin) {
5435 if (rec.batteryLevel < 10) pw.print("00");
5436 else if (rec.batteryLevel < 100) pw.print("0");
5437 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005438 if (verbose) {
5439 pw.print(" ");
5440 if (rec.states < 0) ;
5441 else if (rec.states < 0x10) pw.print("0000000");
5442 else if (rec.states < 0x100) pw.print("000000");
5443 else if (rec.states < 0x1000) pw.print("00000");
5444 else if (rec.states < 0x10000) pw.print("0000");
5445 else if (rec.states < 0x100000) pw.print("000");
5446 else if (rec.states < 0x1000000) pw.print("00");
5447 else if (rec.states < 0x10000000) pw.print("0");
5448 pw.print(Integer.toHexString(rec.states));
5449 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005450 } else {
5451 if (oldLevel != rec.batteryLevel) {
5452 oldLevel = rec.batteryLevel;
5453 pw.print(",Bl="); pw.print(rec.batteryLevel);
5454 }
5455 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005456 if (oldStatus != rec.batteryStatus) {
5457 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005458 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005459 switch (oldStatus) {
5460 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005461 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005462 break;
5463 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005464 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005465 break;
5466 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005467 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005468 break;
5469 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005470 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005471 break;
5472 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005473 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005474 break;
5475 default:
5476 pw.print(oldStatus);
5477 break;
5478 }
5479 }
5480 if (oldHealth != rec.batteryHealth) {
5481 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005482 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005483 switch (oldHealth) {
5484 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005485 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005486 break;
5487 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005488 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005489 break;
5490 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005491 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005492 break;
5493 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005494 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005495 break;
5496 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005497 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005498 break;
5499 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005500 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005501 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005502 case BatteryManager.BATTERY_HEALTH_COLD:
5503 pw.print(checkin ? "c" : "cold");
5504 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005505 default:
5506 pw.print(oldHealth);
5507 break;
5508 }
5509 }
5510 if (oldPlug != rec.batteryPlugType) {
5511 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005512 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005513 switch (oldPlug) {
5514 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005515 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005516 break;
5517 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005518 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005519 break;
5520 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005521 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005522 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005523 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005524 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005525 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005526 default:
5527 pw.print(oldPlug);
5528 break;
5529 }
5530 }
5531 if (oldTemp != rec.batteryTemperature) {
5532 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005533 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005534 pw.print(oldTemp);
5535 }
5536 if (oldVolt != rec.batteryVoltage) {
5537 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005538 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005539 pw.print(oldVolt);
5540 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005541 final int chargeMAh = rec.batteryChargeUAh / 1000;
5542 if (oldChargeMAh != chargeMAh) {
5543 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005544 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005545 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005546 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005547 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005548 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005549 printBitDescriptions(pw, oldState2, rec.states2, null,
5550 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005551 if (rec.wakeReasonTag != null) {
5552 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005553 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005554 pw.print(rec.wakeReasonTag.poolIdx);
5555 } else {
5556 pw.print(" wake_reason=");
5557 pw.print(rec.wakeReasonTag.uid);
5558 pw.print(":\"");
5559 pw.print(rec.wakeReasonTag.string);
5560 pw.print("\"");
5561 }
5562 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005563 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005564 pw.print(checkin ? "," : " ");
5565 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5566 pw.print("+");
5567 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5568 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005569 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005570 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
5571 : HISTORY_EVENT_NAMES;
5572 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
5573 | HistoryItem.EVENT_FLAG_FINISH);
5574 if (idx >= 0 && idx < eventNames.length) {
5575 pw.print(eventNames[idx]);
5576 } else {
5577 pw.print(checkin ? "Ev" : "event");
5578 pw.print(idx);
5579 }
5580 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005581 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005582 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08005583 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08005584 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
5585 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005586 pw.print(":\"");
5587 pw.print(rec.eventTag.string);
5588 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005589 }
5590 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005591 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005592 if (rec.stepDetails != null) {
5593 if (!checkin) {
5594 pw.print(" Details: cpu=");
5595 pw.print(rec.stepDetails.userTime);
5596 pw.print("u+");
5597 pw.print(rec.stepDetails.systemTime);
5598 pw.print("s");
5599 if (rec.stepDetails.appCpuUid1 >= 0) {
5600 pw.print(" (");
5601 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
5602 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5603 if (rec.stepDetails.appCpuUid2 >= 0) {
5604 pw.print(", ");
5605 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
5606 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5607 }
5608 if (rec.stepDetails.appCpuUid3 >= 0) {
5609 pw.print(", ");
5610 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
5611 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5612 }
5613 pw.print(')');
5614 }
5615 pw.println();
5616 pw.print(" /proc/stat=");
5617 pw.print(rec.stepDetails.statUserTime);
5618 pw.print(" usr, ");
5619 pw.print(rec.stepDetails.statSystemTime);
5620 pw.print(" sys, ");
5621 pw.print(rec.stepDetails.statIOWaitTime);
5622 pw.print(" io, ");
5623 pw.print(rec.stepDetails.statIrqTime);
5624 pw.print(" irq, ");
5625 pw.print(rec.stepDetails.statSoftIrqTime);
5626 pw.print(" sirq, ");
5627 pw.print(rec.stepDetails.statIdlTime);
5628 pw.print(" idle");
5629 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
5630 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
5631 + rec.stepDetails.statSoftIrqTime;
5632 int total = totalRun + rec.stepDetails.statIdlTime;
5633 if (total > 0) {
5634 pw.print(" (");
5635 float perc = ((float)totalRun) / ((float)total) * 100;
5636 pw.print(String.format("%.1f%%", perc));
5637 pw.print(" of ");
5638 StringBuilder sb = new StringBuilder(64);
5639 formatTimeMsNoSpace(sb, total*10);
5640 pw.print(sb);
5641 pw.print(")");
5642 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005643 pw.print(", PlatformIdleStat ");
5644 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005645 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005646
5647 pw.print(", SubsystemPowerState ");
5648 pw.print(rec.stepDetails.statSubsystemPowerState);
5649 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005650 } else {
5651 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5652 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
5653 pw.print(rec.stepDetails.userTime);
5654 pw.print(":");
5655 pw.print(rec.stepDetails.systemTime);
5656 if (rec.stepDetails.appCpuUid1 >= 0) {
5657 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
5658 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5659 if (rec.stepDetails.appCpuUid2 >= 0) {
5660 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
5661 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5662 }
5663 if (rec.stepDetails.appCpuUid3 >= 0) {
5664 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
5665 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5666 }
5667 }
5668 pw.println();
5669 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5670 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
5671 pw.print(rec.stepDetails.statUserTime);
5672 pw.print(',');
5673 pw.print(rec.stepDetails.statSystemTime);
5674 pw.print(',');
5675 pw.print(rec.stepDetails.statIOWaitTime);
5676 pw.print(',');
5677 pw.print(rec.stepDetails.statIrqTime);
5678 pw.print(',');
5679 pw.print(rec.stepDetails.statSoftIrqTime);
5680 pw.print(',');
5681 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005682 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005683 if (rec.stepDetails.statPlatformIdleState != null) {
5684 pw.print(rec.stepDetails.statPlatformIdleState);
Ahmed ElArabawy307edcd2017-07-07 17:48:13 -07005685 if (rec.stepDetails.statSubsystemPowerState != null) {
5686 pw.print(',');
5687 }
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005688 }
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005689
5690 if (rec.stepDetails.statSubsystemPowerState != null) {
5691 pw.print(rec.stepDetails.statSubsystemPowerState);
5692 }
5693 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005694 }
5695 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005696 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005697 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005698 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005699 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005700
5701 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
5702 UserHandle.formatUid(pw, uid);
5703 pw.print("=");
5704 pw.print(utime);
5705 pw.print("u+");
5706 pw.print(stime);
5707 pw.print("s");
5708 }
5709
5710 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5711 pw.print('/');
5712 pw.print(uid);
5713 pw.print(":");
5714 pw.print(utime);
5715 pw.print(":");
5716 pw.print(stime);
5717 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005718 }
5719
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005720 private void printSizeValue(PrintWriter pw, long size) {
5721 float result = size;
5722 String suffix = "";
5723 if (result >= 10*1024) {
5724 suffix = "KB";
5725 result = result / 1024;
5726 }
5727 if (result >= 10*1024) {
5728 suffix = "MB";
5729 result = result / 1024;
5730 }
5731 if (result >= 10*1024) {
5732 suffix = "GB";
5733 result = result / 1024;
5734 }
5735 if (result >= 10*1024) {
5736 suffix = "TB";
5737 result = result / 1024;
5738 }
5739 if (result >= 10*1024) {
5740 suffix = "PB";
5741 result = result / 1024;
5742 }
5743 pw.print((int)result);
5744 pw.print(suffix);
5745 }
5746
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005747 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5748 String label3, long estimatedTime) {
5749 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005750 return false;
5751 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005752 pw.print(label1);
5753 pw.print(label2);
5754 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005755 StringBuilder sb = new StringBuilder(64);
5756 formatTimeMs(sb, estimatedTime);
5757 pw.print(sb);
5758 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005759 return true;
5760 }
5761
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005762 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5763 LevelStepTracker steps, boolean checkin) {
5764 if (steps == null) {
5765 return false;
5766 }
5767 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005768 if (count <= 0) {
5769 return false;
5770 }
5771 if (!checkin) {
5772 pw.println(header);
5773 }
Kweku Adams030980a2015-04-01 16:07:48 -07005774 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005775 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005776 long duration = steps.getDurationAt(i);
5777 int level = steps.getLevelAt(i);
5778 long initMode = steps.getInitModeAt(i);
5779 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005780 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005781 lineArgs[0] = Long.toString(duration);
5782 lineArgs[1] = Integer.toString(level);
5783 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5784 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5785 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5786 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5787 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5788 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005789 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005790 }
5791 } else {
5792 lineArgs[2] = "";
5793 }
5794 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5795 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5796 } else {
5797 lineArgs[3] = "";
5798 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005799 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005800 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005801 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005802 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005803 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005804 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5805 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005806 pw.print(prefix);
5807 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005808 TimeUtils.formatDuration(duration, pw);
5809 pw.print(" to "); pw.print(level);
5810 boolean haveModes = false;
5811 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5812 pw.print(" (");
5813 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5814 case Display.STATE_OFF: pw.print("screen-off"); break;
5815 case Display.STATE_ON: pw.print("screen-on"); break;
5816 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5817 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005818 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005819 }
5820 haveModes = true;
5821 }
5822 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5823 pw.print(haveModes ? ", " : " (");
5824 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5825 ? "power-save-on" : "power-save-off");
5826 haveModes = true;
5827 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005828 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5829 pw.print(haveModes ? ", " : " (");
5830 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5831 ? "device-idle-on" : "device-idle-off");
5832 haveModes = true;
5833 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005834 if (haveModes) {
5835 pw.print(")");
5836 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005837 pw.println();
5838 }
5839 }
5840 return true;
5841 }
5842
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005843 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005844 public static final int DUMP_DAILY_ONLY = 1<<2;
5845 public static final int DUMP_HISTORY_ONLY = 1<<3;
5846 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5847 public static final int DUMP_VERBOSE = 1<<5;
5848 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005849
Dianne Hackborn37de0982014-05-09 09:32:18 -07005850 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5851 final HistoryPrinter hprinter = new HistoryPrinter();
5852 final HistoryItem rec = new HistoryItem();
5853 long lastTime = -1;
5854 long baseTime = -1;
5855 boolean printed = false;
5856 HistoryEventTracker tracker = null;
5857 while (getNextHistoryLocked(rec)) {
5858 lastTime = rec.time;
5859 if (baseTime < 0) {
5860 baseTime = lastTime;
5861 }
5862 if (rec.time >= histStart) {
5863 if (histStart >= 0 && !printed) {
5864 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005865 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005866 || rec.cmd == HistoryItem.CMD_START
5867 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005868 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005869 hprinter.printNextItem(pw, rec, baseTime, checkin,
5870 (flags&DUMP_VERBOSE) != 0);
5871 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005872 } else if (rec.currentTime != 0) {
5873 printed = true;
5874 byte cmd = rec.cmd;
5875 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005876 hprinter.printNextItem(pw, rec, baseTime, checkin,
5877 (flags&DUMP_VERBOSE) != 0);
5878 rec.cmd = cmd;
5879 }
5880 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005881 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5882 hprinter.printNextItem(pw, rec, baseTime, checkin,
5883 (flags&DUMP_VERBOSE) != 0);
5884 rec.cmd = HistoryItem.CMD_UPDATE;
5885 }
5886 int oldEventCode = rec.eventCode;
5887 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005888 rec.eventTag = new HistoryTag();
5889 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5890 HashMap<String, SparseIntArray> active
5891 = tracker.getStateForEvent(i);
5892 if (active == null) {
5893 continue;
5894 }
5895 for (HashMap.Entry<String, SparseIntArray> ent
5896 : active.entrySet()) {
5897 SparseIntArray uids = ent.getValue();
5898 for (int j=0; j<uids.size(); j++) {
5899 rec.eventCode = i;
5900 rec.eventTag.string = ent.getKey();
5901 rec.eventTag.uid = uids.keyAt(j);
5902 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005903 hprinter.printNextItem(pw, rec, baseTime, checkin,
5904 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005905 rec.wakeReasonTag = null;
5906 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005907 }
5908 }
5909 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005910 rec.eventCode = oldEventCode;
5911 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005912 tracker = null;
5913 }
5914 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005915 hprinter.printNextItem(pw, rec, baseTime, checkin,
5916 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005917 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5918 // This is an attempt to aggregate the previous state and generate
5919 // fake events to reflect that state at the point where we start
5920 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005921 if (tracker == null) {
5922 tracker = new HistoryEventTracker();
5923 }
5924 tracker.updateState(rec.eventCode, rec.eventTag.string,
5925 rec.eventTag.uid, rec.eventTag.poolIdx);
5926 }
5927 }
5928 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005929 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005930 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5931 }
5932 }
5933
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005934 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5935 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5936 if (steps == null) {
5937 return;
5938 }
5939 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5940 if (timeRemaining >= 0) {
5941 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5942 tmpSb.setLength(0);
5943 formatTimeMs(tmpSb, timeRemaining);
5944 pw.print(tmpSb);
5945 pw.print(" (from "); pw.print(tmpOutInt[0]);
5946 pw.println(" steps)");
5947 }
5948 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5949 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5950 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5951 if (estimatedTime > 0) {
5952 pw.print(prefix); pw.print(label); pw.print(" ");
5953 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5954 pw.print(" time: ");
5955 tmpSb.setLength(0);
5956 formatTimeMs(tmpSb, estimatedTime);
5957 pw.print(tmpSb);
5958 pw.print(" (from "); pw.print(tmpOutInt[0]);
5959 pw.println(" steps)");
5960 }
5961 }
5962 }
5963
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005964 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5965 ArrayList<PackageChange> changes) {
5966 if (changes == null) {
5967 return;
5968 }
5969 pw.print(prefix); pw.println("Package changes:");
5970 for (int i=0; i<changes.size(); i++) {
5971 PackageChange pc = changes.get(i);
5972 if (pc.mUpdate) {
5973 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5974 pw.print(" vers="); pw.println(pc.mVersionCode);
5975 } else {
5976 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5977 }
5978 }
5979 }
5980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005981 /**
5982 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5983 *
5984 * @param pw a Printer to receive the dump output.
5985 */
5986 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005987 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005988 prepareForDumpLocked();
5989
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005990 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005991 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005992
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005993 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005994 final long historyTotalSize = getHistoryTotalSize();
5995 final long historyUsedSize = getHistoryUsedSize();
5996 if (startIteratingHistoryLocked()) {
5997 try {
5998 pw.print("Battery History (");
5999 pw.print((100*historyUsedSize)/historyTotalSize);
6000 pw.print("% used, ");
6001 printSizeValue(pw, historyUsedSize);
6002 pw.print(" used of ");
6003 printSizeValue(pw, historyTotalSize);
6004 pw.print(", ");
6005 pw.print(getHistoryStringPoolSize());
6006 pw.print(" strings using ");
6007 printSizeValue(pw, getHistoryStringPoolBytes());
6008 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07006009 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006010 pw.println();
6011 } finally {
6012 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006013 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006014 }
6015
6016 if (startIteratingOldHistoryLocked()) {
6017 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006018 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006019 pw.println("Old battery History:");
6020 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006021 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006022 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006023 if (baseTime < 0) {
6024 baseTime = rec.time;
6025 }
6026 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006027 }
6028 pw.println();
6029 } finally {
6030 finishIteratingOldHistoryLocked();
6031 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07006032 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006033 }
6034
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006035 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006036 return;
6037 }
6038
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006039 if (!filtering) {
6040 SparseArray<? extends Uid> uidStats = getUidStats();
6041 final int NU = uidStats.size();
6042 boolean didPid = false;
6043 long nowRealtime = SystemClock.elapsedRealtime();
6044 for (int i=0; i<NU; i++) {
6045 Uid uid = uidStats.valueAt(i);
6046 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
6047 if (pids != null) {
6048 for (int j=0; j<pids.size(); j++) {
6049 Uid.Pid pid = pids.valueAt(j);
6050 if (!didPid) {
6051 pw.println("Per-PID Stats:");
6052 didPid = true;
6053 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006054 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
6055 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006056 pw.print(" PID "); pw.print(pids.keyAt(j));
6057 pw.print(" wake time: ");
6058 TimeUtils.formatDuration(time, pw);
6059 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006060 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006061 }
6062 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006063 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006064 pw.println();
6065 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006066 }
6067
6068 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006069 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
6070 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006071 long timeRemaining = computeBatteryTimeRemaining(
6072 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006073 if (timeRemaining >= 0) {
6074 pw.print(" Estimated discharge time remaining: ");
6075 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6076 pw.println();
6077 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006078 final LevelStepTracker steps = getDischargeLevelStepTracker();
6079 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6080 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
6081 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6082 STEP_LEVEL_MODE_VALUES[i], null));
6083 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006084 pw.println();
6085 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006086 if (dumpDurationSteps(pw, " ", "Charge step durations:",
6087 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006088 long timeRemaining = computeChargeTimeRemaining(
6089 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006090 if (timeRemaining >= 0) {
6091 pw.print(" Estimated charge time remaining: ");
6092 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6093 pw.println();
6094 }
6095 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006096 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006097 }
6098 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
6099 pw.println("Daily stats:");
6100 pw.print(" Current start time: ");
6101 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6102 getCurrentDailyStartTime()).toString());
6103 pw.print(" Next min deadline: ");
6104 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6105 getNextMinDailyDeadline()).toString());
6106 pw.print(" Next max deadline: ");
6107 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6108 getNextMaxDailyDeadline()).toString());
6109 StringBuilder sb = new StringBuilder(64);
6110 int[] outInt = new int[1];
6111 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
6112 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006113 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
6114 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006115 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006116 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
6117 dsteps, false)) {
6118 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6119 sb, outInt);
6120 }
6121 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
6122 csteps, false)) {
6123 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6124 sb, outInt);
6125 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006126 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006127 } else {
6128 pw.println(" Current daily steps:");
6129 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6130 sb, outInt);
6131 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6132 sb, outInt);
6133 }
6134 }
6135 DailyItem dit;
6136 int curIndex = 0;
6137 while ((dit=getDailyItemLocked(curIndex)) != null) {
6138 curIndex++;
6139 if ((flags&DUMP_DAILY_ONLY) != 0) {
6140 pw.println();
6141 }
6142 pw.print(" Daily from ");
6143 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
6144 pw.print(" to ");
6145 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
6146 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006147 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006148 if (dumpDurationSteps(pw, " ",
6149 " Discharge step durations:", dit.mDischargeSteps, false)) {
6150 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6151 sb, outInt);
6152 }
6153 if (dumpDurationSteps(pw, " ",
6154 " Charge step durations:", dit.mChargeSteps, false)) {
6155 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6156 sb, outInt);
6157 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006158 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006159 } else {
6160 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6161 sb, outInt);
6162 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6163 sb, outInt);
6164 }
6165 }
6166 pw.println();
6167 }
6168 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006169 pw.println("Statistics since last charge:");
6170 pw.println(" System starts: " + getStartCount()
6171 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07006172 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
6173 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006174 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006175 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006176 }
6177
6178 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006179 public void dumpCheckinLocked(Context context, PrintWriter pw,
6180 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006181 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006182
6183 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07006184 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
6185 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006186
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006187 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6188
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006189 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006190 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006191
6192 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07006193 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006194 try {
6195 for (int i=0; i<getHistoryStringPoolSize(); i++) {
6196 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6197 pw.print(HISTORY_STRING_POOL); pw.print(',');
6198 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006199 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006200 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006201 pw.print(",\"");
6202 String str = getHistoryTagPoolString(i);
6203 str = str.replace("\\", "\\\\");
6204 str = str.replace("\"", "\\\"");
6205 pw.print(str);
6206 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006207 pw.println();
6208 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006209 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006210 } finally {
6211 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006212 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006213 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006214 }
6215
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006216 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006217 return;
6218 }
6219
Dianne Hackborne4a59512010-12-07 11:08:07 -08006220 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006221 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006222 for (int i=0; i<apps.size(); i++) {
6223 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006224 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6225 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006226 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006227 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6228 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006229 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006230 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006231 }
6232 SparseArray<? extends Uid> uidStats = getUidStats();
6233 final int NU = uidStats.size();
6234 String[] lineArgs = new String[2];
6235 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006236 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6237 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6238 if (pkgs != null && !pkgs.second.value) {
6239 pkgs.second.value = true;
6240 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006241 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006242 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006243 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6244 (Object[])lineArgs);
6245 }
6246 }
6247 }
6248 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006249 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006250 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006251 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006252 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006253 if (timeRemaining >= 0) {
6254 lineArgs[0] = Long.toString(timeRemaining);
6255 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6256 (Object[])lineArgs);
6257 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006258 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006259 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006260 if (timeRemaining >= 0) {
6261 lineArgs[0] = Long.toString(timeRemaining);
6262 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6263 (Object[])lineArgs);
6264 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006265 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6266 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006267 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006268 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006269}