blob: 7840ae2dd6d702db87ef95afdc0835d6dc88ca06 [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 /**
Adam Lesinski6832f392015-09-05 18:05:40 -0700696 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a
697 * 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 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003554 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003555 }
3556 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003557
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003558 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3559 for (int isy=syncs.size()-1; isy>=0; isy--) {
3560 final Timer timer = syncs.valueAt(isy);
3561 // Convert from microseconds to milliseconds with rounding
3562 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3563 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003564 final Timer bgTimer = timer.getSubTimer();
3565 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003566 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07003567 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003568 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003569 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003570 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003571 }
3572 }
3573
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003574 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3575 for (int ij=jobs.size()-1; ij>=0; ij--) {
3576 final Timer timer = jobs.valueAt(ij);
3577 // Convert from microseconds to milliseconds with rounding
3578 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3579 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003580 final Timer bgTimer = timer.getSubTimer();
3581 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003582 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07003583 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003584 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003585 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003586 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003587 }
3588 }
3589
Dianne Hackborn94326cb2017-06-28 16:17:20 -07003590 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
3591 for (int ic=completions.size()-1; ic>=0; ic--) {
3592 SparseIntArray types = completions.valueAt(ic);
3593 if (types != null) {
3594 dumpLine(pw, uid, category, JOB_COMPLETION_DATA,
3595 "\"" + completions.keyAt(ic) + "\"",
3596 types.get(JobParameters.REASON_CANCELED, 0),
3597 types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0),
3598 types.get(JobParameters.REASON_PREEMPT, 0),
3599 types.get(JobParameters.REASON_TIMEOUT, 0),
3600 types.get(JobParameters.REASON_DEVICE_IDLE, 0));
3601 }
3602 }
3603
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003604 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3605 rawRealtime, which);
3606 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3607 rawRealtime, which);
3608 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3609 rawRealtime, which);
3610 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3611 rawRealtime, which);
3612
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003613 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3614 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003615 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003616 final Uid.Sensor se = sensors.valueAt(ise);
3617 final int sensorNumber = sensors.keyAt(ise);
3618 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003619 if (timer != null) {
3620 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003621 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3622 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003623 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003624 final int count = timer.getCountLocked(which);
3625 final Timer bgTimer = se.getSensorBackgroundTime();
3626 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003627 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3628 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3629 final long bgActualTime = bgTimer != null ?
3630 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3631 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3632 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003633 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 }
3635 }
3636
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003637 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3638 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003639
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07003640 dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(),
3641 rawRealtime, which);
3642
3643 dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003644 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003645
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003646 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003647 long totalStateTime = 0;
3648 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003649 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3650 totalStateTime += time;
3651 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003652 }
3653 if (totalStateTime > 0) {
3654 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3655 }
3656
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003657 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3658 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003659 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003660 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003661 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003662 }
3663
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003664 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3665 // If total cpuFreqTimes is null, then we don't need to check for screenOffCpuFreqTimes.
3666 if (cpuFreqTimeMs != null) {
3667 sb.setLength(0);
3668 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3669 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
3670 }
3671 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3672 if (screenOffCpuFreqTimeMs != null) {
3673 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3674 sb.append("," + screenOffCpuFreqTimeMs[i]);
3675 }
3676 } else {
3677 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3678 sb.append(",0");
3679 }
3680 }
3681 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
3682 cpuFreqTimeMs.length, sb.toString());
3683 }
3684
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003685 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3686 = u.getProcessStats();
3687 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3688 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003689
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003690 final long userMillis = ps.getUserTime(which);
3691 final long systemMillis = ps.getSystemTime(which);
3692 final long foregroundMillis = ps.getForegroundTime(which);
3693 final int starts = ps.getStarts(which);
3694 final int numCrashes = ps.getNumCrashes(which);
3695 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003696
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003697 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3698 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003699 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
3700 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 }
3702 }
3703
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003704 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3705 = u.getPackageStats();
3706 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3707 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3708 int wakeups = 0;
3709 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3710 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003711 int count = alarms.valueAt(iwa).getCountLocked(which);
3712 wakeups += count;
3713 String name = alarms.keyAt(iwa).replace(',', '_');
3714 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003715 }
3716 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3717 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3718 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3719 final long startTime = ss.getStartTime(batteryUptime, which);
3720 final int starts = ss.getStarts(which);
3721 final int launches = ss.getLaunches(which);
3722 if (startTime != 0 || starts != 0 || launches != 0) {
3723 dumpLine(pw, uid, category, APK_DATA,
3724 wakeups, // wakeup alarms
3725 packageStats.keyAt(ipkg), // Apk
3726 serviceStats.keyAt(isvc), // service
3727 startTime / 1000, // time spent started, in ms
3728 starts,
3729 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003730 }
3731 }
3732 }
3733 }
3734 }
3735
Dianne Hackborn81038902012-11-26 17:04:09 -08003736 static final class TimerEntry {
3737 final String mName;
3738 final int mId;
3739 final BatteryStats.Timer mTimer;
3740 final long mTime;
3741 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3742 mName = name;
3743 mId = id;
3744 mTimer = timer;
3745 mTime = time;
3746 }
3747 }
3748
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003749 private void printmAh(PrintWriter printer, double power) {
3750 printer.print(BatteryStatsHelper.makemAh(power));
3751 }
3752
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003753 private void printmAh(StringBuilder sb, double power) {
3754 sb.append(BatteryStatsHelper.makemAh(power));
3755 }
3756
Dianne Hackbornd953c532014-08-16 18:17:38 -07003757 /**
3758 * Temporary for settings.
3759 */
3760 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3761 int reqUid) {
3762 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3763 }
3764
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003765 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003766 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003767 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003768 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3769 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07003770 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003772
3773 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3774 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3775 final long totalRealtime = computeRealtime(rawRealtime, which);
3776 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003777 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3778 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3779 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003780 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3781 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003782
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003783 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003784
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003785 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003786 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003788 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3789 if (estimatedBatteryCapacity > 0) {
3790 sb.setLength(0);
3791 sb.append(prefix);
3792 sb.append(" Estimated battery capacity: ");
3793 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3794 sb.append(" mAh");
3795 pw.println(sb.toString());
3796 }
3797
Jocelyn Dangc627d102017-04-14 13:15:14 -07003798 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
3799 if (minLearnedBatteryCapacity > 0) {
3800 sb.setLength(0);
3801 sb.append(prefix);
3802 sb.append(" Min learned battery capacity: ");
3803 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
3804 sb.append(" mAh");
3805 pw.println(sb.toString());
3806 }
3807 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
3808 if (maxLearnedBatteryCapacity > 0) {
3809 sb.setLength(0);
3810 sb.append(prefix);
3811 sb.append(" Max learned battery capacity: ");
3812 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
3813 sb.append(" mAh");
3814 pw.println(sb.toString());
3815 }
3816
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003817 sb.setLength(0);
3818 sb.append(prefix);
3819 sb.append(" Time on battery: ");
3820 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3821 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3822 sb.append(") realtime, ");
3823 formatTimeMs(sb, whichBatteryUptime / 1000);
3824 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3825 sb.append(") uptime");
3826 pw.println(sb.toString());
3827 sb.setLength(0);
3828 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003829 sb.append(" Time on battery screen off: ");
3830 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3831 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3832 sb.append(") realtime, ");
3833 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3834 sb.append("(");
3835 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3836 sb.append(") uptime");
3837 pw.println(sb.toString());
3838 sb.setLength(0);
3839 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003840 sb.append(" Total run time: ");
3841 formatTimeMs(sb, totalRealtime / 1000);
3842 sb.append("realtime, ");
3843 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003844 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003845 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003846 if (batteryTimeRemaining >= 0) {
3847 sb.setLength(0);
3848 sb.append(prefix);
3849 sb.append(" Battery time remaining: ");
3850 formatTimeMs(sb, batteryTimeRemaining / 1000);
3851 pw.println(sb.toString());
3852 }
3853 if (chargeTimeRemaining >= 0) {
3854 sb.setLength(0);
3855 sb.append(prefix);
3856 sb.append(" Charge time remaining: ");
3857 formatTimeMs(sb, chargeTimeRemaining / 1000);
3858 pw.println(sb.toString());
3859 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003860
3861 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3862 final long dischargeCount = dischargeCounter.getCountLocked(which);
3863 if (dischargeCount >= 0) {
3864 sb.setLength(0);
3865 sb.append(prefix);
3866 sb.append(" Discharge: ");
3867 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3868 sb.append(" mAh");
3869 pw.println(sb.toString());
3870 }
3871
3872 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3873 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3874 if (dischargeScreenOffCount >= 0) {
3875 sb.setLength(0);
3876 sb.append(prefix);
3877 sb.append(" Screen off discharge: ");
3878 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3879 sb.append(" mAh");
3880 pw.println(sb.toString());
3881 }
3882
3883 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3884 if (dischargeScreenOnCount >= 0) {
3885 sb.setLength(0);
3886 sb.append(prefix);
3887 sb.append(" Screen on discharge: ");
3888 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3889 sb.append(" mAh");
3890 pw.println(sb.toString());
3891 }
3892
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003893 pw.print(" Start clock time: ");
3894 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3895
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003896 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003897 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003898 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003899 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3900 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003901 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003902 rawRealtime, which);
3903 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3904 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003905 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003906 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003907 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3908 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3909 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003910 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003911 sb.append(prefix);
3912 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3913 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003914 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003915 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3916 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003917 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003918 pw.println(sb.toString());
3919 sb.setLength(0);
3920 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003921 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003922 boolean didOne = false;
3923 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003924 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003925 if (time == 0) {
3926 continue;
3927 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003928 sb.append("\n ");
3929 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003930 didOne = true;
3931 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3932 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003933 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003934 sb.append("(");
3935 sb.append(formatRatioLocked(time, screenOnTime));
3936 sb.append(")");
3937 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003938 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003939 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003940 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003941 sb.setLength(0);
3942 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003943 sb.append(" Power save mode enabled: ");
3944 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003945 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003946 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003947 sb.append(")");
3948 pw.println(sb.toString());
3949 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003950 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003951 sb.setLength(0);
3952 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003953 sb.append(" Device light idling: ");
3954 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003955 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003956 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3957 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003958 sb.append("x");
3959 pw.println(sb.toString());
3960 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003961 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003962 sb.setLength(0);
3963 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003964 sb.append(" Idle mode light time: ");
3965 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003966 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003967 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3968 sb.append(") ");
3969 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003970 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003971 sb.append(" -- longest ");
3972 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3973 pw.println(sb.toString());
3974 }
3975 if (deviceIdlingTime != 0) {
3976 sb.setLength(0);
3977 sb.append(prefix);
3978 sb.append(" Device full idling: ");
3979 formatTimeMs(sb, deviceIdlingTime / 1000);
3980 sb.append("(");
3981 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003982 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003983 sb.append("x");
3984 pw.println(sb.toString());
3985 }
3986 if (deviceIdleModeFullTime != 0) {
3987 sb.setLength(0);
3988 sb.append(prefix);
3989 sb.append(" Idle mode full time: ");
3990 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3991 sb.append("(");
3992 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3993 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003994 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003995 sb.append("x");
3996 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003997 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003998 pw.println(sb.toString());
3999 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004000 if (phoneOnTime != 0) {
4001 sb.setLength(0);
4002 sb.append(prefix);
4003 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
4004 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004005 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004006 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004007 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08004008 if (connChanges != 0) {
4009 pw.print(prefix);
4010 pw.print(" Connectivity changes: "); pw.println(connChanges);
4011 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004012
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004013 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07004014 long fullWakeLockTimeTotalMicros = 0;
4015 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08004016
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004017 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08004018
Evan Millar22ac0432009-03-31 11:33:18 -07004019 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004020 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004021
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004022 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4023 = u.getWakelockStats();
4024 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4025 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07004026
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004027 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
4028 if (fullWakeTimer != null) {
4029 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
4030 rawRealtime, which);
4031 }
4032
4033 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4034 if (partialWakeTimer != null) {
4035 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
4036 rawRealtime, which);
4037 if (totalTimeMicros > 0) {
4038 if (reqUid < 0) {
4039 // Only show the ordered list of all wake
4040 // locks if the caller is not asking for data
4041 // about a specific uid.
4042 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
4043 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08004044 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004045 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07004046 }
4047 }
4048 }
4049 }
Bookatzc8c44962017-05-11 12:12:54 -07004050
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004051 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4052 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4053 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4054 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
4055 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4056 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
4057 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4058 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004059 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4060 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004061
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004062 if (fullWakeLockTimeTotalMicros != 0) {
4063 sb.setLength(0);
4064 sb.append(prefix);
4065 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
4066 (fullWakeLockTimeTotalMicros + 500) / 1000);
4067 pw.println(sb.toString());
4068 }
4069
4070 if (partialWakeLockTimeTotalMicros != 0) {
4071 sb.setLength(0);
4072 sb.append(prefix);
4073 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
4074 (partialWakeLockTimeTotalMicros + 500) / 1000);
4075 pw.println(sb.toString());
4076 }
4077
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004078 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004079 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
4080 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
4081 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
4082 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004083 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004084 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004085 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004086 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08004087 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004088 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004089 if (time == 0) {
4090 continue;
4091 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004092 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004093 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004094 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08004095 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004096 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004097 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004098 sb.append("(");
4099 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004100 sb.append(") ");
4101 sb.append(getPhoneSignalStrengthCount(i, which));
4102 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004103 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004104 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004105 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004106
4107 sb.setLength(0);
4108 sb.append(prefix);
4109 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004110 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07004111 pw.println(sb.toString());
4112
Dianne Hackborn627bba72009-03-24 22:32:56 -07004113 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004114 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004115 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004116 didOne = false;
4117 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004118 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004119 if (time == 0) {
4120 continue;
4121 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004122 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004123 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004124 didOne = true;
4125 sb.append(DATA_CONNECTION_NAMES[i]);
4126 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004127 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004128 sb.append("(");
4129 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004130 sb.append(") ");
4131 sb.append(getPhoneDataConnectionCount(i, which));
4132 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004133 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004134 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004135 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004136
4137 sb.setLength(0);
4138 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08004139 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004140 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004141 formatTimeMs(sb, mobileActiveTime / 1000);
4142 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4143 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
4144 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004145 pw.println(sb.toString());
4146
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004147 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
4148 if (mobileActiveUnknownTime != 0) {
4149 sb.setLength(0);
4150 sb.append(prefix);
4151 sb.append(" Mobile radio active unknown time: ");
4152 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
4153 sb.append("(");
4154 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
4155 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
4156 sb.append("x");
4157 pw.println(sb.toString());
4158 }
4159
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004160 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
4161 if (mobileActiveAdjustedTime != 0) {
4162 sb.setLength(0);
4163 sb.append(prefix);
4164 sb.append(" Mobile radio active adjusted time: ");
4165 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
4166 sb.append("(");
4167 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
4168 sb.append(")");
4169 pw.println(sb.toString());
4170 }
4171
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004172 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
4173
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004174 pw.print(prefix);
4175 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
4176 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
4177 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
4178 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004179 sb.setLength(0);
4180 sb.append(prefix);
4181 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
4182 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
4183 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
4184 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004185 sb.append(")");
4186 pw.println(sb.toString());
4187
4188 sb.setLength(0);
4189 sb.append(prefix);
4190 sb.append(" Wifi states:");
4191 didOne = false;
4192 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004193 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004194 if (time == 0) {
4195 continue;
4196 }
4197 sb.append("\n ");
4198 didOne = true;
4199 sb.append(WIFI_STATE_NAMES[i]);
4200 sb.append(" ");
4201 formatTimeMs(sb, time/1000);
4202 sb.append("(");
4203 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4204 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004205 sb.append(getWifiStateCount(i, which));
4206 sb.append("x");
4207 }
4208 if (!didOne) sb.append(" (no activity)");
4209 pw.println(sb.toString());
4210
4211 sb.setLength(0);
4212 sb.append(prefix);
4213 sb.append(" Wifi supplicant states:");
4214 didOne = false;
4215 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4216 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4217 if (time == 0) {
4218 continue;
4219 }
4220 sb.append("\n ");
4221 didOne = true;
4222 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4223 sb.append(" ");
4224 formatTimeMs(sb, time/1000);
4225 sb.append("(");
4226 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4227 sb.append(") ");
4228 sb.append(getWifiSupplStateCount(i, which));
4229 sb.append("x");
4230 }
4231 if (!didOne) sb.append(" (no activity)");
4232 pw.println(sb.toString());
4233
4234 sb.setLength(0);
4235 sb.append(prefix);
4236 sb.append(" Wifi signal levels:");
4237 didOne = false;
4238 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
4239 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4240 if (time == 0) {
4241 continue;
4242 }
4243 sb.append("\n ");
4244 sb.append(prefix);
4245 didOne = true;
4246 sb.append("level(");
4247 sb.append(i);
4248 sb.append(") ");
4249 formatTimeMs(sb, time/1000);
4250 sb.append("(");
4251 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4252 sb.append(") ");
4253 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004254 sb.append("x");
4255 }
4256 if (!didOne) sb.append(" (no activity)");
4257 pw.println(sb.toString());
4258
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004259 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004260
Adam Lesinski50e47602015-12-04 17:04:54 -08004261 pw.print(prefix);
4262 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4263 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4264
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004265 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4266 sb.setLength(0);
4267 sb.append(prefix);
4268 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4269 pw.println(sb.toString());
4270
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004271 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4272 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004273
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004274 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004275
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004276 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004277 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004278 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004279 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004280 pw.println(getDischargeStartLevel());
4281 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4282 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004283 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004284 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004285 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004286 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004287 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004288 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004289 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004290 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4291 pw.println(getDischargeAmountScreenOn());
4292 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4293 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004294 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004295 } else {
4296 pw.print(prefix); pw.println(" Device battery use since last full charge");
4297 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
4298 pw.println(getLowDischargeAmountSinceCharge());
4299 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
4300 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004301 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4302 pw.println(getDischargeAmountScreenOnSinceCharge());
4303 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4304 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004305 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004306 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004307
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004308 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004309 helper.create(this);
4310 helper.refreshStats(which, UserHandle.USER_ALL);
4311 List<BatterySipper> sippers = helper.getUsageList();
4312 if (sippers != null && sippers.size() > 0) {
4313 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4314 pw.print(prefix); pw.print(" Capacity: ");
4315 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004316 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004317 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4318 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4319 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4320 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004321 pw.println();
4322 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004323 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004324 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004325 switch (bs.drainType) {
4326 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004327 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004328 break;
4329 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004330 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004331 break;
4332 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004333 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004334 break;
4335 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004336 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004337 break;
4338 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004339 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004340 break;
4341 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004342 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004343 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004344 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004345 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004346 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004347 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004348 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004349 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004350 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004351 break;
4352 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004353 pw.print(" User "); pw.print(bs.userId);
4354 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004355 break;
4356 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004357 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004358 break;
4359 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004360 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004361 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004362 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004363 pw.print(" Camera: ");
4364 break;
4365 default:
4366 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004367 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004368 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004369 printmAh(pw, bs.totalPowerMah);
4370
Adam Lesinski57123002015-06-12 16:12:07 -07004371 if (bs.usagePowerMah != bs.totalPowerMah) {
4372 // If the usage (generic power) isn't the whole amount, we list out
4373 // what components are involved in the calculation.
4374
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004375 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004376 if (bs.usagePowerMah != 0) {
4377 pw.print(" usage=");
4378 printmAh(pw, bs.usagePowerMah);
4379 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004380 if (bs.cpuPowerMah != 0) {
4381 pw.print(" cpu=");
4382 printmAh(pw, bs.cpuPowerMah);
4383 }
4384 if (bs.wakeLockPowerMah != 0) {
4385 pw.print(" wake=");
4386 printmAh(pw, bs.wakeLockPowerMah);
4387 }
4388 if (bs.mobileRadioPowerMah != 0) {
4389 pw.print(" radio=");
4390 printmAh(pw, bs.mobileRadioPowerMah);
4391 }
4392 if (bs.wifiPowerMah != 0) {
4393 pw.print(" wifi=");
4394 printmAh(pw, bs.wifiPowerMah);
4395 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004396 if (bs.bluetoothPowerMah != 0) {
4397 pw.print(" bt=");
4398 printmAh(pw, bs.bluetoothPowerMah);
4399 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004400 if (bs.gpsPowerMah != 0) {
4401 pw.print(" gps=");
4402 printmAh(pw, bs.gpsPowerMah);
4403 }
4404 if (bs.sensorPowerMah != 0) {
4405 pw.print(" sensor=");
4406 printmAh(pw, bs.sensorPowerMah);
4407 }
4408 if (bs.cameraPowerMah != 0) {
4409 pw.print(" camera=");
4410 printmAh(pw, bs.cameraPowerMah);
4411 }
4412 if (bs.flashlightPowerMah != 0) {
4413 pw.print(" flash=");
4414 printmAh(pw, bs.flashlightPowerMah);
4415 }
4416 pw.print(" )");
4417 }
Bookatz17d7d9d2017-06-08 14:50:46 -07004418
4419 // If there is additional smearing information, include it.
4420 if (bs.totalSmearedPowerMah != bs.totalPowerMah) {
4421 pw.print(" Including smearing: ");
4422 printmAh(pw, bs.totalSmearedPowerMah);
4423 pw.print(" (");
4424 if (bs.screenPowerMah != 0) {
4425 pw.print(" screen=");
4426 printmAh(pw, bs.screenPowerMah);
4427 }
4428 if (bs.proportionalSmearMah != 0) {
4429 pw.print(" proportional=");
4430 printmAh(pw, bs.proportionalSmearMah);
4431 }
4432 pw.print(" )");
4433 }
4434 if (bs.shouldHide) {
4435 pw.print(" Excluded from smearing");
4436 }
4437
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004438 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004439 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004440 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004441 }
4442
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004443 sippers = helper.getMobilemsppList();
4444 if (sippers != null && sippers.size() > 0) {
4445 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004446 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004447 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004448 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004449 sb.setLength(0);
4450 sb.append(prefix); sb.append(" Uid ");
4451 UserHandle.formatUid(sb, bs.uidObj.getUid());
4452 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4453 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4454 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004455 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004456 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004457 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004458 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004459 sb.setLength(0);
4460 sb.append(prefix);
4461 sb.append(" TOTAL TIME: ");
4462 formatTimeMs(sb, totalTime);
4463 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4464 sb.append(")");
4465 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004466 pw.println();
4467 }
4468
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004469 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4470 @Override
4471 public int compare(TimerEntry lhs, TimerEntry rhs) {
4472 long lhsTime = lhs.mTime;
4473 long rhsTime = rhs.mTime;
4474 if (lhsTime < rhsTime) {
4475 return 1;
4476 }
4477 if (lhsTime > rhsTime) {
4478 return -1;
4479 }
4480 return 0;
4481 }
4482 };
4483
4484 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004485 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4486 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004487 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004488 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4489 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4490 : kernelWakelocks.entrySet()) {
4491 final BatteryStats.Timer timer = ent.getValue();
4492 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004493 if (totalTimeMillis > 0) {
4494 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4495 }
4496 }
4497 if (ktimers.size() > 0) {
4498 Collections.sort(ktimers, timerComparator);
4499 pw.print(prefix); pw.println(" All kernel wake locks:");
4500 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004501 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004502 String linePrefix = ": ";
4503 sb.setLength(0);
4504 sb.append(prefix);
4505 sb.append(" Kernel Wake lock ");
4506 sb.append(timer.mName);
4507 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4508 which, linePrefix);
4509 if (!linePrefix.equals(": ")) {
4510 sb.append(" realtime");
4511 // Only print out wake locks that were held
4512 pw.println(sb.toString());
4513 }
4514 }
4515 pw.println();
4516 }
4517 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004518
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004519 if (timers.size() > 0) {
4520 Collections.sort(timers, timerComparator);
4521 pw.print(prefix); pw.println(" All partial wake locks:");
4522 for (int i=0; i<timers.size(); i++) {
4523 TimerEntry timer = timers.get(i);
4524 sb.setLength(0);
4525 sb.append(" Wake lock ");
4526 UserHandle.formatUid(sb, timer.mId);
4527 sb.append(" ");
4528 sb.append(timer.mName);
4529 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4530 sb.append(" realtime");
4531 pw.println(sb.toString());
4532 }
4533 timers.clear();
4534 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004535 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004536
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004537 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004538 if (wakeupReasons.size() > 0) {
4539 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004540 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004541 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004542 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004543 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4544 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004545 }
4546 Collections.sort(reasons, timerComparator);
4547 for (int i=0; i<reasons.size(); i++) {
4548 TimerEntry timer = reasons.get(i);
4549 String linePrefix = ": ";
4550 sb.setLength(0);
4551 sb.append(prefix);
4552 sb.append(" Wakeup reason ");
4553 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004554 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4555 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004556 pw.println(sb.toString());
4557 }
4558 pw.println();
4559 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004560 }
Evan Millar22ac0432009-03-31 11:33:18 -07004561
James Carr2dd7e5e2016-07-20 18:48:39 -07004562 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
4563 pw.println("Memory Stats");
4564 for (int i = 0; i < mMemoryStats.size(); i++) {
4565 sb.setLength(0);
4566 sb.append("Bandwidth ");
4567 sb.append(mMemoryStats.keyAt(i));
4568 sb.append(" Time ");
4569 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4570 pw.println(sb.toString());
4571 }
4572
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004573 final long[] cpuFreqs = getCpuFreqs();
4574 if (cpuFreqs != null) {
4575 sb.setLength(0);
4576 sb.append("CPU freqs:");
4577 for (int i = 0; i < cpuFreqs.length; ++i) {
4578 sb.append(" " + cpuFreqs[i]);
4579 }
4580 pw.println(sb.toString());
4581 }
4582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004583 for (int iu=0; iu<NU; iu++) {
4584 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004585 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004586 continue;
4587 }
Bookatzc8c44962017-05-11 12:12:54 -07004588
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004589 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004590
4591 pw.print(prefix);
4592 pw.print(" ");
4593 UserHandle.formatUid(pw, uid);
4594 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004595 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004596
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004597 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4598 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4599 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4600 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004601 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4602 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4603
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004604 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4605 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004606 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4607 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004608
4609 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4610 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4611
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004612 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4613 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4614 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08004615 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
4616 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4617 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
4618 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004619 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004620
Adam Lesinski5f056f62016-07-14 16:56:08 -07004621 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4622 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4623
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004624 if (mobileRxBytes > 0 || mobileTxBytes > 0
4625 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004626 pw.print(prefix); pw.print(" Mobile network: ");
4627 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004628 pw.print(formatBytesLocked(mobileTxBytes));
4629 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4630 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004631 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004632 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4633 sb.setLength(0);
4634 sb.append(prefix); sb.append(" Mobile radio active: ");
4635 formatTimeMs(sb, uidMobileActiveTime / 1000);
4636 sb.append("(");
4637 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4638 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4639 long packets = mobileRxPackets + mobileTxPackets;
4640 if (packets == 0) {
4641 packets = 1;
4642 }
4643 sb.append(" @ ");
4644 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4645 sb.append(" mspp");
4646 pw.println(sb.toString());
4647 }
4648
Adam Lesinski5f056f62016-07-14 16:56:08 -07004649 if (mobileWakeup > 0) {
4650 sb.setLength(0);
4651 sb.append(prefix);
4652 sb.append(" Mobile radio AP wakeups: ");
4653 sb.append(mobileWakeup);
4654 pw.println(sb.toString());
4655 }
4656
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004657 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4658 u.getModemControllerActivity(), which);
4659
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004660 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004661 pw.print(prefix); pw.print(" Wi-Fi network: ");
4662 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004663 pw.print(formatBytesLocked(wifiTxBytes));
4664 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4665 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004666 }
4667
Dianne Hackborn62793e42015-03-09 11:15:41 -07004668 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08004669 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004670 || uidWifiRunningTime != 0) {
4671 sb.setLength(0);
4672 sb.append(prefix); sb.append(" Wifi Running: ");
4673 formatTimeMs(sb, uidWifiRunningTime / 1000);
4674 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4675 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07004676 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004677 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4678 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4679 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08004680 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004681 formatTimeMs(sb, wifiScanTime / 1000);
4682 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004683 whichBatteryRealtime)); sb.append(") ");
4684 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08004685 sb.append("x\n");
4686 // actual and background times are unpooled and since reset (regardless of 'which')
4687 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
4688 formatTimeMs(sb, wifiScanActualTime / 1000);
4689 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
4690 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4691 sb.append(") ");
4692 sb.append(wifiScanCount);
4693 sb.append("x\n");
4694 sb.append(prefix); sb.append(" Background Wifi Scan: ");
4695 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
4696 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
4697 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4698 sb.append(") ");
4699 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07004700 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004701 pw.println(sb.toString());
4702 }
4703
Adam Lesinski5f056f62016-07-14 16:56:08 -07004704 if (wifiWakeup > 0) {
4705 sb.setLength(0);
4706 sb.append(prefix);
4707 sb.append(" WiFi AP wakeups: ");
4708 sb.append(wifiWakeup);
4709 pw.println(sb.toString());
4710 }
4711
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004712 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4713 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004714
Adam Lesinski50e47602015-12-04 17:04:54 -08004715 if (btRxBytes > 0 || btTxBytes > 0) {
4716 pw.print(prefix); pw.print(" Bluetooth network: ");
4717 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4718 pw.print(formatBytesLocked(btTxBytes));
4719 pw.println(" sent");
4720 }
4721
Bookatz867c0d72017-03-07 18:23:42 -08004722 final Timer bleTimer = u.getBluetoothScanTimer();
4723 if (bleTimer != null) {
4724 // Convert from microseconds to milliseconds with rounding
4725 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
4726 / 1000;
4727 if (totalTimeMs != 0) {
4728 final int count = bleTimer.getCountLocked(which);
4729 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
4730 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004731 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4732 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
4733 final long actualTimeMsBg = bleTimerBg != null ?
4734 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004735 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07004736 final int resultCount = u.getBluetoothScanResultCounter() != null ?
4737 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004738 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
4739 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
4740 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
4741 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
4742 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
4743 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4744 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
4745 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
4746 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
4747 final Timer unoptimizedScanTimerBg =
4748 u.getBluetoothUnoptimizedScanBackgroundTimer();
4749 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
4750 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4751 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
4752 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004753
4754 sb.setLength(0);
Bookatz867c0d72017-03-07 18:23:42 -08004755 if (actualTimeMs != totalTimeMs) {
Bookatzb1f04f32017-05-19 13:57:32 -07004756 sb.append(prefix);
4757 sb.append(" Bluetooth Scan (total blamed realtime): ");
Bookatz867c0d72017-03-07 18:23:42 -08004758 formatTimeMs(sb, totalTimeMs);
Bookatzb1f04f32017-05-19 13:57:32 -07004759 sb.append(" (");
4760 sb.append(count);
4761 sb.append(" times)");
4762 if (bleTimer.isRunningLocked()) {
4763 sb.append(" (currently running)");
4764 }
4765 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08004766 }
Bookatzb1f04f32017-05-19 13:57:32 -07004767
4768 sb.append(prefix);
4769 sb.append(" Bluetooth Scan (total actual realtime): ");
4770 formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which'
4771 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08004772 sb.append(count);
4773 sb.append(" times)");
4774 if (bleTimer.isRunningLocked()) {
Bookatzb1f04f32017-05-19 13:57:32 -07004775 sb.append(" (currently running)");
Bookatz867c0d72017-03-07 18:23:42 -08004776 }
Bookatzb1f04f32017-05-19 13:57:32 -07004777 sb.append("\n");
4778 if (actualTimeMsBg > 0 || countBg > 0) {
4779 sb.append(prefix);
4780 sb.append(" Bluetooth Scan (background realtime): ");
4781 formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which'
4782 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08004783 sb.append(countBg);
4784 sb.append(" times)");
Bookatzb1f04f32017-05-19 13:57:32 -07004785 if (bleTimerBg != null && bleTimerBg.isRunningLocked()) {
4786 sb.append(" (currently running in background)");
4787 }
4788 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08004789 }
Bookatzb1f04f32017-05-19 13:57:32 -07004790
4791 sb.append(prefix);
4792 sb.append(" Bluetooth Scan Results: ");
Bookatz956f36bf2017-04-28 09:48:17 -07004793 sb.append(resultCount);
Bookatzb1f04f32017-05-19 13:57:32 -07004794 sb.append(" (");
4795 sb.append(resultCountBg);
4796 sb.append(" in background)");
4797
4798 if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) {
4799 sb.append("\n");
4800 sb.append(prefix);
4801 sb.append(" Unoptimized Bluetooth Scan (realtime): ");
4802 formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which'
4803 sb.append(" (max ");
4804 formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which'
4805 sb.append(")");
4806 if (unoptimizedScanTimer != null
4807 && unoptimizedScanTimer.isRunningLocked()) {
4808 sb.append(" (currently running unoptimized)");
4809 }
4810 if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) {
4811 sb.append("\n");
4812 sb.append(prefix);
4813 sb.append(" Unoptimized Bluetooth Scan (background realtime): ");
4814 formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset
4815 sb.append(" (max ");
4816 formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset
4817 sb.append(")");
4818 if (unoptimizedScanTimerBg.isRunningLocked()) {
4819 sb.append(" (currently running unoptimized in background)");
4820 }
4821 }
4822 }
Bookatz867c0d72017-03-07 18:23:42 -08004823 pw.println(sb.toString());
4824 uidActivity = true;
4825 }
4826 }
4827
4828
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004829
Dianne Hackborn617f8772009-03-31 15:04:46 -07004830 if (u.hasUserActivity()) {
4831 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004832 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004833 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004834 if (val != 0) {
4835 if (!hasData) {
4836 sb.setLength(0);
4837 sb.append(" User activity: ");
4838 hasData = true;
4839 } else {
4840 sb.append(", ");
4841 }
4842 sb.append(val);
4843 sb.append(" ");
4844 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4845 }
4846 }
4847 if (hasData) {
4848 pw.println(sb.toString());
4849 }
4850 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004851
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004852 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4853 = u.getWakelockStats();
4854 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004855 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004856 int countWakelock = 0;
4857 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4858 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4859 String linePrefix = ": ";
4860 sb.setLength(0);
4861 sb.append(prefix);
4862 sb.append(" Wake lock ");
4863 sb.append(wakelocks.keyAt(iw));
4864 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4865 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004866 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4867 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004868 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004869 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
4870 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004871 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4872 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004873 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4874 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004875 sb.append(" realtime");
4876 pw.println(sb.toString());
4877 uidActivity = true;
4878 countWakelock++;
4879
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004880 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4881 rawRealtime, which);
4882 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4883 rawRealtime, which);
4884 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4885 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004886 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004887 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004888 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004889 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07004890 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
4891 // pooled and therefore just a lower bound)
4892 long actualTotalPartialWakelock = 0;
4893 long actualBgPartialWakelock = 0;
4894 if (u.getAggregatedPartialWakelockTimer() != null) {
4895 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
4896 // Convert from microseconds to milliseconds with rounding
4897 actualTotalPartialWakelock =
Bookatz6d799932017-06-07 12:30:07 -07004898 aggTimer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07004899 final Timer bgAggTimer = aggTimer.getSubTimer();
4900 actualBgPartialWakelock = bgAggTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004901 bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07004902 }
4903
4904 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
4905 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
4906 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004907 sb.setLength(0);
4908 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004909 sb.append(" TOTAL wake: ");
4910 boolean needComma = false;
4911 if (totalFullWakelock != 0) {
4912 needComma = true;
4913 formatTimeMs(sb, totalFullWakelock);
4914 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004915 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004916 if (totalPartialWakelock != 0) {
4917 if (needComma) {
4918 sb.append(", ");
4919 }
4920 needComma = true;
4921 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07004922 sb.append("blamed partial");
4923 }
4924 if (actualTotalPartialWakelock != 0) {
4925 if (needComma) {
4926 sb.append(", ");
4927 }
4928 needComma = true;
4929 formatTimeMs(sb, actualTotalPartialWakelock);
4930 sb.append("actual partial");
4931 }
4932 if (actualBgPartialWakelock != 0) {
4933 if (needComma) {
4934 sb.append(", ");
4935 }
4936 needComma = true;
4937 formatTimeMs(sb, actualBgPartialWakelock);
4938 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004939 }
4940 if (totalWindowWakelock != 0) {
4941 if (needComma) {
4942 sb.append(", ");
4943 }
4944 needComma = true;
4945 formatTimeMs(sb, totalWindowWakelock);
4946 sb.append("window");
4947 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004948 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004949 if (needComma) {
4950 sb.append(",");
4951 }
4952 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004953 formatTimeMs(sb, totalDrawWakelock);
4954 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004955 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004956 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004957 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004958 }
4959 }
4960
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004961 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4962 for (int isy=syncs.size()-1; isy>=0; isy--) {
4963 final Timer timer = syncs.valueAt(isy);
4964 // Convert from microseconds to milliseconds with rounding
4965 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4966 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07004967 final Timer bgTimer = timer.getSubTimer();
4968 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07004969 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07004970 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004971 sb.setLength(0);
4972 sb.append(prefix);
4973 sb.append(" Sync ");
4974 sb.append(syncs.keyAt(isy));
4975 sb.append(": ");
4976 if (totalTime != 0) {
4977 formatTimeMs(sb, totalTime);
4978 sb.append("realtime (");
4979 sb.append(count);
4980 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07004981 if (bgTime > 0) {
4982 sb.append(", ");
4983 formatTimeMs(sb, bgTime);
4984 sb.append("background (");
4985 sb.append(bgCount);
4986 sb.append(" times)");
4987 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004988 } else {
4989 sb.append("(not used)");
4990 }
4991 pw.println(sb.toString());
4992 uidActivity = true;
4993 }
4994
4995 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4996 for (int ij=jobs.size()-1; ij>=0; ij--) {
4997 final Timer timer = jobs.valueAt(ij);
4998 // Convert from microseconds to milliseconds with rounding
4999 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5000 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07005001 final Timer bgTimer = timer.getSubTimer();
5002 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005003 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07005004 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005005 sb.setLength(0);
5006 sb.append(prefix);
5007 sb.append(" Job ");
5008 sb.append(jobs.keyAt(ij));
5009 sb.append(": ");
5010 if (totalTime != 0) {
5011 formatTimeMs(sb, totalTime);
5012 sb.append("realtime (");
5013 sb.append(count);
5014 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07005015 if (bgTime > 0) {
5016 sb.append(", ");
5017 formatTimeMs(sb, bgTime);
5018 sb.append("background (");
5019 sb.append(bgCount);
5020 sb.append(" times)");
5021 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005022 } else {
5023 sb.append("(not used)");
5024 }
5025 pw.println(sb.toString());
5026 uidActivity = true;
5027 }
5028
Dianne Hackborn94326cb2017-06-28 16:17:20 -07005029 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
5030 for (int ic=completions.size()-1; ic>=0; ic--) {
5031 SparseIntArray types = completions.valueAt(ic);
5032 if (types != null) {
5033 pw.print(prefix);
5034 pw.print(" Job Completions ");
5035 pw.print(completions.keyAt(ic));
5036 pw.print(":");
5037 for (int it=0; it<types.size(); it++) {
5038 pw.print(" ");
5039 pw.print(JobParameters.getReasonName(types.keyAt(it)));
5040 pw.print("(");
5041 pw.print(types.valueAt(it));
5042 pw.print("x)");
5043 }
5044 pw.println();
5045 }
5046 }
5047
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005048 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
5049 prefix, "Flashlight");
5050 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
5051 prefix, "Camera");
5052 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
5053 prefix, "Video");
5054 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
5055 prefix, "Audio");
5056
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005057 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
5058 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005059 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005060 final Uid.Sensor se = sensors.valueAt(ise);
5061 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005062 sb.setLength(0);
5063 sb.append(prefix);
5064 sb.append(" Sensor ");
5065 int handle = se.getHandle();
5066 if (handle == Uid.Sensor.GPS) {
5067 sb.append("GPS");
5068 } else {
5069 sb.append(handle);
5070 }
5071 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005072
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005073 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005074 if (timer != null) {
5075 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08005076 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
5077 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005078 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08005079 final Timer bgTimer = se.getSensorBackgroundTime();
5080 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005081 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5082 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
5083 final long bgActualTime = bgTimer != null ?
5084 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5085
Dianne Hackborn61659e52014-07-09 16:13:01 -07005086 //timer.logState();
5087 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08005088 if (actualTime != totalTime) {
5089 formatTimeMs(sb, totalTime);
5090 sb.append("blamed realtime, ");
5091 }
5092
5093 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07005094 sb.append("realtime (");
5095 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08005096 sb.append(" times)");
5097
5098 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005099 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08005100 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
5101 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005102 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08005103 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005104 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005105 } else {
5106 sb.append("(not used)");
5107 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005108 } else {
5109 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005110 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005111
5112 pw.println(sb.toString());
5113 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005114 }
5115
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005116 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
5117 "Vibrator");
5118 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
5119 prefix, "Foreground activities");
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07005120 uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which,
5121 prefix, "Foreground services");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07005122
Dianne Hackborn61659e52014-07-09 16:13:01 -07005123 long totalStateTime = 0;
5124 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
5125 long time = u.getProcessStateTime(ips, rawRealtime, which);
5126 if (time > 0) {
5127 totalStateTime += time;
5128 sb.setLength(0);
5129 sb.append(prefix);
5130 sb.append(" ");
5131 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
5132 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08005133 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005134 pw.println(sb.toString());
5135 uidActivity = true;
5136 }
5137 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08005138 if (totalStateTime > 0) {
5139 sb.setLength(0);
5140 sb.append(prefix);
5141 sb.append(" Total running: ");
5142 formatTimeMs(sb, (totalStateTime + 500) / 1000);
5143 pw.println(sb.toString());
5144 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005145
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005146 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
5147 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07005148 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005149 sb.setLength(0);
5150 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07005151 sb.append(" Total cpu time: u=");
5152 formatTimeMs(sb, userCpuTimeUs / 1000);
5153 sb.append("s=");
5154 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005155 pw.println(sb.toString());
5156 }
5157
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005158 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
5159 if (cpuFreqTimes != null) {
5160 sb.setLength(0);
5161 sb.append(" Total cpu time per freq:");
5162 for (int i = 0; i < cpuFreqTimes.length; ++i) {
5163 sb.append(" " + cpuFreqTimes[i]);
5164 }
5165 pw.println(sb.toString());
5166 }
5167 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
5168 if (screenOffCpuFreqTimes != null) {
5169 sb.setLength(0);
5170 sb.append(" Total screen-off cpu time per freq:");
5171 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
5172 sb.append(" " + screenOffCpuFreqTimes[i]);
5173 }
5174 pw.println(sb.toString());
5175 }
5176
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005177 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
5178 = u.getProcessStats();
5179 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
5180 final Uid.Proc ps = processStats.valueAt(ipr);
5181 long userTime;
5182 long systemTime;
5183 long foregroundTime;
5184 int starts;
5185 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005186
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005187 userTime = ps.getUserTime(which);
5188 systemTime = ps.getSystemTime(which);
5189 foregroundTime = ps.getForegroundTime(which);
5190 starts = ps.getStarts(which);
5191 final int numCrashes = ps.getNumCrashes(which);
5192 final int numAnrs = ps.getNumAnrs(which);
5193 numExcessive = which == STATS_SINCE_CHARGED
5194 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005195
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005196 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5197 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5198 sb.setLength(0);
5199 sb.append(prefix); sb.append(" Proc ");
5200 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5201 sb.append(prefix); sb.append(" CPU: ");
5202 formatTimeMs(sb, userTime); sb.append("usr + ");
5203 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5204 formatTimeMs(sb, foregroundTime); sb.append("fg");
5205 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5206 sb.append("\n"); sb.append(prefix); sb.append(" ");
5207 boolean hasOne = false;
5208 if (starts != 0) {
5209 hasOne = true;
5210 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005211 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005212 if (numCrashes != 0) {
5213 if (hasOne) {
5214 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005215 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005216 hasOne = true;
5217 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005218 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005219 if (numAnrs != 0) {
5220 if (hasOne) {
5221 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005222 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005223 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005224 }
5225 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005226 pw.println(sb.toString());
5227 for (int e=0; e<numExcessive; e++) {
5228 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5229 if (ew != null) {
5230 pw.print(prefix); pw.print(" * Killed for ");
Dianne Hackbornffca58b2017-05-24 16:15:45 -07005231 if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005232 pw.print("cpu");
5233 } else {
5234 pw.print("unknown");
5235 }
5236 pw.print(" use: ");
5237 TimeUtils.formatDuration(ew.usedTime, pw);
5238 pw.print(" over ");
5239 TimeUtils.formatDuration(ew.overTime, pw);
5240 if (ew.overTime != 0) {
5241 pw.print(" (");
5242 pw.print((ew.usedTime*100)/ew.overTime);
5243 pw.println("%)");
5244 }
5245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005246 }
5247 uidActivity = true;
5248 }
5249 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005250
5251 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5252 = u.getPackageStats();
5253 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5254 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5255 pw.println(":");
5256 boolean apkActivity = false;
5257 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5258 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5259 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5260 pw.print(prefix); pw.print(" Wakeup alarm ");
5261 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5262 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5263 pw.println(" times");
5264 apkActivity = true;
5265 }
5266 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5267 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5268 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5269 final long startTime = ss.getStartTime(batteryUptime, which);
5270 final int starts = ss.getStarts(which);
5271 final int launches = ss.getLaunches(which);
5272 if (startTime != 0 || starts != 0 || launches != 0) {
5273 sb.setLength(0);
5274 sb.append(prefix); sb.append(" Service ");
5275 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5276 sb.append(prefix); sb.append(" Created for: ");
5277 formatTimeMs(sb, startTime / 1000);
5278 sb.append("uptime\n");
5279 sb.append(prefix); sb.append(" Starts: ");
5280 sb.append(starts);
5281 sb.append(", launches: "); sb.append(launches);
5282 pw.println(sb.toString());
5283 apkActivity = true;
5284 }
5285 }
5286 if (!apkActivity) {
5287 pw.print(prefix); pw.println(" (nothing executed)");
5288 }
5289 uidActivity = true;
5290 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005291 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005292 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005293 }
5294 }
5295 }
5296
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005297 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005298 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005299 int diff = oldval ^ newval;
5300 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005301 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005302 for (int i=0; i<descriptions.length; i++) {
5303 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005304 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005305 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005306 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005307 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005308 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005309 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5310 didWake = true;
5311 pw.print("=");
5312 if (longNames) {
5313 UserHandle.formatUid(pw, wakelockTag.uid);
5314 pw.print(":\"");
5315 pw.print(wakelockTag.string);
5316 pw.print("\"");
5317 } else {
5318 pw.print(wakelockTag.poolIdx);
5319 }
5320 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005321 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005322 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005323 pw.print("=");
5324 int val = (newval&bd.mask)>>bd.shift;
5325 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005326 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005327 } else {
5328 pw.print(val);
5329 }
5330 }
5331 }
5332 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005333 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005334 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005335 if (longNames) {
5336 UserHandle.formatUid(pw, wakelockTag.uid);
5337 pw.print(":\"");
5338 pw.print(wakelockTag.string);
5339 pw.print("\"");
5340 } else {
5341 pw.print(wakelockTag.poolIdx);
5342 }
5343 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005344 }
5345
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005346 public void prepareForDumpLocked() {
5347 }
5348
5349 public static class HistoryPrinter {
5350 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005351 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005352 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005353 int oldStatus = -1;
5354 int oldHealth = -1;
5355 int oldPlug = -1;
5356 int oldTemp = -1;
5357 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005358 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005359 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005360
Dianne Hackborn3251b902014-06-20 14:40:53 -07005361 void reset() {
5362 oldState = oldState2 = 0;
5363 oldLevel = -1;
5364 oldStatus = -1;
5365 oldHealth = -1;
5366 oldPlug = -1;
5367 oldTemp = -1;
5368 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005369 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005370 }
5371
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005372 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005373 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005374 if (!checkin) {
5375 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005376 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005377 pw.print(" (");
5378 pw.print(rec.numReadInts);
5379 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005380 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005381 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5382 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005383 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005384 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005385 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005386 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005387 }
5388 lastTime = rec.time;
5389 }
5390 if (rec.cmd == HistoryItem.CMD_START) {
5391 if (checkin) {
5392 pw.print(":");
5393 }
5394 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005395 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005396 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5397 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005398 if (checkin) {
5399 pw.print(":");
5400 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005401 if (rec.cmd == HistoryItem.CMD_RESET) {
5402 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005403 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005404 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005405 pw.print("TIME:");
5406 if (checkin) {
5407 pw.println(rec.currentTime);
5408 } else {
5409 pw.print(" ");
5410 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5411 rec.currentTime).toString());
5412 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005413 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5414 if (checkin) {
5415 pw.print(":");
5416 }
5417 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005418 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5419 if (checkin) {
5420 pw.print(":");
5421 }
5422 pw.println("*OVERFLOW*");
5423 } else {
5424 if (!checkin) {
5425 if (rec.batteryLevel < 10) pw.print("00");
5426 else if (rec.batteryLevel < 100) pw.print("0");
5427 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005428 if (verbose) {
5429 pw.print(" ");
5430 if (rec.states < 0) ;
5431 else if (rec.states < 0x10) pw.print("0000000");
5432 else if (rec.states < 0x100) pw.print("000000");
5433 else if (rec.states < 0x1000) pw.print("00000");
5434 else if (rec.states < 0x10000) pw.print("0000");
5435 else if (rec.states < 0x100000) pw.print("000");
5436 else if (rec.states < 0x1000000) pw.print("00");
5437 else if (rec.states < 0x10000000) pw.print("0");
5438 pw.print(Integer.toHexString(rec.states));
5439 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005440 } else {
5441 if (oldLevel != rec.batteryLevel) {
5442 oldLevel = rec.batteryLevel;
5443 pw.print(",Bl="); pw.print(rec.batteryLevel);
5444 }
5445 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005446 if (oldStatus != rec.batteryStatus) {
5447 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005448 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005449 switch (oldStatus) {
5450 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005451 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005452 break;
5453 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005454 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005455 break;
5456 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005457 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005458 break;
5459 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005460 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005461 break;
5462 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005463 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005464 break;
5465 default:
5466 pw.print(oldStatus);
5467 break;
5468 }
5469 }
5470 if (oldHealth != rec.batteryHealth) {
5471 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005472 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005473 switch (oldHealth) {
5474 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005475 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005476 break;
5477 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005478 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005479 break;
5480 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005481 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005482 break;
5483 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005484 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005485 break;
5486 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005487 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005488 break;
5489 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005490 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005491 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005492 case BatteryManager.BATTERY_HEALTH_COLD:
5493 pw.print(checkin ? "c" : "cold");
5494 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005495 default:
5496 pw.print(oldHealth);
5497 break;
5498 }
5499 }
5500 if (oldPlug != rec.batteryPlugType) {
5501 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005502 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005503 switch (oldPlug) {
5504 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005505 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005506 break;
5507 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005508 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005509 break;
5510 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005511 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005512 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005513 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005514 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005515 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005516 default:
5517 pw.print(oldPlug);
5518 break;
5519 }
5520 }
5521 if (oldTemp != rec.batteryTemperature) {
5522 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005523 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005524 pw.print(oldTemp);
5525 }
5526 if (oldVolt != rec.batteryVoltage) {
5527 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005528 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005529 pw.print(oldVolt);
5530 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005531 final int chargeMAh = rec.batteryChargeUAh / 1000;
5532 if (oldChargeMAh != chargeMAh) {
5533 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005534 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005535 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005536 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005537 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005538 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005539 printBitDescriptions(pw, oldState2, rec.states2, null,
5540 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005541 if (rec.wakeReasonTag != null) {
5542 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005543 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005544 pw.print(rec.wakeReasonTag.poolIdx);
5545 } else {
5546 pw.print(" wake_reason=");
5547 pw.print(rec.wakeReasonTag.uid);
5548 pw.print(":\"");
5549 pw.print(rec.wakeReasonTag.string);
5550 pw.print("\"");
5551 }
5552 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005553 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005554 pw.print(checkin ? "," : " ");
5555 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5556 pw.print("+");
5557 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5558 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005559 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005560 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
5561 : HISTORY_EVENT_NAMES;
5562 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
5563 | HistoryItem.EVENT_FLAG_FINISH);
5564 if (idx >= 0 && idx < eventNames.length) {
5565 pw.print(eventNames[idx]);
5566 } else {
5567 pw.print(checkin ? "Ev" : "event");
5568 pw.print(idx);
5569 }
5570 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005571 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005572 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08005573 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08005574 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
5575 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005576 pw.print(":\"");
5577 pw.print(rec.eventTag.string);
5578 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005579 }
5580 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005581 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005582 if (rec.stepDetails != null) {
5583 if (!checkin) {
5584 pw.print(" Details: cpu=");
5585 pw.print(rec.stepDetails.userTime);
5586 pw.print("u+");
5587 pw.print(rec.stepDetails.systemTime);
5588 pw.print("s");
5589 if (rec.stepDetails.appCpuUid1 >= 0) {
5590 pw.print(" (");
5591 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
5592 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5593 if (rec.stepDetails.appCpuUid2 >= 0) {
5594 pw.print(", ");
5595 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
5596 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5597 }
5598 if (rec.stepDetails.appCpuUid3 >= 0) {
5599 pw.print(", ");
5600 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
5601 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5602 }
5603 pw.print(')');
5604 }
5605 pw.println();
5606 pw.print(" /proc/stat=");
5607 pw.print(rec.stepDetails.statUserTime);
5608 pw.print(" usr, ");
5609 pw.print(rec.stepDetails.statSystemTime);
5610 pw.print(" sys, ");
5611 pw.print(rec.stepDetails.statIOWaitTime);
5612 pw.print(" io, ");
5613 pw.print(rec.stepDetails.statIrqTime);
5614 pw.print(" irq, ");
5615 pw.print(rec.stepDetails.statSoftIrqTime);
5616 pw.print(" sirq, ");
5617 pw.print(rec.stepDetails.statIdlTime);
5618 pw.print(" idle");
5619 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
5620 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
5621 + rec.stepDetails.statSoftIrqTime;
5622 int total = totalRun + rec.stepDetails.statIdlTime;
5623 if (total > 0) {
5624 pw.print(" (");
5625 float perc = ((float)totalRun) / ((float)total) * 100;
5626 pw.print(String.format("%.1f%%", perc));
5627 pw.print(" of ");
5628 StringBuilder sb = new StringBuilder(64);
5629 formatTimeMsNoSpace(sb, total*10);
5630 pw.print(sb);
5631 pw.print(")");
5632 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005633 pw.print(", PlatformIdleStat ");
5634 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005635 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005636
5637 pw.print(", SubsystemPowerState ");
5638 pw.print(rec.stepDetails.statSubsystemPowerState);
5639 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005640 } else {
5641 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5642 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
5643 pw.print(rec.stepDetails.userTime);
5644 pw.print(":");
5645 pw.print(rec.stepDetails.systemTime);
5646 if (rec.stepDetails.appCpuUid1 >= 0) {
5647 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
5648 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5649 if (rec.stepDetails.appCpuUid2 >= 0) {
5650 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
5651 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5652 }
5653 if (rec.stepDetails.appCpuUid3 >= 0) {
5654 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
5655 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5656 }
5657 }
5658 pw.println();
5659 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5660 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
5661 pw.print(rec.stepDetails.statUserTime);
5662 pw.print(',');
5663 pw.print(rec.stepDetails.statSystemTime);
5664 pw.print(',');
5665 pw.print(rec.stepDetails.statIOWaitTime);
5666 pw.print(',');
5667 pw.print(rec.stepDetails.statIrqTime);
5668 pw.print(',');
5669 pw.print(rec.stepDetails.statSoftIrqTime);
5670 pw.print(',');
5671 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005672 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005673 if (rec.stepDetails.statPlatformIdleState != null) {
5674 pw.print(rec.stepDetails.statPlatformIdleState);
Ahmed ElArabawy307edcd2017-07-07 17:48:13 -07005675 if (rec.stepDetails.statSubsystemPowerState != null) {
5676 pw.print(',');
5677 }
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005678 }
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005679
5680 if (rec.stepDetails.statSubsystemPowerState != null) {
5681 pw.print(rec.stepDetails.statSubsystemPowerState);
5682 }
5683 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005684 }
5685 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005686 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005687 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005688 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005689 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005690
5691 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
5692 UserHandle.formatUid(pw, uid);
5693 pw.print("=");
5694 pw.print(utime);
5695 pw.print("u+");
5696 pw.print(stime);
5697 pw.print("s");
5698 }
5699
5700 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5701 pw.print('/');
5702 pw.print(uid);
5703 pw.print(":");
5704 pw.print(utime);
5705 pw.print(":");
5706 pw.print(stime);
5707 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005708 }
5709
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005710 private void printSizeValue(PrintWriter pw, long size) {
5711 float result = size;
5712 String suffix = "";
5713 if (result >= 10*1024) {
5714 suffix = "KB";
5715 result = result / 1024;
5716 }
5717 if (result >= 10*1024) {
5718 suffix = "MB";
5719 result = result / 1024;
5720 }
5721 if (result >= 10*1024) {
5722 suffix = "GB";
5723 result = result / 1024;
5724 }
5725 if (result >= 10*1024) {
5726 suffix = "TB";
5727 result = result / 1024;
5728 }
5729 if (result >= 10*1024) {
5730 suffix = "PB";
5731 result = result / 1024;
5732 }
5733 pw.print((int)result);
5734 pw.print(suffix);
5735 }
5736
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005737 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5738 String label3, long estimatedTime) {
5739 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005740 return false;
5741 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005742 pw.print(label1);
5743 pw.print(label2);
5744 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005745 StringBuilder sb = new StringBuilder(64);
5746 formatTimeMs(sb, estimatedTime);
5747 pw.print(sb);
5748 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005749 return true;
5750 }
5751
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005752 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5753 LevelStepTracker steps, boolean checkin) {
5754 if (steps == null) {
5755 return false;
5756 }
5757 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005758 if (count <= 0) {
5759 return false;
5760 }
5761 if (!checkin) {
5762 pw.println(header);
5763 }
Kweku Adams030980a2015-04-01 16:07:48 -07005764 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005765 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005766 long duration = steps.getDurationAt(i);
5767 int level = steps.getLevelAt(i);
5768 long initMode = steps.getInitModeAt(i);
5769 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005770 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005771 lineArgs[0] = Long.toString(duration);
5772 lineArgs[1] = Integer.toString(level);
5773 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5774 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5775 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5776 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5777 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5778 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005779 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005780 }
5781 } else {
5782 lineArgs[2] = "";
5783 }
5784 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5785 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5786 } else {
5787 lineArgs[3] = "";
5788 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005789 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005790 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005791 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005792 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005793 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005794 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5795 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005796 pw.print(prefix);
5797 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005798 TimeUtils.formatDuration(duration, pw);
5799 pw.print(" to "); pw.print(level);
5800 boolean haveModes = false;
5801 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5802 pw.print(" (");
5803 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5804 case Display.STATE_OFF: pw.print("screen-off"); break;
5805 case Display.STATE_ON: pw.print("screen-on"); break;
5806 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5807 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005808 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005809 }
5810 haveModes = true;
5811 }
5812 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5813 pw.print(haveModes ? ", " : " (");
5814 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5815 ? "power-save-on" : "power-save-off");
5816 haveModes = true;
5817 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005818 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5819 pw.print(haveModes ? ", " : " (");
5820 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5821 ? "device-idle-on" : "device-idle-off");
5822 haveModes = true;
5823 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005824 if (haveModes) {
5825 pw.print(")");
5826 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005827 pw.println();
5828 }
5829 }
5830 return true;
5831 }
5832
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005833 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005834 public static final int DUMP_DAILY_ONLY = 1<<2;
5835 public static final int DUMP_HISTORY_ONLY = 1<<3;
5836 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5837 public static final int DUMP_VERBOSE = 1<<5;
5838 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005839
Dianne Hackborn37de0982014-05-09 09:32:18 -07005840 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5841 final HistoryPrinter hprinter = new HistoryPrinter();
5842 final HistoryItem rec = new HistoryItem();
5843 long lastTime = -1;
5844 long baseTime = -1;
5845 boolean printed = false;
5846 HistoryEventTracker tracker = null;
5847 while (getNextHistoryLocked(rec)) {
5848 lastTime = rec.time;
5849 if (baseTime < 0) {
5850 baseTime = lastTime;
5851 }
5852 if (rec.time >= histStart) {
5853 if (histStart >= 0 && !printed) {
5854 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005855 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005856 || rec.cmd == HistoryItem.CMD_START
5857 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005858 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005859 hprinter.printNextItem(pw, rec, baseTime, checkin,
5860 (flags&DUMP_VERBOSE) != 0);
5861 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005862 } else if (rec.currentTime != 0) {
5863 printed = true;
5864 byte cmd = rec.cmd;
5865 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005866 hprinter.printNextItem(pw, rec, baseTime, checkin,
5867 (flags&DUMP_VERBOSE) != 0);
5868 rec.cmd = cmd;
5869 }
5870 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005871 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5872 hprinter.printNextItem(pw, rec, baseTime, checkin,
5873 (flags&DUMP_VERBOSE) != 0);
5874 rec.cmd = HistoryItem.CMD_UPDATE;
5875 }
5876 int oldEventCode = rec.eventCode;
5877 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005878 rec.eventTag = new HistoryTag();
5879 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5880 HashMap<String, SparseIntArray> active
5881 = tracker.getStateForEvent(i);
5882 if (active == null) {
5883 continue;
5884 }
5885 for (HashMap.Entry<String, SparseIntArray> ent
5886 : active.entrySet()) {
5887 SparseIntArray uids = ent.getValue();
5888 for (int j=0; j<uids.size(); j++) {
5889 rec.eventCode = i;
5890 rec.eventTag.string = ent.getKey();
5891 rec.eventTag.uid = uids.keyAt(j);
5892 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005893 hprinter.printNextItem(pw, rec, baseTime, checkin,
5894 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005895 rec.wakeReasonTag = null;
5896 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005897 }
5898 }
5899 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005900 rec.eventCode = oldEventCode;
5901 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005902 tracker = null;
5903 }
5904 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005905 hprinter.printNextItem(pw, rec, baseTime, checkin,
5906 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005907 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5908 // This is an attempt to aggregate the previous state and generate
5909 // fake events to reflect that state at the point where we start
5910 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005911 if (tracker == null) {
5912 tracker = new HistoryEventTracker();
5913 }
5914 tracker.updateState(rec.eventCode, rec.eventTag.string,
5915 rec.eventTag.uid, rec.eventTag.poolIdx);
5916 }
5917 }
5918 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005919 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005920 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5921 }
5922 }
5923
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005924 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5925 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5926 if (steps == null) {
5927 return;
5928 }
5929 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5930 if (timeRemaining >= 0) {
5931 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5932 tmpSb.setLength(0);
5933 formatTimeMs(tmpSb, timeRemaining);
5934 pw.print(tmpSb);
5935 pw.print(" (from "); pw.print(tmpOutInt[0]);
5936 pw.println(" steps)");
5937 }
5938 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5939 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5940 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5941 if (estimatedTime > 0) {
5942 pw.print(prefix); pw.print(label); pw.print(" ");
5943 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5944 pw.print(" time: ");
5945 tmpSb.setLength(0);
5946 formatTimeMs(tmpSb, estimatedTime);
5947 pw.print(tmpSb);
5948 pw.print(" (from "); pw.print(tmpOutInt[0]);
5949 pw.println(" steps)");
5950 }
5951 }
5952 }
5953
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005954 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5955 ArrayList<PackageChange> changes) {
5956 if (changes == null) {
5957 return;
5958 }
5959 pw.print(prefix); pw.println("Package changes:");
5960 for (int i=0; i<changes.size(); i++) {
5961 PackageChange pc = changes.get(i);
5962 if (pc.mUpdate) {
5963 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5964 pw.print(" vers="); pw.println(pc.mVersionCode);
5965 } else {
5966 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5967 }
5968 }
5969 }
5970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005971 /**
5972 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5973 *
5974 * @param pw a Printer to receive the dump output.
5975 */
5976 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005977 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005978 prepareForDumpLocked();
5979
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005980 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005981 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005982
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005983 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005984 final long historyTotalSize = getHistoryTotalSize();
5985 final long historyUsedSize = getHistoryUsedSize();
5986 if (startIteratingHistoryLocked()) {
5987 try {
5988 pw.print("Battery History (");
5989 pw.print((100*historyUsedSize)/historyTotalSize);
5990 pw.print("% used, ");
5991 printSizeValue(pw, historyUsedSize);
5992 pw.print(" used of ");
5993 printSizeValue(pw, historyTotalSize);
5994 pw.print(", ");
5995 pw.print(getHistoryStringPoolSize());
5996 pw.print(" strings using ");
5997 printSizeValue(pw, getHistoryStringPoolBytes());
5998 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005999 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006000 pw.println();
6001 } finally {
6002 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006003 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006004 }
6005
6006 if (startIteratingOldHistoryLocked()) {
6007 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006008 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006009 pw.println("Old battery History:");
6010 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006011 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006012 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006013 if (baseTime < 0) {
6014 baseTime = rec.time;
6015 }
6016 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006017 }
6018 pw.println();
6019 } finally {
6020 finishIteratingOldHistoryLocked();
6021 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07006022 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006023 }
6024
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006025 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006026 return;
6027 }
6028
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006029 if (!filtering) {
6030 SparseArray<? extends Uid> uidStats = getUidStats();
6031 final int NU = uidStats.size();
6032 boolean didPid = false;
6033 long nowRealtime = SystemClock.elapsedRealtime();
6034 for (int i=0; i<NU; i++) {
6035 Uid uid = uidStats.valueAt(i);
6036 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
6037 if (pids != null) {
6038 for (int j=0; j<pids.size(); j++) {
6039 Uid.Pid pid = pids.valueAt(j);
6040 if (!didPid) {
6041 pw.println("Per-PID Stats:");
6042 didPid = true;
6043 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006044 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
6045 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006046 pw.print(" PID "); pw.print(pids.keyAt(j));
6047 pw.print(" wake time: ");
6048 TimeUtils.formatDuration(time, pw);
6049 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006050 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006051 }
6052 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006053 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006054 pw.println();
6055 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006056 }
6057
6058 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006059 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
6060 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006061 long timeRemaining = computeBatteryTimeRemaining(
6062 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006063 if (timeRemaining >= 0) {
6064 pw.print(" Estimated discharge time remaining: ");
6065 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6066 pw.println();
6067 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006068 final LevelStepTracker steps = getDischargeLevelStepTracker();
6069 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6070 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
6071 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6072 STEP_LEVEL_MODE_VALUES[i], null));
6073 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006074 pw.println();
6075 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006076 if (dumpDurationSteps(pw, " ", "Charge step durations:",
6077 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006078 long timeRemaining = computeChargeTimeRemaining(
6079 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006080 if (timeRemaining >= 0) {
6081 pw.print(" Estimated charge time remaining: ");
6082 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6083 pw.println();
6084 }
6085 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006086 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006087 }
6088 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
6089 pw.println("Daily stats:");
6090 pw.print(" Current start time: ");
6091 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6092 getCurrentDailyStartTime()).toString());
6093 pw.print(" Next min deadline: ");
6094 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6095 getNextMinDailyDeadline()).toString());
6096 pw.print(" Next max deadline: ");
6097 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6098 getNextMaxDailyDeadline()).toString());
6099 StringBuilder sb = new StringBuilder(64);
6100 int[] outInt = new int[1];
6101 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
6102 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006103 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
6104 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006105 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006106 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
6107 dsteps, false)) {
6108 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6109 sb, outInt);
6110 }
6111 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
6112 csteps, false)) {
6113 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6114 sb, outInt);
6115 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006116 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006117 } else {
6118 pw.println(" Current daily steps:");
6119 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6120 sb, outInt);
6121 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6122 sb, outInt);
6123 }
6124 }
6125 DailyItem dit;
6126 int curIndex = 0;
6127 while ((dit=getDailyItemLocked(curIndex)) != null) {
6128 curIndex++;
6129 if ((flags&DUMP_DAILY_ONLY) != 0) {
6130 pw.println();
6131 }
6132 pw.print(" Daily from ");
6133 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
6134 pw.print(" to ");
6135 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
6136 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006137 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006138 if (dumpDurationSteps(pw, " ",
6139 " Discharge step durations:", dit.mDischargeSteps, false)) {
6140 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6141 sb, outInt);
6142 }
6143 if (dumpDurationSteps(pw, " ",
6144 " Charge step durations:", dit.mChargeSteps, false)) {
6145 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6146 sb, outInt);
6147 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006148 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006149 } else {
6150 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6151 sb, outInt);
6152 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6153 sb, outInt);
6154 }
6155 }
6156 pw.println();
6157 }
6158 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006159 pw.println("Statistics since last charge:");
6160 pw.println(" System starts: " + getStartCount()
6161 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07006162 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
6163 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006164 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006165 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006166 }
6167
6168 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006169 public void dumpCheckinLocked(Context context, PrintWriter pw,
6170 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006171 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006172
6173 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07006174 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
6175 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006176
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006177 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6178
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006179 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006180 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006181
6182 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07006183 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006184 try {
6185 for (int i=0; i<getHistoryStringPoolSize(); i++) {
6186 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6187 pw.print(HISTORY_STRING_POOL); pw.print(',');
6188 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006189 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006190 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006191 pw.print(",\"");
6192 String str = getHistoryTagPoolString(i);
6193 str = str.replace("\\", "\\\\");
6194 str = str.replace("\"", "\\\"");
6195 pw.print(str);
6196 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006197 pw.println();
6198 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006199 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006200 } finally {
6201 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006202 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006203 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006204 }
6205
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006206 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006207 return;
6208 }
6209
Dianne Hackborne4a59512010-12-07 11:08:07 -08006210 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006211 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006212 for (int i=0; i<apps.size(); i++) {
6213 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006214 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6215 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006216 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006217 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6218 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006219 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006220 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006221 }
6222 SparseArray<? extends Uid> uidStats = getUidStats();
6223 final int NU = uidStats.size();
6224 String[] lineArgs = new String[2];
6225 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006226 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6227 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6228 if (pkgs != null && !pkgs.second.value) {
6229 pkgs.second.value = true;
6230 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006231 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006232 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006233 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6234 (Object[])lineArgs);
6235 }
6236 }
6237 }
6238 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006239 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006240 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006241 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006242 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006243 if (timeRemaining >= 0) {
6244 lineArgs[0] = Long.toString(timeRemaining);
6245 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6246 (Object[])lineArgs);
6247 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006248 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006249 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006250 if (timeRemaining >= 0) {
6251 lineArgs[0] = Long.toString(timeRemaining);
6252 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6253 (Object[])lineArgs);
6254 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006255 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6256 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006257 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006259}