blob: bf0a264b49edf33dc0cd65b901e88681816170ec [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;
Bookatz82b341172017-09-07 19:06:08 -070056 /** Fetching RPM stats is too slow to do each time screen changes, so disable it. */
57 protected static final boolean SCREEN_OFF_RPM_STATS_ENABLED = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070058
59 /** @hide */
60 public static final String SERVICE_NAME = "batterystats";
61
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 /**
63 * A constant indicating a partial wake lock timer.
64 */
65 public static final int WAKE_TYPE_PARTIAL = 0;
66
67 /**
68 * A constant indicating a full wake lock timer.
69 */
70 public static final int WAKE_TYPE_FULL = 1;
71
72 /**
73 * A constant indicating a window wake lock timer.
74 */
75 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 /**
78 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 */
80 public static final int SENSOR = 3;
Mike Mac2f518a2017-09-19 16:06:03 -070081
The Android Open Source Project10592532009-03-18 17:39:46 -070082 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070083 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070084 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070085 public static final int WIFI_RUNNING = 4;
Mike Mac2f518a2017-09-19 16:06:03 -070086
Dianne Hackborn617f8772009-03-31 15:04:46 -070087 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070088 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070089 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070090 public static final int FULL_WIFI_LOCK = 5;
Mike Mac2f518a2017-09-19 16:06:03 -070091
The Android Open Source Project10592532009-03-18 17:39:46 -070092 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070093 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070094 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070095 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096
Dianne Hackborn62793e42015-03-09 11:15:41 -070097 /**
98 * A constant indicating a wifi multicast timer
99 */
100 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700103 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700104 */
105 public static final int VIDEO_TURNED_ON = 8;
106
107 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800108 * A constant indicating a vibrator on timer
109 */
110 public static final int VIBRATOR_ON = 9;
111
112 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700113 * A constant indicating a foreground activity timer
114 */
115 public static final int FOREGROUND_ACTIVITY = 10;
116
117 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700118 * A constant indicating a wifi batched scan is active
119 */
120 public static final int WIFI_BATCHED_SCAN = 11;
121
122 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700123 * A constant indicating a process state timer
124 */
125 public static final int PROCESS_STATE = 12;
126
127 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700128 * A constant indicating a sync timer
129 */
130 public static final int SYNC = 13;
131
132 /**
133 * A constant indicating a job timer
134 */
135 public static final int JOB = 14;
136
137 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800138 * A constant indicating an audio turn on timer
139 */
140 public static final int AUDIO_TURNED_ON = 15;
141
142 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700143 * A constant indicating a flashlight turn on timer
144 */
145 public static final int FLASHLIGHT_TURNED_ON = 16;
146
147 /**
148 * A constant indicating a camera turn on timer
149 */
150 public static final int CAMERA_TURNED_ON = 17;
151
152 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700153 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700154 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700155 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700156
157 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800158 * A constant indicating a bluetooth scan timer.
159 */
160 public static final int BLUETOOTH_SCAN_ON = 19;
161
162 /**
Bookatzc8c44962017-05-11 12:12:54 -0700163 * A constant indicating an aggregated partial wake lock timer.
164 */
165 public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20;
166
167 /**
Bookatzb1f04f32017-05-19 13:57:32 -0700168 * A constant indicating a bluetooth scan timer for unoptimized scans.
169 */
170 public static final int BLUETOOTH_UNOPTIMIZED_SCAN_ON = 21;
171
172 /**
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700173 * A constant indicating a foreground service timer
174 */
175 public static final int FOREGROUND_SERVICE = 22;
176
177 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 * Include all of the data in the stats, including previously saved data.
179 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700180 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181
182 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 * Include only the current run in the stats.
184 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700185 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186
187 /**
188 * Include only the run since the last time the device was unplugged in the stats.
189 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700190 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700191
192 // NOTE: Update this list if you add/change any stats above.
193 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700194 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700195 private static final String[] STAT_NAMES = { "l", "c", "u" };
196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700198 * Current version of checkin data format.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700199 *
200 * New in version 19:
201 * - Wakelock data (wl) gets current and max times.
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800202 * New in version 20:
Bookatz2bffb5b2017-04-13 11:59:33 -0700203 * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs.
Bookatz506a8182017-05-01 14:18:42 -0700204 * New in version 21:
205 * - Actual (not just apportioned) Wakelock time is also recorded.
Bookatzc8c44962017-05-11 12:12:54 -0700206 * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded.
Bookatzb1f04f32017-05-19 13:57:32 -0700207 * - BLE scan result count
208 * - CPU frequency time per uid
209 * New in version 22:
210 * - BLE scan result background count, BLE unoptimized scan time
Bookatz98d4d5c2017-08-01 19:07:54 -0700211 * - Background partial wakelock time & count
212 * New in version 23:
213 * - Logging smeared power model values
214 * New in version 24:
215 * - Fixed bugs in background timers and BLE scan time
216 * New in version 25:
217 * - Package wakeup alarms are now on screen-off timebase
Bookatz50df7112017-08-04 14:53:26 -0700218 * New in version 26:
Bookatz82b341172017-09-07 19:06:08 -0700219 * - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly]
Mike Mac2f518a2017-09-19 16:06:03 -0700220 * New in version 27:
221 * - Always On Display (screen doze mode) time and power
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700222 */
Mike Mac2f518a2017-09-19 16:06:03 -0700223 static final String CHECKIN_VERSION = "27";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700224
225 /**
226 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700228 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700229
Evan Millar22ac0432009-03-31 11:33:18 -0700230 private static final long BYTES_PER_KB = 1024;
231 private static final long BYTES_PER_MB = 1048576; // 1024^2
232 private static final long BYTES_PER_GB = 1073741824; //1024^3
Bookatz506a8182017-05-01 14:18:42 -0700233
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700234 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800235 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700236 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700238 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700239 private static final String CPU_DATA = "cpu";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700240 private static final String GLOBAL_CPU_FREQ_DATA = "gcf";
241 private static final String CPU_TIMES_AT_FREQ_DATA = "ctf";
Bookatz50df7112017-08-04 14:53:26 -0700242 // rpm line is:
243 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "rpm", state/voter name, total time, total count,
244 // screen-off time, screen-off count
245 private static final String RESOURCE_POWER_MANAGER_DATA = "rpm";
Evan Millare84de8d2009-04-02 22:16:12 -0700246 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800247 private static final String VIBRATOR_DATA = "vib";
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700248 private static final String FOREGROUND_ACTIVITY_DATA = "fg";
249 // fgs line is:
250 // BATTERY_STATS_CHECKIN_VERSION, uid, category, "fgs",
251 // foreground service time, count
252 private static final String FOREGROUND_SERVICE_DATA = "fgs";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700253 private static final String STATE_TIME_DATA = "st";
Bookatz506a8182017-05-01 14:18:42 -0700254 // wl line is:
255 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
Bookatz5b5ec322017-05-26 09:40:38 -0700256 // full totalTime, 'f', count, current duration, max duration, total duration,
257 // partial totalTime, 'p', count, current duration, max duration, total duration,
258 // bg partial totalTime, 'bp', count, current duration, max duration, total duration,
259 // window totalTime, 'w', count, current duration, max duration, total duration
Bookatz506a8182017-05-01 14:18:42 -0700260 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700261 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700262 // awl line is:
263 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
264 // cumulative partial wakelock duration, cumulative background partial wakelock duration
265 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700266 private static final String SYNC_DATA = "sy";
267 private static final String JOB_DATA = "jb";
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700268 private static final String JOB_COMPLETION_DATA = "jbc";
Evan Millarc64edde2009-04-18 12:26:32 -0700269 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700270 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700271 private static final String NETWORK_DATA = "nt";
272 private static final String USER_ACTIVITY_DATA = "ua";
273 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800274 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700275 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700276 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700277 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800278 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
279 private static final String WIFI_CONTROLLER_DATA = "wfcd";
280 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
281 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700282 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700283 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800284 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800285 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
286 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800287 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700288 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700289 private static final String SCREEN_BRIGHTNESS_DATA = "br";
290 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700291 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700292 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
293 private static final String DATA_CONNECTION_TIME_DATA = "dct";
294 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800295 private static final String WIFI_STATE_TIME_DATA = "wst";
296 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700297 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
298 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
299 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
300 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800301 private static final String POWER_USE_SUMMARY_DATA = "pws";
302 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700303 private static final String DISCHARGE_STEP_DATA = "dsd";
304 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700305 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
306 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700307 private static final String FLASHLIGHT_DATA = "fla";
308 private static final String CAMERA_DATA = "cam";
309 private static final String VIDEO_DATA = "vid";
310 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311
Adam Lesinski010bf372016-04-11 12:18:18 -0700312 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
313
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700314 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 private final Formatter mFormatter = new Formatter(mFormatBuilder);
316
317 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700318 * Indicates times spent by the uid at each cpu frequency in all process states.
319 *
320 * Other types might include times spent in foreground, background etc.
321 */
322 private final String UID_TIMES_TYPE_ALL = "A";
323
324 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700325 * State for keeping track of counting information.
326 */
327 public static abstract class Counter {
328
329 /**
330 * Returns the count associated with this Counter for the
331 * selected type of statistics.
332 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700333 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700334 */
Evan Millarc64edde2009-04-18 12:26:32 -0700335 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700336
337 /**
338 * Temporary for debugging.
339 */
340 public abstract void logState(Printer pw, String prefix);
341 }
342
343 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700344 * State for keeping track of long counting information.
345 */
346 public static abstract class LongCounter {
347
348 /**
349 * Returns the count associated with this Counter for the
350 * selected type of statistics.
351 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700352 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700353 */
354 public abstract long getCountLocked(int which);
355
356 /**
357 * Temporary for debugging.
358 */
359 public abstract void logState(Printer pw, String prefix);
360 }
361
362 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700363 * State for keeping track of array of long counting information.
364 */
365 public static abstract class LongCounterArray {
366 /**
367 * Returns the counts associated with this Counter for the
368 * selected type of statistics.
369 *
370 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
371 */
372 public abstract long[] getCountsLocked(int which);
373
374 /**
375 * Temporary for debugging.
376 */
377 public abstract void logState(Printer pw, String prefix);
378 }
379
380 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800381 * Container class that aggregates counters for transmit, receive, and idle state of a
382 * radio controller.
383 */
384 public static abstract class ControllerActivityCounter {
385 /**
386 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
387 * idle state.
388 */
389 public abstract LongCounter getIdleTimeCounter();
390
391 /**
392 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
393 * receive state.
394 */
395 public abstract LongCounter getRxTimeCounter();
396
397 /**
398 * An array of {@link LongCounter}, representing various transmit levels, where each level
399 * may draw a different amount of power. The levels themselves are controller-specific.
400 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
401 * various transmit level states.
402 */
403 public abstract LongCounter[] getTxTimeCounters();
404
405 /**
406 * @return a non-null {@link LongCounter} representing the power consumed by the controller
407 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
408 * yield a value of 0 if the device doesn't support power calculations.
409 */
410 public abstract LongCounter getPowerCounter();
411 }
412
413 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 * State for keeping track of timing information.
415 */
416 public static abstract class Timer {
417
418 /**
419 * Returns the count associated with this Timer for the
420 * selected type of statistics.
421 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700422 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 */
Evan Millarc64edde2009-04-18 12:26:32 -0700424 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425
426 /**
427 * Returns the total time in microseconds associated with this Timer for the
428 * selected type of statistics.
429 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800430 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700431 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 * @return a time in microseconds
433 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800434 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700437 * Returns the total time in microseconds associated with this Timer since the
438 * 'mark' was last set.
439 *
440 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
441 * @return a time in microseconds
442 */
443 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
444
445 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700446 * Returns the max duration if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800447 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700448
449 */
450 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
451 return -1;
452 }
453
454 /**
455 * Returns the current time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800456 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700457 */
458 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
459 return -1;
460 }
461
462 /**
Bookatz867c0d72017-03-07 18:23:42 -0800463 * Returns the current time the timer has been active, if it is being tracked.
464 *
465 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
466 * been on since reset.
467 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
468 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
469 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
470 * the actual total time.
471 * Not all Timer subclasses track the max, total, current durations.
472 */
473 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
474 return -1;
475 }
476
477 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700478 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
479 * used, for example, for tracking background usage. Secondary timers are never pooled.
480 *
481 * Not all Timer subclasses have a secondary timer; those that don't return null.
482 */
483 public Timer getSubTimer() {
484 return null;
485 }
486
487 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700488 * Returns whether the timer is currently running. Some types of timers
489 * (e.g. BatchTimers) don't know whether the event is currently active,
490 * and report false.
491 */
492 public boolean isRunningLocked() {
493 return false;
494 }
495
496 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 * Temporary for debugging.
498 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700499 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 }
501
502 /**
503 * The statistics associated with a particular uid.
504 */
505 public static abstract class Uid {
506
507 /**
508 * Returns a mapping containing wakelock statistics.
509 *
510 * @return a Map from Strings to Uid.Wakelock objects.
511 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700512 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513
514 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700515 * Returns a mapping containing sync statistics.
516 *
517 * @return a Map from Strings to Timer objects.
518 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700519 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700520
521 /**
522 * Returns a mapping containing scheduled job statistics.
523 *
524 * @return a Map from Strings to Timer objects.
525 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700526 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700527
528 /**
Dianne Hackborn94326cb2017-06-28 16:17:20 -0700529 * Returns statistics about how jobs have completed.
530 *
531 * @return A Map of String job names to completion type -> count mapping.
532 */
533 public abstract ArrayMap<String, SparseIntArray> getJobCompletionStats();
534
535 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 * The statistics associated with a particular wake lock.
537 */
538 public static abstract class Wakelock {
539 public abstract Timer getWakeTime(int type);
540 }
541
542 /**
Bookatzc8c44962017-05-11 12:12:54 -0700543 * The cumulative time the uid spent holding any partial wakelocks. This will generally
544 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
545 * wakelocks that overlap in time (and therefore over-counts).
546 */
547 public abstract Timer getAggregatedPartialWakelockTimer();
548
549 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 * Returns a mapping containing sensor statistics.
551 *
552 * @return a Map from Integer sensor ids to Uid.Sensor objects.
553 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700554 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555
556 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700557 * Returns a mapping containing active process data.
558 */
559 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700560
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700561 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 * Returns a mapping containing process statistics.
563 *
564 * @return a Map from Strings to Uid.Proc objects.
565 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700566 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567
568 /**
569 * Returns a mapping containing package statistics.
570 *
571 * @return a Map from Strings to Uid.Pkg objects.
572 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700573 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700574
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800575 public abstract ControllerActivityCounter getWifiControllerActivity();
576 public abstract ControllerActivityCounter getBluetoothControllerActivity();
577 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800578
579 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 * {@hide}
581 */
582 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700583
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800584 public abstract void noteWifiRunningLocked(long elapsedRealtime);
585 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
586 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
587 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
588 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
589 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
590 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
591 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
592 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
593 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800594 public abstract void noteActivityResumedLocked(long elapsedRealtime);
595 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800596 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
597 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
598 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700599 public abstract int getWifiScanCount(int which);
Bookatz867c0d72017-03-07 18:23:42 -0800600 public abstract int getWifiScanBackgroundCount(int which);
601 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
602 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800603 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700604 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800605 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700606 public abstract Timer getAudioTurnedOnTimer();
607 public abstract Timer getVideoTurnedOnTimer();
608 public abstract Timer getFlashlightTurnedOnTimer();
609 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700610 public abstract Timer getForegroundActivityTimer();
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -0700611
612 /**
613 * Returns the timer keeping track of Foreground Service time
614 */
615 public abstract Timer getForegroundServiceTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800616 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800617 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatzb1f04f32017-05-19 13:57:32 -0700618 public abstract Timer getBluetoothUnoptimizedScanTimer();
619 public abstract Timer getBluetoothUnoptimizedScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700620 public abstract Counter getBluetoothScanResultCounter();
Bookatzb1f04f32017-05-19 13:57:32 -0700621 public abstract Counter getBluetoothScanResultBgCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700622
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700623 public abstract long[] getCpuFreqTimes(int which);
624 public abstract long[] getScreenOffCpuFreqTimes(int which);
625
Dianne Hackborna0200e32016-03-30 18:01:41 -0700626 // Note: the following times are disjoint. They can be added together to find the
627 // total time a uid has had any processes running at all.
628
629 /**
630 * Time this uid has any processes in the top state (or above such as persistent).
631 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800632 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700633 /**
634 * Time this uid has any process with a started out bound foreground service, but
635 * none in the "top" state.
636 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800637 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700638 /**
639 * Time this uid has any process that is top while the device is sleeping, but none
640 * in the "foreground service" or better state.
641 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800642 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700643 /**
644 * Time this uid has any process in an active foreground state, but none in the
645 * "top sleeping" or better state.
646 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800647 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700648 /**
649 * Time this uid has any process in an active background state, but none in the
650 * "foreground" or better state.
651 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800652 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700653 /**
654 * Time this uid has any processes that are sitting around cached, not in one of the
655 * other active states.
656 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800657 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700658 /**
659 * Total number of process states we track.
660 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800661 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700662
663 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800664 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700665 };
666
667 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800668 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700669
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800670 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671
Robert Greenwalta029ea12013-09-25 16:38:12 -0700672 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
673
Dianne Hackborn617f8772009-03-31 15:04:46 -0700674 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700675 * Note that these must match the constants in android.os.PowerManager.
676 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
677 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700678 */
679 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700680 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700681 };
Bookatzc8c44962017-05-11 12:12:54 -0700682
Phil Weaverda80d672016-03-15 16:25:46 -0700683 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700684
Dianne Hackborn617f8772009-03-31 15:04:46 -0700685 public abstract void noteUserActivityLocked(int type);
686 public abstract boolean hasUserActivity();
687 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700688
689 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800690 public abstract long getNetworkActivityBytes(int type, int which);
691 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800692 public abstract long getMobileRadioActiveTime(int which);
693 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700694
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700695 /**
696 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
697 */
698 public abstract long getUserCpuTimeUs(int which);
699
700 /**
701 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
702 */
703 public abstract long getSystemCpuTimeUs(int which);
704
705 /**
Sudheer Shanka71f34b32017-07-21 00:14:24 -0700706 * Returns the approximate cpu time (in microseconds) spent at a certain CPU speed for a
Adam Lesinski6832f392015-09-05 18:05:40 -0700707 * given CPU cluster.
708 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700709 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700710 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700711 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
712 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700713 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700714 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700715
Adam Lesinski5f056f62016-07-14 16:56:08 -0700716 /**
717 * Returns the number of times this UID woke up the Application Processor to
718 * process a mobile radio packet.
719 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
720 */
721 public abstract long getMobileRadioApWakeupCount(int which);
722
723 /**
724 * Returns the number of times this UID woke up the Application Processor to
725 * process a WiFi packet.
726 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
727 */
728 public abstract long getWifiRadioApWakeupCount(int which);
729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800731 /*
732 * FIXME: it's not correct to use this magic value because it
733 * could clash with a sensor handle (which are defined by
734 * the sensor HAL, and therefore out of our control
735 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 // Magic sensor number for the GPS.
737 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800742
Bookatz867c0d72017-03-07 18:23:42 -0800743 /** Returns a Timer for sensor usage when app is in the background. */
744 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 }
746
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700747 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800748 public int mWakeNesting;
749 public long mWakeSumMs;
750 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700751 }
752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 /**
754 * The statistics associated with a particular process.
755 */
756 public static abstract class Proc {
757
Dianne Hackborn287952c2010-09-22 22:34:31 -0700758 public static class ExcessivePower {
759 public static final int TYPE_WAKE = 1;
760 public static final int TYPE_CPU = 2;
761
762 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700763 public long overTime;
764 public long usedTime;
765 }
766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800768 * Returns true if this process is still active in the battery stats.
769 */
770 public abstract boolean isActive();
771
772 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700773 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700775 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 */
777 public abstract long getUserTime(int which);
778
779 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700780 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700782 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 */
784 public abstract long getSystemTime(int which);
785
786 /**
787 * Returns the number of times the process has been started.
788 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700789 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 */
791 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700792
793 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800794 * Returns the number of times the process has crashed.
795 *
796 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
797 */
798 public abstract int getNumCrashes(int which);
799
800 /**
801 * Returns the number of times the process has ANRed.
802 *
803 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
804 */
805 public abstract int getNumAnrs(int which);
806
807 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700808 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700809 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700810 * @return foreground cpu time in microseconds
811 */
812 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700813
Dianne Hackborn287952c2010-09-22 22:34:31 -0700814 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700815
Dianne Hackborn287952c2010-09-22 22:34:31 -0700816 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 }
818
819 /**
820 * The statistics associated with a particular package.
821 */
822 public static abstract class Pkg {
823
824 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700825 * Returns information about all wakeup alarms that have been triggered for this
826 * package. The mapping keys are tag names for the alarms, the counter contains
827 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700829 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830
831 /**
832 * Returns a mapping containing service statistics.
833 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700834 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835
836 /**
837 * The statistics associated with a particular service.
838 */
Joe Onoratoabded112016-02-08 16:49:39 -0800839 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840
841 /**
842 * Returns the amount of time spent started.
843 *
844 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700845 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 * @return
847 */
848 public abstract long getStartTime(long batteryUptime, int which);
849
850 /**
851 * Returns the total number of times startService() has been called.
852 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700853 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 */
855 public abstract int getStarts(int which);
856
857 /**
858 * Returns the total number times the service has been launched.
859 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700860 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 */
862 public abstract int getLaunches(int which);
863 }
864 }
865 }
866
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800867 public static final class LevelStepTracker {
868 public long mLastStepTime = -1;
869 public int mNumStepDurations;
870 public final long[] mStepDurations;
871
872 public LevelStepTracker(int maxLevelSteps) {
873 mStepDurations = new long[maxLevelSteps];
874 }
875
876 public LevelStepTracker(int numSteps, long[] steps) {
877 mNumStepDurations = numSteps;
878 mStepDurations = new long[numSteps];
879 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
880 }
881
882 public long getDurationAt(int index) {
883 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
884 }
885
886 public int getLevelAt(int index) {
887 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
888 >> STEP_LEVEL_LEVEL_SHIFT);
889 }
890
891 public int getInitModeAt(int index) {
892 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
893 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
894 }
895
896 public int getModModeAt(int index) {
897 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
898 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
899 }
900
901 private void appendHex(long val, int topOffset, StringBuilder out) {
902 boolean hasData = false;
903 while (topOffset >= 0) {
904 int digit = (int)( (val>>topOffset) & 0xf );
905 topOffset -= 4;
906 if (!hasData && digit == 0) {
907 continue;
908 }
909 hasData = true;
910 if (digit >= 0 && digit <= 9) {
911 out.append((char)('0' + digit));
912 } else {
913 out.append((char)('a' + digit - 10));
914 }
915 }
916 }
917
918 public void encodeEntryAt(int index, StringBuilder out) {
919 long item = mStepDurations[index];
920 long duration = item & STEP_LEVEL_TIME_MASK;
921 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
922 >> STEP_LEVEL_LEVEL_SHIFT);
923 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
924 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
925 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
926 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
927 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
928 case Display.STATE_OFF: out.append('f'); break;
929 case Display.STATE_ON: out.append('o'); break;
930 case Display.STATE_DOZE: out.append('d'); break;
931 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
932 }
933 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
934 out.append('p');
935 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700936 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
937 out.append('i');
938 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800939 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
940 case Display.STATE_OFF: out.append('F'); break;
941 case Display.STATE_ON: out.append('O'); break;
942 case Display.STATE_DOZE: out.append('D'); break;
943 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
944 }
945 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
946 out.append('P');
947 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700948 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
949 out.append('I');
950 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800951 out.append('-');
952 appendHex(level, 4, out);
953 out.append('-');
954 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
955 }
956
957 public void decodeEntryAt(int index, String value) {
958 final int N = value.length();
959 int i = 0;
960 char c;
961 long out = 0;
962 while (i < N && (c=value.charAt(i)) != '-') {
963 i++;
964 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800965 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800966 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800967 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800968 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800969 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800970 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800971 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
972 << STEP_LEVEL_INITIAL_MODE_SHIFT);
973 break;
974 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
975 << STEP_LEVEL_INITIAL_MODE_SHIFT);
976 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700977 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
978 << STEP_LEVEL_INITIAL_MODE_SHIFT);
979 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800980 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
981 break;
982 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
983 break;
984 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
985 break;
986 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
987 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
988 break;
989 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
990 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800991 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700992 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
993 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
994 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800995 }
996 }
997 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800998 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800999 while (i < N && (c=value.charAt(i)) != '-') {
1000 i++;
1001 level <<= 4;
1002 if (c >= '0' && c <= '9') {
1003 level += c - '0';
1004 } else if (c >= 'a' && c <= 'f') {
1005 level += c - 'a' + 10;
1006 } else if (c >= 'A' && c <= 'F') {
1007 level += c - 'A' + 10;
1008 }
1009 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -08001010 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001011 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
1012 long duration = 0;
1013 while (i < N && (c=value.charAt(i)) != '-') {
1014 i++;
1015 duration <<= 4;
1016 if (c >= '0' && c <= '9') {
1017 duration += c - '0';
1018 } else if (c >= 'a' && c <= 'f') {
1019 duration += c - 'a' + 10;
1020 } else if (c >= 'A' && c <= 'F') {
1021 duration += c - 'A' + 10;
1022 }
1023 }
1024 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
1025 }
1026
1027 public void init() {
1028 mLastStepTime = -1;
1029 mNumStepDurations = 0;
1030 }
1031
1032 public void clearTime() {
1033 mLastStepTime = -1;
1034 }
1035
1036 public long computeTimePerLevel() {
1037 final long[] steps = mStepDurations;
1038 final int numSteps = mNumStepDurations;
1039
1040 // For now we'll do a simple average across all steps.
1041 if (numSteps <= 0) {
1042 return -1;
1043 }
1044 long total = 0;
1045 for (int i=0; i<numSteps; i++) {
1046 total += steps[i] & STEP_LEVEL_TIME_MASK;
1047 }
1048 return total / numSteps;
1049 /*
1050 long[] buckets = new long[numSteps];
1051 int numBuckets = 0;
1052 int numToAverage = 4;
1053 int i = 0;
1054 while (i < numSteps) {
1055 long totalTime = 0;
1056 int num = 0;
1057 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1058 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1059 num++;
1060 }
1061 buckets[numBuckets] = totalTime / num;
1062 numBuckets++;
1063 numToAverage *= 2;
1064 i += num;
1065 }
1066 if (numBuckets < 1) {
1067 return -1;
1068 }
1069 long averageTime = buckets[numBuckets-1];
1070 for (i=numBuckets-2; i>=0; i--) {
1071 averageTime = (averageTime + buckets[i]) / 2;
1072 }
1073 return averageTime;
1074 */
1075 }
1076
1077 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1078 int[] outNumOfInterest) {
1079 final long[] steps = mStepDurations;
1080 final int count = mNumStepDurations;
1081 if (count <= 0) {
1082 return -1;
1083 }
1084 long total = 0;
1085 int numOfInterest = 0;
1086 for (int i=0; i<count; i++) {
1087 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1088 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1089 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1090 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1091 // If the modes of interest didn't change during this step period...
1092 if ((modMode&modesOfInterest) == 0) {
1093 // And the mode values during this period match those we are measuring...
1094 if ((initMode&modesOfInterest) == modeValues) {
1095 // Then this can be used to estimate the total time!
1096 numOfInterest++;
1097 total += steps[i] & STEP_LEVEL_TIME_MASK;
1098 }
1099 }
1100 }
1101 if (numOfInterest <= 0) {
1102 return -1;
1103 }
1104
1105 if (outNumOfInterest != null) {
1106 outNumOfInterest[0] = numOfInterest;
1107 }
1108
1109 // The estimated time is the average time we spend in each level, multipled
1110 // by 100 -- the total number of battery levels
1111 return (total / numOfInterest) * 100;
1112 }
1113
1114 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1115 int stepCount = mNumStepDurations;
1116 final long lastStepTime = mLastStepTime;
1117 if (lastStepTime >= 0 && numStepLevels > 0) {
1118 final long[] steps = mStepDurations;
1119 long duration = elapsedRealtime - lastStepTime;
1120 for (int i=0; i<numStepLevels; i++) {
1121 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1122 long thisDuration = duration / (numStepLevels-i);
1123 duration -= thisDuration;
1124 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1125 thisDuration = STEP_LEVEL_TIME_MASK;
1126 }
1127 steps[0] = thisDuration | modeBits;
1128 }
1129 stepCount += numStepLevels;
1130 if (stepCount > steps.length) {
1131 stepCount = steps.length;
1132 }
1133 }
1134 mNumStepDurations = stepCount;
1135 mLastStepTime = elapsedRealtime;
1136 }
1137
1138 public void readFromParcel(Parcel in) {
1139 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001140 if (N > mStepDurations.length) {
1141 throw new ParcelFormatException("more step durations than available: " + N);
1142 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001143 mNumStepDurations = N;
1144 for (int i=0; i<N; i++) {
1145 mStepDurations[i] = in.readLong();
1146 }
1147 }
1148
1149 public void writeToParcel(Parcel out) {
1150 final int N = mNumStepDurations;
1151 out.writeInt(N);
1152 for (int i=0; i<N; i++) {
1153 out.writeLong(mStepDurations[i]);
1154 }
1155 }
1156 }
1157
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001158 public static final class PackageChange {
1159 public String mPackageName;
1160 public boolean mUpdate;
1161 public int mVersionCode;
1162 }
1163
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001164 public static final class DailyItem {
1165 public long mStartTime;
1166 public long mEndTime;
1167 public LevelStepTracker mDischargeSteps;
1168 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001169 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001170 }
1171
1172 public abstract DailyItem getDailyItemLocked(int daysAgo);
1173
1174 public abstract long getCurrentDailyStartTime();
1175
1176 public abstract long getNextMinDailyDeadline();
1177
1178 public abstract long getNextMaxDailyDeadline();
1179
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001180 public abstract long[] getCpuFreqs();
1181
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001182 public final static class HistoryTag {
1183 public String string;
1184 public int uid;
1185
1186 public int poolIdx;
1187
1188 public void setTo(HistoryTag o) {
1189 string = o.string;
1190 uid = o.uid;
1191 poolIdx = o.poolIdx;
1192 }
1193
1194 public void setTo(String _string, int _uid) {
1195 string = _string;
1196 uid = _uid;
1197 poolIdx = -1;
1198 }
1199
1200 public void writeToParcel(Parcel dest, int flags) {
1201 dest.writeString(string);
1202 dest.writeInt(uid);
1203 }
1204
1205 public void readFromParcel(Parcel src) {
1206 string = src.readString();
1207 uid = src.readInt();
1208 poolIdx = -1;
1209 }
1210
1211 @Override
1212 public boolean equals(Object o) {
1213 if (this == o) return true;
1214 if (o == null || getClass() != o.getClass()) return false;
1215
1216 HistoryTag that = (HistoryTag) o;
1217
1218 if (uid != that.uid) return false;
1219 if (!string.equals(that.string)) return false;
1220
1221 return true;
1222 }
1223
1224 @Override
1225 public int hashCode() {
1226 int result = string.hashCode();
1227 result = 31 * result + uid;
1228 return result;
1229 }
1230 }
1231
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001232 /**
1233 * Optional detailed information that can go into a history step. This is typically
1234 * generated each time the battery level changes.
1235 */
1236 public final static class HistoryStepDetails {
1237 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1238 public int userTime;
1239 public int systemTime;
1240
1241 // Top three apps using CPU in the last step, with times in 1/100 second.
1242 public int appCpuUid1;
1243 public int appCpuUTime1;
1244 public int appCpuSTime1;
1245 public int appCpuUid2;
1246 public int appCpuUTime2;
1247 public int appCpuSTime2;
1248 public int appCpuUid3;
1249 public int appCpuUTime3;
1250 public int appCpuSTime3;
1251
1252 // Information from /proc/stat
1253 public int statUserTime;
1254 public int statSystemTime;
1255 public int statIOWaitTime;
1256 public int statIrqTime;
1257 public int statSoftIrqTime;
1258 public int statIdlTime;
1259
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001260 // Platform-level low power state stats
1261 public String statPlatformIdleState;
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001262 public String statSubsystemPowerState;
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001263
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001264 public HistoryStepDetails() {
1265 clear();
1266 }
1267
1268 public void clear() {
1269 userTime = systemTime = 0;
1270 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1271 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1272 = appCpuUTime3 = appCpuSTime3 = 0;
1273 }
1274
1275 public void writeToParcel(Parcel out) {
1276 out.writeInt(userTime);
1277 out.writeInt(systemTime);
1278 out.writeInt(appCpuUid1);
1279 out.writeInt(appCpuUTime1);
1280 out.writeInt(appCpuSTime1);
1281 out.writeInt(appCpuUid2);
1282 out.writeInt(appCpuUTime2);
1283 out.writeInt(appCpuSTime2);
1284 out.writeInt(appCpuUid3);
1285 out.writeInt(appCpuUTime3);
1286 out.writeInt(appCpuSTime3);
1287 out.writeInt(statUserTime);
1288 out.writeInt(statSystemTime);
1289 out.writeInt(statIOWaitTime);
1290 out.writeInt(statIrqTime);
1291 out.writeInt(statSoftIrqTime);
1292 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001293 out.writeString(statPlatformIdleState);
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001294 out.writeString(statSubsystemPowerState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001295 }
1296
1297 public void readFromParcel(Parcel in) {
1298 userTime = in.readInt();
1299 systemTime = in.readInt();
1300 appCpuUid1 = in.readInt();
1301 appCpuUTime1 = in.readInt();
1302 appCpuSTime1 = in.readInt();
1303 appCpuUid2 = in.readInt();
1304 appCpuUTime2 = in.readInt();
1305 appCpuSTime2 = in.readInt();
1306 appCpuUid3 = in.readInt();
1307 appCpuUTime3 = in.readInt();
1308 appCpuSTime3 = in.readInt();
1309 statUserTime = in.readInt();
1310 statSystemTime = in.readInt();
1311 statIOWaitTime = in.readInt();
1312 statIrqTime = in.readInt();
1313 statSoftIrqTime = in.readInt();
1314 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001315 statPlatformIdleState = in.readString();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001316 statSubsystemPowerState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001317 }
1318 }
1319
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001320 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001321 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001322
1323 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001324 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001325
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001326 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001327 public static final byte CMD_NULL = -1;
1328 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001329 public static final byte CMD_CURRENT_TIME = 5;
1330 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001331 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001332 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001333
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001334 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001335
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001336 /**
1337 * Return whether the command code is a delta data update.
1338 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001339 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001340 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001341 }
1342
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001343 public byte batteryLevel;
1344 public byte batteryStatus;
1345 public byte batteryHealth;
1346 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001347
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001348 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001349 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001350
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001351 // The charge of the battery in micro-Ampere-hours.
1352 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001353
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001354 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001355 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001356 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001357 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001358 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1359 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001360 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001361 public static final int STATE_PHONE_STATE_SHIFT = 6;
1362 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001363 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001364 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001365 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001366
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001367 // These states always appear directly in the first int token
1368 // of a delta change; they should be ones that change relatively
1369 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001370 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1371 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001372 public static final int STATE_GPS_ON_FLAG = 1<<29;
1373 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001374 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001375 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001376 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001377 // Do not use, this is used for coulomb delta count.
1378 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001379 // These are on the lower bits used for the command; if they change
1380 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001381 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001382 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001383 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001384 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1385 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
Mike Mac2f518a2017-09-19 16:06:03 -07001386 public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001387 // empty slot
1388 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001389
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001390 public static final int MOST_INTERESTING_STATES =
Mike Mac2f518a2017-09-19 16:06:03 -07001391 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001392
1393 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001394
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001395 public int states;
1396
Dianne Hackborn3251b902014-06-20 14:40:53 -07001397 // Constants from WIFI_SUPPL_STATE_*
1398 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1399 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1400 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1401 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1402 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1403 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1404
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001405 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001406 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1407 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1408 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001409 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001410 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1411 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1412 public static final int STATE2_CHARGING_FLAG = 1<<24;
1413 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1414 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1415 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001416 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001417
1418 public static final int MOST_INTERESTING_STATES2 =
Mike Mac2f518a2017-09-19 16:06:03 -07001419 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
1420 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001421
1422 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001423
Dianne Hackborn40c87252014-03-19 16:55:40 -07001424 public int states2;
1425
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001426 // The wake lock that was acquired at this point.
1427 public HistoryTag wakelockTag;
1428
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001429 // Kernel wakeup reason at this point.
1430 public HistoryTag wakeReasonTag;
1431
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001432 // Non-null when there is more detailed information at this step.
1433 public HistoryStepDetails stepDetails;
1434
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001435 public static final int EVENT_FLAG_START = 0x8000;
1436 public static final int EVENT_FLAG_FINISH = 0x4000;
1437
1438 // No event in this item.
1439 public static final int EVENT_NONE = 0x0000;
1440 // Event is about a process that is running.
1441 public static final int EVENT_PROC = 0x0001;
1442 // Event is about an application package that is in the foreground.
1443 public static final int EVENT_FOREGROUND = 0x0002;
1444 // Event is about an application package that is at the top of the screen.
1445 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001446 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001447 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001448 // Events for all additional wake locks aquired/release within a wake block.
1449 // These are not generated by default.
1450 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001451 // Event is about an application executing a scheduled job.
1452 public static final int EVENT_JOB = 0x0006;
1453 // Events for users running.
1454 public static final int EVENT_USER_RUNNING = 0x0007;
1455 // Events for foreground user.
1456 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001457 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001458 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001459 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001460 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001461 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001462 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001463 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001464 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001465 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001466 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001467 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001468 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001469 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001470 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001471 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001472 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001473 // Event for a package being on the temporary whitelist.
1474 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001475 // Event for the screen waking up.
1476 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001477 // Event for the UID that woke up the application processor.
1478 // Used for wakeups coming from WiFi, modem, etc.
1479 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001480 // Event for reporting that a specific partial wake lock has been held for a long duration.
1481 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001482
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001483 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001484 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001485 // Mask to extract out only the type part of the event.
1486 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001487
1488 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1489 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1490 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1491 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1492 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1493 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001494 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1495 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001496 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1497 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001498 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1499 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1500 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1501 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1502 public static final int EVENT_USER_FOREGROUND_START =
1503 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1504 public static final int EVENT_USER_FOREGROUND_FINISH =
1505 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001506 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1507 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001508 public static final int EVENT_TEMP_WHITELIST_START =
1509 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1510 public static final int EVENT_TEMP_WHITELIST_FINISH =
1511 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001512 public static final int EVENT_LONG_WAKE_LOCK_START =
1513 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1514 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1515 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001516
1517 // For CMD_EVENT.
1518 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001519 public HistoryTag eventTag;
1520
Dianne Hackborn9a755432014-05-15 17:05:22 -07001521 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001522 public long currentTime;
1523
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001524 // Meta-data when reading.
1525 public int numReadInts;
1526
1527 // Pre-allocated objects.
1528 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001529 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001530 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001531
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001532 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001533 }
Bookatzc8c44962017-05-11 12:12:54 -07001534
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001535 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001536 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001537 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001538 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001539 }
Bookatzc8c44962017-05-11 12:12:54 -07001540
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001541 public int describeContents() {
1542 return 0;
1543 }
1544
1545 public void writeToParcel(Parcel dest, int flags) {
1546 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001547 int bat = (((int)cmd)&0xff)
1548 | ((((int)batteryLevel)<<8)&0xff00)
1549 | ((((int)batteryStatus)<<16)&0xf0000)
1550 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001551 | ((((int)batteryPlugType)<<24)&0xf000000)
1552 | (wakelockTag != null ? 0x10000000 : 0)
1553 | (wakeReasonTag != null ? 0x20000000 : 0)
1554 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001555 dest.writeInt(bat);
1556 bat = (((int)batteryTemperature)&0xffff)
1557 | ((((int)batteryVoltage)<<16)&0xffff0000);
1558 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001559 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001560 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001561 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001562 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001563 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001564 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001565 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001566 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001567 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001568 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001569 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001570 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001571 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001572 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001573 dest.writeLong(currentTime);
1574 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001575 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001576
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001577 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001578 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001579 int bat = src.readInt();
1580 cmd = (byte)(bat&0xff);
1581 batteryLevel = (byte)((bat>>8)&0xff);
1582 batteryStatus = (byte)((bat>>16)&0xf);
1583 batteryHealth = (byte)((bat>>20)&0xf);
1584 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001585 int bat2 = src.readInt();
1586 batteryTemperature = (short)(bat2&0xffff);
1587 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001588 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001589 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001590 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001591 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001592 wakelockTag = localWakelockTag;
1593 wakelockTag.readFromParcel(src);
1594 } else {
1595 wakelockTag = null;
1596 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001597 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001598 wakeReasonTag = localWakeReasonTag;
1599 wakeReasonTag.readFromParcel(src);
1600 } else {
1601 wakeReasonTag = null;
1602 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001603 if ((bat&0x40000000) != 0) {
1604 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001605 eventTag = localEventTag;
1606 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001607 } else {
1608 eventCode = EVENT_NONE;
1609 eventTag = null;
1610 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001611 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001612 currentTime = src.readLong();
1613 } else {
1614 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001615 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001616 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001617 }
1618
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001619 public void clear() {
1620 time = 0;
1621 cmd = CMD_NULL;
1622 batteryLevel = 0;
1623 batteryStatus = 0;
1624 batteryHealth = 0;
1625 batteryPlugType = 0;
1626 batteryTemperature = 0;
1627 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001628 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001629 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001630 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001631 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001632 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001633 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001634 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001635 }
Bookatzc8c44962017-05-11 12:12:54 -07001636
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001637 public void setTo(HistoryItem o) {
1638 time = o.time;
1639 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001640 setToCommon(o);
1641 }
1642
1643 public void setTo(long time, byte cmd, HistoryItem o) {
1644 this.time = time;
1645 this.cmd = cmd;
1646 setToCommon(o);
1647 }
1648
1649 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001650 batteryLevel = o.batteryLevel;
1651 batteryStatus = o.batteryStatus;
1652 batteryHealth = o.batteryHealth;
1653 batteryPlugType = o.batteryPlugType;
1654 batteryTemperature = o.batteryTemperature;
1655 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001656 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001657 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001658 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001659 if (o.wakelockTag != null) {
1660 wakelockTag = localWakelockTag;
1661 wakelockTag.setTo(o.wakelockTag);
1662 } else {
1663 wakelockTag = null;
1664 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001665 if (o.wakeReasonTag != null) {
1666 wakeReasonTag = localWakeReasonTag;
1667 wakeReasonTag.setTo(o.wakeReasonTag);
1668 } else {
1669 wakeReasonTag = null;
1670 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001671 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001672 if (o.eventTag != null) {
1673 eventTag = localEventTag;
1674 eventTag.setTo(o.eventTag);
1675 } else {
1676 eventTag = null;
1677 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001678 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001679 }
1680
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001681 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001682 return batteryLevel == o.batteryLevel
1683 && batteryStatus == o.batteryStatus
1684 && batteryHealth == o.batteryHealth
1685 && batteryPlugType == o.batteryPlugType
1686 && batteryTemperature == o.batteryTemperature
1687 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001688 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001689 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001690 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001691 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001692 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001693
1694 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001695 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001696 return false;
1697 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001698 if (wakelockTag != o.wakelockTag) {
1699 if (wakelockTag == null || o.wakelockTag == null) {
1700 return false;
1701 }
1702 if (!wakelockTag.equals(o.wakelockTag)) {
1703 return false;
1704 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001705 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001706 if (wakeReasonTag != o.wakeReasonTag) {
1707 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1708 return false;
1709 }
1710 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1711 return false;
1712 }
1713 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001714 if (eventTag != o.eventTag) {
1715 if (eventTag == null || o.eventTag == null) {
1716 return false;
1717 }
1718 if (!eventTag.equals(o.eventTag)) {
1719 return false;
1720 }
1721 }
1722 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001723 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001724 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001725
1726 public final static class HistoryEventTracker {
1727 private final HashMap<String, SparseIntArray>[] mActiveEvents
1728 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1729
1730 public boolean updateState(int code, String name, int uid, int poolIdx) {
1731 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1732 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1733 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1734 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001735 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001736 mActiveEvents[idx] = active;
1737 }
1738 SparseIntArray uids = active.get(name);
1739 if (uids == null) {
1740 uids = new SparseIntArray();
1741 active.put(name, uids);
1742 }
1743 if (uids.indexOfKey(uid) >= 0) {
1744 // Already set, nothing to do!
1745 return false;
1746 }
1747 uids.put(uid, poolIdx);
1748 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1749 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1750 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1751 if (active == null) {
1752 // not currently active, nothing to do.
1753 return false;
1754 }
1755 SparseIntArray uids = active.get(name);
1756 if (uids == null) {
1757 // not currently active, nothing to do.
1758 return false;
1759 }
1760 idx = uids.indexOfKey(uid);
1761 if (idx < 0) {
1762 // not currently active, nothing to do.
1763 return false;
1764 }
1765 uids.removeAt(idx);
1766 if (uids.size() <= 0) {
1767 active.remove(name);
1768 }
1769 }
1770 return true;
1771 }
1772
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001773 public void removeEvents(int code) {
1774 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1775 mActiveEvents[idx] = null;
1776 }
1777
Dianne Hackborn37de0982014-05-09 09:32:18 -07001778 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1779 return mActiveEvents[code];
1780 }
1781 }
1782
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001783 public static final class BitDescription {
1784 public final int mask;
1785 public final int shift;
1786 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001787 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001788 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001789 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001790
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001791 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001792 this.mask = mask;
1793 this.shift = -1;
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 = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001797 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001798 }
Bookatzc8c44962017-05-11 12:12:54 -07001799
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001800 public BitDescription(int mask, int shift, String name, String shortName,
1801 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001802 this.mask = mask;
1803 this.shift = shift;
1804 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001805 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001806 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001807 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001808 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001809 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001810
Dianne Hackbornfc064132014-06-02 12:42:12 -07001811 /**
1812 * Don't allow any more batching in to the current history event. This
1813 * is called when printing partial histories, so to ensure that the next
1814 * history event will go in to a new batch after what was printed in the
1815 * last partial history.
1816 */
1817 public abstract void commitCurrentHistoryBatchLocked();
1818
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001819 public abstract int getHistoryTotalSize();
1820
1821 public abstract int getHistoryUsedSize();
1822
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001823 public abstract boolean startIteratingHistoryLocked();
1824
Dianne Hackborn099bc622014-01-22 13:39:16 -08001825 public abstract int getHistoryStringPoolSize();
1826
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001827 public abstract int getHistoryStringPoolBytes();
1828
1829 public abstract String getHistoryTagPoolString(int index);
1830
1831 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001832
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001833 public abstract boolean getNextHistoryLocked(HistoryItem out);
1834
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001835 public abstract void finishIteratingHistoryLocked();
1836
1837 public abstract boolean startIteratingOldHistoryLocked();
1838
1839 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1840
1841 public abstract void finishIteratingOldHistoryLocked();
1842
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001843 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001844 * Return the base time offset for the battery history.
1845 */
1846 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001847
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001848 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001849 * Returns the number of times the device has been started.
1850 */
1851 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001854 * 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 -08001855 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001856 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 * {@hide}
1858 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001859 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001860
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001861 /**
1862 * Returns the number of times the screen was turned on.
1863 *
1864 * {@hide}
1865 */
1866 public abstract int getScreenOnCount(int which);
1867
Mike Mac2f518a2017-09-19 16:06:03 -07001868 /**
1869 * Returns the time in microseconds that the screen has been dozing while the device was
1870 * running on battery.
1871 *
1872 * {@hide}
1873 */
1874 public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which);
1875
1876 /**
1877 * Returns the number of times the screen was turned dozing.
1878 *
1879 * {@hide}
1880 */
1881 public abstract int getScreenDozeCount(int which);
1882
Jeff Browne95c3cd2014-05-02 16:59:26 -07001883 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1884
Dianne Hackborn617f8772009-03-31 15:04:46 -07001885 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1886 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1887 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1888 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1889 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001890
Dianne Hackborn617f8772009-03-31 15:04:46 -07001891 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1892 "dark", "dim", "medium", "light", "bright"
1893 };
Bookatzc8c44962017-05-11 12:12:54 -07001894
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001895 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1896 "0", "1", "2", "3", "4"
1897 };
1898
Dianne Hackborn617f8772009-03-31 15:04:46 -07001899 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001900
Dianne Hackborn617f8772009-03-31 15:04:46 -07001901 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001902 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001903 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001904 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001905 * {@hide}
1906 */
1907 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001908 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001911 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001912 * running on battery.
1913 *
1914 * {@hide}
1915 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001916 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001917
1918 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001919 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001920 *
1921 * {@hide}
1922 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001923 public abstract int getPowerSaveModeEnabledCount(int which);
1924
1925 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001926 * Constant for device idle mode: not active.
1927 */
1928 public static final int DEVICE_IDLE_MODE_OFF = 0;
1929
1930 /**
1931 * Constant for device idle mode: active in lightweight mode.
1932 */
1933 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1934
1935 /**
1936 * Constant for device idle mode: active in full mode.
1937 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001938 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001939
1940 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001941 * Returns the time in microseconds that device has been in idle mode while
1942 * running on battery.
1943 *
1944 * {@hide}
1945 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001946 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001947
1948 /**
1949 * Returns the number of times that the devie has gone in to idle mode.
1950 *
1951 * {@hide}
1952 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001953 public abstract int getDeviceIdleModeCount(int mode, int which);
1954
1955 /**
1956 * Return the longest duration we spent in a particular device idle mode (fully in the
1957 * mode, not in idle maintenance etc).
1958 */
1959 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001960
1961 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001962 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001963 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001964 * counts all of the time that we consider the device to be idle, whether or not
1965 * it is currently in the actual device idle mode.
1966 *
1967 * {@hide}
1968 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001969 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001970
1971 /**
1972 * Returns the number of times that the devie has started idling.
1973 *
1974 * {@hide}
1975 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001976 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001977
1978 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001979 * Returns the number of times that connectivity state changed.
1980 *
1981 * {@hide}
1982 */
1983 public abstract int getNumConnectivityChange(int which);
1984
1985 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001986 * 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 -08001987 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001988 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 * {@hide}
1990 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001991 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001992
Dianne Hackborn627bba72009-03-24 22:32:56 -07001993 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001994 * Returns the number of times a phone call was activated.
1995 *
1996 * {@hide}
1997 */
1998 public abstract int getPhoneOnCount(int which);
1999
2000 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002001 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002002 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002003 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002004 * {@hide}
2005 */
2006 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002007 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002008
Dianne Hackborn617f8772009-03-31 15:04:46 -07002009 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07002010 * Returns the time in microseconds that the phone has been trying to
2011 * acquire a signal.
2012 *
2013 * {@hide}
2014 */
2015 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002016 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002017
2018 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002019 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07002020 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002021 * {@hide}
2022 */
2023 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
2024
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002025 /**
2026 * Returns the time in microseconds that the mobile network has been active
2027 * (in a high power state).
2028 *
2029 * {@hide}
2030 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002031 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002032
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002033 /**
2034 * Returns the number of times that the mobile network has transitioned to the
2035 * active state.
2036 *
2037 * {@hide}
2038 */
2039 public abstract int getMobileRadioActiveCount(int which);
2040
2041 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002042 * Returns the time in microseconds that is the difference between the mobile radio
2043 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
2044 * from the radio.
2045 *
2046 * {@hide}
2047 */
2048 public abstract long getMobileRadioActiveAdjustedTime(int which);
2049
2050 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002051 * Returns the time in microseconds that the mobile network has been active
2052 * (in a high power state) but not being able to blame on an app.
2053 *
2054 * {@hide}
2055 */
2056 public abstract long getMobileRadioActiveUnknownTime(int which);
2057
2058 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002059 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002060 *
2061 * {@hide}
2062 */
2063 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002064
Dianne Hackborn627bba72009-03-24 22:32:56 -07002065 public static final int DATA_CONNECTION_NONE = 0;
2066 public static final int DATA_CONNECTION_GPRS = 1;
2067 public static final int DATA_CONNECTION_EDGE = 2;
2068 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002069 public static final int DATA_CONNECTION_CDMA = 4;
2070 public static final int DATA_CONNECTION_EVDO_0 = 5;
2071 public static final int DATA_CONNECTION_EVDO_A = 6;
2072 public static final int DATA_CONNECTION_1xRTT = 7;
2073 public static final int DATA_CONNECTION_HSDPA = 8;
2074 public static final int DATA_CONNECTION_HSUPA = 9;
2075 public static final int DATA_CONNECTION_HSPA = 10;
2076 public static final int DATA_CONNECTION_IDEN = 11;
2077 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002078 public static final int DATA_CONNECTION_LTE = 13;
2079 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002080 public static final int DATA_CONNECTION_HSPAP = 15;
2081 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002082
Dianne Hackborn627bba72009-03-24 22:32:56 -07002083 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002084 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002085 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002086 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002087 };
Bookatzc8c44962017-05-11 12:12:54 -07002088
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002089 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002090
Dianne Hackborn627bba72009-03-24 22:32:56 -07002091 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002092 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002093 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002094 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002095 * {@hide}
2096 */
2097 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002098 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002100 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002101 * Returns the number of times the phone has entered the given data
2102 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002103 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002104 * {@hide}
2105 */
2106 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002107
Dianne Hackborn3251b902014-06-20 14:40:53 -07002108 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2109 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2110 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2111 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2112 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2113 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2114 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2115 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2116 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2117 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2118 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2119 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2120 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2121
2122 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2123
2124 static final String[] WIFI_SUPPL_STATE_NAMES = {
2125 "invalid", "disconn", "disabled", "inactive", "scanning",
2126 "authenticating", "associating", "associated", "4-way-handshake",
2127 "group-handshake", "completed", "dormant", "uninit"
2128 };
2129
2130 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2131 "inv", "dsc", "dis", "inact", "scan",
2132 "auth", "ascing", "asced", "4-way",
2133 "group", "compl", "dorm", "uninit"
2134 };
2135
Mike Mac2f518a2017-09-19 16:06:03 -07002136 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002137 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002138 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2139 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002140 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002141 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2142 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2143 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002144 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002145 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002146 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002147 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002148 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2149 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Mike Mac2f518a2017-09-19 16:06:03 -07002150 new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002151 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2152 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2153 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2154 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2155 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2156 new String[] {"in", "out", "emergency", "off"},
2157 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002158 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2159 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2160 SignalStrength.SIGNAL_STRENGTH_NAMES,
2161 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002162 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2163 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2164 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002165 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002166
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002167 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2168 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002169 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002170 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002171 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002172 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002173 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002174 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2175 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2176 new String[] { "off", "light", "full", "???" },
2177 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002178 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2179 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2180 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002181 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2182 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2183 new String[] { "0", "1", "2", "3", "4" },
2184 new String[] { "0", "1", "2", "3", "4" }),
2185 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2186 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2187 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002188 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002189 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002190 };
2191
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002192 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002193 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002194 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2195 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002196 };
2197
2198 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002199 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002200 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002201 "Esw", "Ewa", "Elw", "Eec"
2202 };
2203
2204 @FunctionalInterface
2205 public interface IntToString {
2206 String applyAsString(int val);
2207 }
2208
2209 private static final IntToString sUidToString = UserHandle::formatUid;
2210 private static final IntToString sIntToString = Integer::toString;
2211
2212 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2213 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2214 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2215 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2216 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002217 };
2218
Dianne Hackborn617f8772009-03-31 15:04:46 -07002219 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002220 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002221 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002222 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002223 * {@hide}
2224 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002225 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002226
2227 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002228 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002229 * been in the running state while the device was running on battery.
2230 *
2231 * {@hide}
2232 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002233 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002234
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002235 public static final int WIFI_STATE_OFF = 0;
2236 public static final int WIFI_STATE_OFF_SCANNING = 1;
2237 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2238 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2239 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2240 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2241 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2242 public static final int WIFI_STATE_SOFT_AP = 7;
2243
2244 static final String[] WIFI_STATE_NAMES = {
2245 "off", "scanning", "no_net", "disconn",
2246 "sta", "p2p", "sta_p2p", "soft_ap"
2247 };
2248
2249 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2250
2251 /**
2252 * Returns the time in microseconds that WiFi has been running in the given state.
2253 *
2254 * {@hide}
2255 */
2256 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002257 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002258
2259 /**
2260 * Returns the number of times that WiFi has entered the given state.
2261 *
2262 * {@hide}
2263 */
2264 public abstract int getWifiStateCount(int wifiState, int which);
2265
The Android Open Source Project10592532009-03-18 17:39:46 -07002266 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002267 * Returns the time in microseconds that the wifi supplicant has been
2268 * in a given state.
2269 *
2270 * {@hide}
2271 */
2272 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2273
2274 /**
2275 * Returns the number of times that the wifi supplicant has transitioned
2276 * to a given state.
2277 *
2278 * {@hide}
2279 */
2280 public abstract int getWifiSupplStateCount(int state, int which);
2281
2282 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2283
2284 /**
2285 * Returns the time in microseconds that WIFI has been running with
2286 * the given signal strength.
2287 *
2288 * {@hide}
2289 */
2290 public abstract long getWifiSignalStrengthTime(int strengthBin,
2291 long elapsedRealtimeUs, int which);
2292
2293 /**
2294 * Returns the number of times WIFI has entered the given signal strength.
2295 *
2296 * {@hide}
2297 */
2298 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2299
2300 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002301 * Returns the time in microseconds that the flashlight has been on while the device was
2302 * running on battery.
2303 *
2304 * {@hide}
2305 */
2306 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2307
2308 /**
2309 * Returns the number of times that the flashlight has been turned on while the device was
2310 * running on battery.
2311 *
2312 * {@hide}
2313 */
2314 public abstract long getFlashlightOnCount(int which);
2315
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002316 /**
2317 * Returns the time in microseconds that the camera has been on while the device was
2318 * running on battery.
2319 *
2320 * {@hide}
2321 */
2322 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2323
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002324 /**
2325 * Returns the time in microseconds that bluetooth scans were running while the device was
2326 * on battery.
2327 *
2328 * {@hide}
2329 */
2330 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002331
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002332 public static final int NETWORK_MOBILE_RX_DATA = 0;
2333 public static final int NETWORK_MOBILE_TX_DATA = 1;
2334 public static final int NETWORK_WIFI_RX_DATA = 2;
2335 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002336 public static final int NETWORK_BT_RX_DATA = 4;
2337 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002338 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2339 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2340 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2341 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2342 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002343
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002344 public abstract long getNetworkActivityBytes(int type, int which);
2345 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002346
Adam Lesinskie08af192015-03-25 16:42:59 -07002347 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002348 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002349 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002350 * actual power data.
2351 */
2352 public abstract boolean hasWifiActivityReporting();
2353
2354 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002355 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2356 * in various radio controller states, such as transmit, receive, and idle.
2357 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002358 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002359 public abstract ControllerActivityCounter getWifiControllerActivity();
2360
2361 /**
2362 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2363 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2364 * actual power data.
2365 */
2366 public abstract boolean hasBluetoothActivityReporting();
2367
2368 /**
2369 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2370 * in various radio controller states, such as transmit, receive, and idle.
2371 * @return non-null {@link ControllerActivityCounter}
2372 */
2373 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2374
2375 /**
2376 * Returns true if the BatteryStats object has detailed modem power reports.
2377 * When true, calling {@link #getModemControllerActivity()} will yield the
2378 * actual power data.
2379 */
2380 public abstract boolean hasModemActivityReporting();
2381
2382 /**
2383 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2384 * in various radio controller states, such as transmit, receive, and idle.
2385 * @return non-null {@link ControllerActivityCounter}
2386 */
2387 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002388
The Android Open Source Project10592532009-03-18 17:39:46 -07002389 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002390 * Return the wall clock time when battery stats data collection started.
2391 */
2392 public abstract long getStartClockTime();
2393
2394 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002395 * Return platform version tag that we were running in when the battery stats started.
2396 */
2397 public abstract String getStartPlatformVersion();
2398
2399 /**
2400 * Return platform version tag that we were running in when the battery stats ended.
2401 */
2402 public abstract String getEndPlatformVersion();
2403
2404 /**
2405 * Return the internal version code of the parcelled format.
2406 */
2407 public abstract int getParcelVersion();
2408
2409 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 * Return whether we are currently running on battery.
2411 */
2412 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002413
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414 /**
2415 * Returns a SparseArray containing the statistics for each uid.
2416 */
2417 public abstract SparseArray<? extends Uid> getUidStats();
2418
2419 /**
2420 * Returns the current battery uptime in microseconds.
2421 *
2422 * @param curTime the amount of elapsed realtime in microseconds.
2423 */
2424 public abstract long getBatteryUptime(long curTime);
2425
2426 /**
2427 * Returns the current battery realtime in microseconds.
2428 *
2429 * @param curTime the amount of elapsed realtime in microseconds.
2430 */
2431 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002432
The Android Open Source Project10592532009-03-18 17:39:46 -07002433 /**
Evan Millar633a1742009-04-02 16:36:33 -07002434 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002435 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002436 */
Evan Millar633a1742009-04-02 16:36:33 -07002437 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002438
The Android Open Source Project10592532009-03-18 17:39:46 -07002439 /**
Evan Millar633a1742009-04-02 16:36:33 -07002440 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2441 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002442 */
Evan Millar633a1742009-04-02 16:36:33 -07002443 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002444
2445 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002446 * Get the amount the battery has discharged since the stats were
2447 * last reset after charging, as a lower-end approximation.
2448 */
2449 public abstract int getLowDischargeAmountSinceCharge();
2450
2451 /**
2452 * Get the amount the battery has discharged since the stats were
2453 * last reset after charging, as an upper-end approximation.
2454 */
2455 public abstract int getHighDischargeAmountSinceCharge();
2456
2457 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002458 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2459 */
2460 public abstract int getDischargeAmount(int which);
2461
2462 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002463 * Get the amount the battery has discharged while the screen was on,
2464 * since the last time power was unplugged.
2465 */
2466 public abstract int getDischargeAmountScreenOn();
2467
2468 /**
2469 * Get the amount the battery has discharged while the screen was on,
2470 * since the last time the device was charged.
2471 */
2472 public abstract int getDischargeAmountScreenOnSinceCharge();
2473
2474 /**
2475 * Get the amount the battery has discharged while the screen was off,
2476 * since the last time power was unplugged.
2477 */
2478 public abstract int getDischargeAmountScreenOff();
2479
2480 /**
2481 * Get the amount the battery has discharged while the screen was off,
2482 * since the last time the device was charged.
2483 */
2484 public abstract int getDischargeAmountScreenOffSinceCharge();
2485
2486 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002487 * Get the amount the battery has discharged while the screen was doze,
2488 * since the last time power was unplugged.
2489 */
2490 public abstract int getDischargeAmountScreenDoze();
2491
2492 /**
2493 * Get the amount the battery has discharged while the screen was doze,
2494 * since the last time the device was charged.
2495 */
2496 public abstract int getDischargeAmountScreenDozeSinceCharge();
2497
2498 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 * Returns the total, last, or current battery uptime in microseconds.
2500 *
2501 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002502 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 */
2504 public abstract long computeBatteryUptime(long curTime, int which);
2505
2506 /**
2507 * Returns the total, last, or current battery realtime in microseconds.
2508 *
2509 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002510 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 */
2512 public abstract long computeBatteryRealtime(long curTime, int which);
2513
2514 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002515 * Returns the total, last, or current battery screen off/doze uptime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002516 *
2517 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002518 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002519 */
2520 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2521
2522 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002523 * Returns the total, last, or current battery screen off/doze realtime in microseconds.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002524 *
2525 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002526 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002527 */
2528 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2529
2530 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 * Returns the total, last, or current uptime in microseconds.
2532 *
2533 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002534 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 */
2536 public abstract long computeUptime(long curTime, int which);
2537
2538 /**
2539 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002540 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002542 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 */
2544 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002545
2546 /**
2547 * Compute an approximation for how much run time (in microseconds) is remaining on
2548 * the battery. Returns -1 if no time can be computed: either there is not
2549 * enough current data to make a decision, or the battery is currently
2550 * charging.
2551 *
2552 * @param curTime The current elepsed realtime in microseconds.
2553 */
2554 public abstract long computeBatteryTimeRemaining(long curTime);
2555
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002556 // The part of a step duration that is the actual time.
2557 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2558
2559 // Bits in a step duration that are the new battery level we are at.
2560 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002561 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002562
2563 // Bits in a step duration that are the initial mode we were in at that step.
2564 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002565 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002566
2567 // Bits in a step duration that indicate which modes changed during that step.
2568 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002569 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002570
2571 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2572 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2573
Santos Cordone94f0502017-02-24 12:31:20 -08002574 // The largest value for screen state that is tracked in battery states. Any values above
2575 // this should be mapped back to one of the tracked values before being tracked here.
2576 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2577
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002578 // Step duration mode: power save is on.
2579 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2580
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002581 // Step duration mode: device is currently in idle mode.
2582 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2583
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002584 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2585 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002586 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2587 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002588 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2589 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2590 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2591 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2592 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002593 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2594 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002595 };
2596 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2597 (Display.STATE_OFF-1),
2598 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002599 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002600 (Display.STATE_ON-1),
2601 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2602 (Display.STATE_DOZE-1),
2603 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2604 (Display.STATE_DOZE_SUSPEND-1),
2605 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002606 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002607 };
2608 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2609 "screen off",
2610 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002611 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002612 "screen on",
2613 "screen on power save",
2614 "screen doze",
2615 "screen doze power save",
2616 "screen doze-suspend",
2617 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002618 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002619 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002620
2621 /**
Mike Mac2f518a2017-09-19 16:06:03 -07002622 * Return the amount of battery discharge while the screen was off, measured in
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002623 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2624 * a coulomb counter.
2625 */
Mike Mac2f518a2017-09-19 16:06:03 -07002626 public abstract long getMahDischargeScreenOff(int which);
2627
2628 /**
2629 * Return the amount of battery discharge while the screen was in doze mode, measured in
2630 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2631 * a coulomb counter.
2632 */
2633 public abstract long getMahDischargeScreenDoze(int which);
2634
2635 /**
2636 * Return the amount of battery discharge measured in micro-Ampere-hours. This will be
2637 * non-zero only if the device's battery has a coulomb counter.
2638 */
2639 public abstract long getMahDischarge(int which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002640
2641 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002642 * Returns the estimated real battery capacity, which may be less than the capacity
2643 * declared by the PowerProfile.
2644 * @return The estimated battery capacity in mAh.
2645 */
2646 public abstract int getEstimatedBatteryCapacity();
2647
2648 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002649 * @return The minimum learned battery capacity in uAh.
2650 */
2651 public abstract int getMinLearnedBatteryCapacity();
2652
2653 /**
2654 * @return The maximum learned battery capacity in uAh.
2655 */
2656 public abstract int getMaxLearnedBatteryCapacity() ;
2657
2658 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002659 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002660 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002661 public abstract LevelStepTracker getDischargeLevelStepTracker();
2662
2663 /**
2664 * Return the array of daily discharge step durations.
2665 */
2666 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002667
2668 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002669 * Compute an approximation for how much time (in microseconds) remains until the battery
2670 * is fully charged. Returns -1 if no time can be computed: either there is not
2671 * enough current data to make a decision, or the battery is currently
2672 * discharging.
2673 *
2674 * @param curTime The current elepsed realtime in microseconds.
2675 */
2676 public abstract long computeChargeTimeRemaining(long curTime);
2677
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002678 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002679 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002680 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002681 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002682
2683 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002684 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002685 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002686 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002687
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002688 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2689
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002690 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002691
Evan Millarc64edde2009-04-18 12:26:32 -07002692 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693
Bookatz50df7112017-08-04 14:53:26 -07002694 /**
2695 * Returns Timers tracking the total time of each Resource Power Manager state and voter.
2696 */
2697 public abstract Map<String, ? extends Timer> getRpmStats();
2698 /**
2699 * Returns Timers tracking the screen-off time of each Resource Power Manager state and voter.
2700 */
2701 public abstract Map<String, ? extends Timer> getScreenOffRpmStats();
2702
2703
James Carr2dd7e5e2016-07-20 18:48:39 -07002704 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2705
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002706 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2707
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002708 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 long days = seconds / (60 * 60 * 24);
2710 if (days != 0) {
2711 out.append(days);
2712 out.append("d ");
2713 }
2714 long used = days * 60 * 60 * 24;
2715
2716 long hours = (seconds - used) / (60 * 60);
2717 if (hours != 0 || used != 0) {
2718 out.append(hours);
2719 out.append("h ");
2720 }
2721 used += hours * 60 * 60;
2722
2723 long mins = (seconds-used) / 60;
2724 if (mins != 0 || used != 0) {
2725 out.append(mins);
2726 out.append("m ");
2727 }
2728 used += mins * 60;
2729
2730 if (seconds != 0 || used != 0) {
2731 out.append(seconds-used);
2732 out.append("s ");
2733 }
2734 }
2735
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002736 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002737 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002738 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002739 sb.append(time - (sec * 1000));
2740 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002741 }
2742
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002743 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002744 long sec = time / 1000;
2745 formatTimeRaw(sb, sec);
2746 sb.append(time - (sec * 1000));
2747 sb.append("ms");
2748 }
2749
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002750 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002752 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002753 }
2754 float perc = ((float)num) / ((float)den) * 100;
2755 mFormatBuilder.setLength(0);
2756 mFormatter.format("%.1f%%", perc);
2757 return mFormatBuilder.toString();
2758 }
2759
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002760 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002761 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002762
Evan Millar22ac0432009-03-31 11:33:18 -07002763 if (bytes < BYTES_PER_KB) {
2764 return bytes + "B";
2765 } else if (bytes < BYTES_PER_MB) {
2766 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2767 return mFormatBuilder.toString();
2768 } else if (bytes < BYTES_PER_GB){
2769 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2770 return mFormatBuilder.toString();
2771 } else {
2772 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2773 return mFormatBuilder.toString();
2774 }
2775 }
2776
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002777 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002778 if (timer != null) {
2779 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002780 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002781 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2782 return totalTimeMillis;
2783 }
2784 return 0;
2785 }
2786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787 /**
2788 *
2789 * @param sb a StringBuilder object.
2790 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002791 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002792 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002793 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 * @param linePrefix a String to be prepended to each line of output.
2795 * @return the line prefix
2796 */
2797 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002798 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002801 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002802
Evan Millarc64edde2009-04-18 12:26:32 -07002803 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 if (totalTimeMillis != 0) {
2805 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002806 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002807 if (name != null) {
2808 sb.append(name);
2809 sb.append(' ');
2810 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002811 sb.append('(');
2812 sb.append(count);
2813 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002814 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2815 if (maxDurationMs >= 0) {
2816 sb.append(" max=");
2817 sb.append(maxDurationMs);
2818 }
Bookatz506a8182017-05-01 14:18:42 -07002819 // Put actual time if it is available and different from totalTimeMillis.
2820 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2821 if (totalDurMs > totalTimeMillis) {
2822 sb.append(" actual=");
2823 sb.append(totalDurMs);
2824 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002825 if (timer.isRunningLocked()) {
2826 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2827 if (currentMs >= 0) {
2828 sb.append(" (running for ");
2829 sb.append(currentMs);
2830 sb.append("ms)");
2831 } else {
2832 sb.append(" (running)");
2833 }
2834 }
2835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 return ", ";
2837 }
2838 }
2839 return linePrefix;
2840 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002841
2842 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002843 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002844 *
2845 * @param pw a PrintWriter object to print to.
2846 * @param sb a StringBuilder object.
2847 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002848 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002849 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2850 * @param prefix a String to be prepended to each line of output.
2851 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002852 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002853 */
2854 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002855 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002856 if (timer != null) {
2857 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002858 final long totalTimeMs = (timer.getTotalTimeLocked(
2859 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002860 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002861 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002862 sb.setLength(0);
2863 sb.append(prefix);
2864 sb.append(" ");
2865 sb.append(type);
2866 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002867 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002868 sb.append("realtime (");
2869 sb.append(count);
2870 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002871 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2872 if (maxDurationMs >= 0) {
2873 sb.append(" max=");
2874 sb.append(maxDurationMs);
2875 }
2876 if (timer.isRunningLocked()) {
2877 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2878 if (currentMs >= 0) {
2879 sb.append(" (running for ");
2880 sb.append(currentMs);
2881 sb.append("ms)");
2882 } else {
2883 sb.append(" (running)");
2884 }
2885 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002886 pw.println(sb.toString());
2887 return true;
2888 }
2889 }
2890 return false;
2891 }
Bookatzc8c44962017-05-11 12:12:54 -07002892
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002893 /**
2894 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002895 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002896 * @param sb a StringBuilder object.
2897 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002898 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002900 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 * @param linePrefix a String to be prepended to each line of output.
2902 * @return the line prefix
2903 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002904 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2905 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 long totalTimeMicros = 0;
2907 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07002908 long max = 0;
2909 long current = 0;
2910 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002912 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07002913 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002914 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2915 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07002916 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 }
2918 sb.append(linePrefix);
2919 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2920 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002921 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002923 sb.append(',');
2924 sb.append(current);
2925 sb.append(',');
2926 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07002927 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
2928 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
2929 // totalDuration independent of totalTimeMicros (since they are not pooled).
2930 if (name != null) {
2931 sb.append(',');
2932 sb.append(totalDuration);
2933 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002934 return ",";
2935 }
Bookatz506a8182017-05-01 14:18:42 -07002936
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002937 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2938 String type) {
2939 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2940 pw.print(',');
2941 pw.print(uid);
2942 pw.print(',');
2943 pw.print(category);
2944 pw.print(',');
2945 pw.print(type);
2946 }
2947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 /**
2949 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07002950 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002951 * @param pw the PageWriter to dump log to
2952 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2953 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2954 * @param args type-dependent data arguments
2955 */
Bookatzc8c44962017-05-11 12:12:54 -07002956 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002957 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002958 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002959 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002960 pw.print(',');
2961 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002963 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002965
2966 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002967 * Dump a given timer stat for terse checkin mode.
2968 *
2969 * @param pw the PageWriter to dump log to
2970 * @param uid the UID to log
2971 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2972 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2973 * @param timer a {@link Timer} to dump stats for
2974 * @param rawRealtime the current elapsed realtime of the system in microseconds
2975 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2976 */
2977 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2978 Timer timer, long rawRealtime, int which) {
2979 if (timer != null) {
2980 // Convert from microseconds to milliseconds with rounding
2981 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2982 / 1000;
2983 final int count = timer.getCountLocked(which);
2984 if (totalTime != 0) {
2985 dumpLine(pw, uid, category, type, totalTime, count);
2986 }
2987 }
2988 }
2989
2990 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002991 * Checks if the ControllerActivityCounter has any data worth dumping.
2992 */
2993 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2994 if (counter == null) {
2995 return false;
2996 }
2997
2998 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2999 || counter.getRxTimeCounter().getCountLocked(which) != 0
3000 || counter.getPowerCounter().getCountLocked(which) != 0) {
3001 return true;
3002 }
3003
3004 for (LongCounter c : counter.getTxTimeCounters()) {
3005 if (c.getCountLocked(which) != 0) {
3006 return true;
3007 }
3008 }
3009 return false;
3010 }
3011
3012 /**
3013 * Dumps the ControllerActivityCounter if it has any data worth dumping.
3014 * The order of the arguments in the final check in line is:
3015 *
3016 * idle, rx, power, tx...
3017 *
3018 * where tx... is one or more transmit level times.
3019 */
3020 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
3021 String type,
3022 ControllerActivityCounter counter,
3023 int which) {
3024 if (!controllerActivityHasData(counter, which)) {
3025 return;
3026 }
3027
3028 dumpLineHeader(pw, uid, category, type);
3029 pw.print(",");
3030 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
3031 pw.print(",");
3032 pw.print(counter.getRxTimeCounter().getCountLocked(which));
3033 pw.print(",");
3034 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
3035 for (LongCounter c : counter.getTxTimeCounters()) {
3036 pw.print(",");
3037 pw.print(c.getCountLocked(which));
3038 }
3039 pw.println();
3040 }
3041
3042 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
3043 String prefix, String controllerName,
3044 ControllerActivityCounter counter,
3045 int which) {
3046 if (controllerActivityHasData(counter, which)) {
3047 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
3048 }
3049 }
3050
3051 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
3052 String controllerName,
3053 ControllerActivityCounter counter, int which) {
3054 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
3055 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
3056 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
3057 long totalTxTimeMs = 0;
3058 for (LongCounter txState : counter.getTxTimeCounters()) {
3059 totalTxTimeMs += txState.getCountLocked(which);
3060 }
3061
3062 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
3063
3064 sb.setLength(0);
3065 sb.append(prefix);
3066 sb.append(" ");
3067 sb.append(controllerName);
3068 sb.append(" Idle time: ");
3069 formatTimeMs(sb, idleTimeMs);
3070 sb.append("(");
3071 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
3072 sb.append(")");
3073 pw.println(sb.toString());
3074
3075 sb.setLength(0);
3076 sb.append(prefix);
3077 sb.append(" ");
3078 sb.append(controllerName);
3079 sb.append(" Rx time: ");
3080 formatTimeMs(sb, rxTimeMs);
3081 sb.append("(");
3082 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
3083 sb.append(")");
3084 pw.println(sb.toString());
3085
3086 sb.setLength(0);
3087 sb.append(prefix);
3088 sb.append(" ");
3089 sb.append(controllerName);
3090 sb.append(" Tx time: ");
3091 formatTimeMs(sb, totalTxTimeMs);
3092 sb.append("(");
3093 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
3094 sb.append(")");
3095 pw.println(sb.toString());
3096
3097 final int numTxLvls = counter.getTxTimeCounters().length;
3098 if (numTxLvls > 1) {
3099 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3100 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3101 sb.setLength(0);
3102 sb.append(prefix);
3103 sb.append(" [");
3104 sb.append(lvl);
3105 sb.append("] ");
3106 formatTimeMs(sb, txLvlTimeMs);
3107 sb.append("(");
3108 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
3109 sb.append(")");
3110 pw.println(sb.toString());
3111 }
3112 }
3113
3114 sb.setLength(0);
3115 sb.append(prefix);
3116 sb.append(" ");
3117 sb.append(controllerName);
3118 sb.append(" Power drain: ").append(
3119 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
3120 sb.append("mAh");
3121 pw.println(sb.toString());
3122 }
3123
3124 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003125 * Temporary for settings.
3126 */
3127 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3128 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3129 }
3130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 /**
3132 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003133 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003136 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3137 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3139 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07003140 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003141 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003142 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3143 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003144 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3145 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3146 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 final long totalRealtime = computeRealtime(rawRealtime, which);
3148 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003149 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Mike Mac2f518a2017-09-19 16:06:03 -07003150 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003151 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003152 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003153 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3154 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003155 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003156 rawRealtime, which);
3157 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3158 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003159 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003160 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003161 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003162 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Mike Mac2f518a2017-09-19 16:06:03 -07003163 final long dischargeCount = getMahDischarge(which);
3164 final long dischargeScreenOffCount = getMahDischargeScreenOff(which);
3165 final long dischargeScreenDozeCount = getMahDischargeScreenDoze(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003166
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003167 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003168
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003169 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003170 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003171
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003172 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003175 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003176 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003177 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003178 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003179 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003180 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003181 getEstimatedBatteryCapacity(),
Mike Mac2f518a2017-09-19 16:06:03 -07003182 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(),
3183 screenDozeTime / 1000);
Adam Lesinski67c134f2016-06-10 15:15:08 -07003184
Bookatzc8c44962017-05-11 12:12:54 -07003185
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003186 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003187 long fullWakeLockTimeTotal = 0;
3188 long partialWakeLockTimeTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003189
Evan Millar22ac0432009-03-31 11:33:18 -07003190 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003191 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003192
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003193 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3194 = u.getWakelockStats();
3195 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3196 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003197
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003198 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3199 if (fullWakeTimer != null) {
3200 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3201 which);
3202 }
3203
3204 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3205 if (partialWakeTimer != null) {
3206 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3207 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003208 }
3209 }
3210 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003211
3212 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003213 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3214 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3215 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3216 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3217 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3218 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3219 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3220 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003221 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3222 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003223 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3224 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003225 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3226 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003227
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003228 // Dump Modem controller stats
3229 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3230 getModemControllerActivity(), which);
3231
Adam Lesinskie283d332015-04-16 12:29:25 -07003232 // Dump Wifi controller stats
3233 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3234 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003235 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003236 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003237
3238 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3239 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003240
3241 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003242 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3243 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245 // Dump misc stats
3246 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003247 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003248 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003249 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003250 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003251 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003252 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3253 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003254 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003255 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3256 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3257 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3258 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003259 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003260
Dianne Hackborn617f8772009-03-31 15:04:46 -07003261 // Dump screen brightness stats
3262 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3263 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003264 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003265 }
3266 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003267
Dianne Hackborn627bba72009-03-24 22:32:56 -07003268 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003269 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3270 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003271 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003272 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003273 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003274 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003275 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003276 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003277 args[i] = getPhoneSignalStrengthCount(i, which);
3278 }
3279 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003280
Dianne Hackborn627bba72009-03-24 22:32:56 -07003281 // Dump network type stats
3282 args = new Object[NUM_DATA_CONNECTION_TYPES];
3283 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003284 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003285 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003286 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3287 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3288 args[i] = getPhoneDataConnectionCount(i, which);
3289 }
3290 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003291
3292 // Dump wifi state stats
3293 args = new Object[NUM_WIFI_STATES];
3294 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003295 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003296 }
3297 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3298 for (int i=0; i<NUM_WIFI_STATES; i++) {
3299 args[i] = getWifiStateCount(i, which);
3300 }
3301 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3302
Dianne Hackborn3251b902014-06-20 14:40:53 -07003303 // Dump wifi suppl state stats
3304 args = new Object[NUM_WIFI_SUPPL_STATES];
3305 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3306 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3307 }
3308 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3309 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3310 args[i] = getWifiSupplStateCount(i, which);
3311 }
3312 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3313
3314 // Dump wifi signal strength stats
3315 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3316 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3317 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3318 }
3319 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3320 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3321 args[i] = getWifiSignalStrengthCount(i, which);
3322 }
3323 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3324
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003325 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003326 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003327 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003328 }
Bookatzc8c44962017-05-11 12:12:54 -07003329
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003330 if (which == STATS_SINCE_UNPLUGGED) {
3331 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3332 getDischargeStartLevel()-getDischargeCurrentLevel(),
3333 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003334 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
Mike Mac2f518a2017-09-19 16:06:03 -07003335 dischargeCount / 1000, dischargeScreenOffCount / 1000,
3336 getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003337 } else {
3338 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3339 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003340 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003341 getDischargeAmountScreenOffSinceCharge(),
Mike Mac2f518a2017-09-19 16:06:03 -07003342 dischargeCount / 1000, dischargeScreenOffCount / 1000,
3343 getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003344 }
Bookatzc8c44962017-05-11 12:12:54 -07003345
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003346 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003347 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003348 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003349 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003350 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003351 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003352 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3353 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003354 }
Evan Millarc64edde2009-04-18 12:26:32 -07003355 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003356 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003357 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003358 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3359 // Not doing the regular wake lock formatting to remain compatible
3360 // with the old checkin format.
3361 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3362 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003363 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003364 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003365 }
3366 }
Evan Millarc64edde2009-04-18 12:26:32 -07003367 }
Bookatzc8c44962017-05-11 12:12:54 -07003368
Bookatz50df7112017-08-04 14:53:26 -07003369 final Map<String, ? extends Timer> rpmStats = getRpmStats();
3370 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
3371 if (rpmStats.size() > 0) {
3372 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
3373 sb.setLength(0);
3374 Timer totalTimer = ent.getValue();
3375 long timeMs = (totalTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3376 int count = totalTimer.getCountLocked(which);
3377 Timer screenOffTimer = screenOffRpmStats.get(ent.getKey());
3378 long screenOffTimeMs = screenOffTimer != null
3379 ? (screenOffTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
3380 int screenOffCount = screenOffTimer != null
3381 ? screenOffTimer.getCountLocked(which) : 0;
Bookatz82b341172017-09-07 19:06:08 -07003382 if (SCREEN_OFF_RPM_STATS_ENABLED) {
3383 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3384 "\"" + ent.getKey() + "\"", timeMs, count, screenOffTimeMs,
3385 screenOffCount);
3386 } else {
3387 dumpLine(pw, 0 /* uid */, category, RESOURCE_POWER_MANAGER_DATA,
3388 "\"" + ent.getKey() + "\"", timeMs, count);
3389 }
Bookatz50df7112017-08-04 14:53:26 -07003390 }
3391 }
3392
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003393 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003394 helper.create(this);
3395 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003396 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003397 if (sippers != null && sippers.size() > 0) {
3398 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3399 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003400 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003401 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3402 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3403 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003404 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003405 int uid = 0;
3406 String label;
3407 switch (bs.drainType) {
3408 case IDLE:
3409 label="idle";
3410 break;
3411 case CELL:
3412 label="cell";
3413 break;
3414 case PHONE:
3415 label="phone";
3416 break;
3417 case WIFI:
3418 label="wifi";
3419 break;
3420 case BLUETOOTH:
3421 label="blue";
3422 break;
3423 case SCREEN:
3424 label="scrn";
3425 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003426 case FLASHLIGHT:
3427 label="flashlight";
3428 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003429 case APP:
3430 uid = bs.uidObj.getUid();
3431 label = "uid";
3432 break;
3433 case USER:
3434 uid = UserHandle.getUid(bs.userId, 0);
3435 label = "user";
3436 break;
3437 case UNACCOUNTED:
3438 label = "unacc";
3439 break;
3440 case OVERCOUNTED:
3441 label = "over";
3442 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003443 case CAMERA:
3444 label = "camera";
3445 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003446 default:
3447 label = "???";
3448 }
3449 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Bookatz17d7d9d2017-06-08 14:50:46 -07003450 BatteryStatsHelper.makemAh(bs.totalPowerMah),
3451 bs.shouldHide ? 1 : 0,
3452 BatteryStatsHelper.makemAh(bs.screenPowerMah),
3453 BatteryStatsHelper.makemAh(bs.proportionalSmearMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003454 }
3455 }
3456
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003457 final long[] cpuFreqs = getCpuFreqs();
3458 if (cpuFreqs != null) {
3459 sb.setLength(0);
3460 for (int i = 0; i < cpuFreqs.length; ++i) {
3461 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3462 }
3463 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3464 }
3465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 for (int iu = 0; iu < NU; iu++) {
3467 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003468 if (reqUid >= 0 && uid != reqUid) {
3469 continue;
3470 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003471 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003474 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3475 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3476 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3477 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3478 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3479 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3480 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3481 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003482 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003483 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3484 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003485 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003486 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3487 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003488 // Background data transfers
3489 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3490 which);
3491 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3492 which);
3493 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3494 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3495 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3496 which);
3497 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3498 which);
3499 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3500 which);
3501 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3502 which);
3503
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003504 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3505 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003506 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003507 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3508 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3509 || wifiBytesBgTx > 0
3510 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3511 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003512 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3513 wifiBytesRx, wifiBytesTx,
3514 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003515 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003516 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003517 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3518 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3519 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3520 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003521 }
3522
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003523 // Dump modem controller data, per UID.
3524 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3525 u.getModemControllerActivity(), which);
3526
3527 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003528 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3529 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3530 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003531 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3532 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003533 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3534 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3535 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003536 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003537 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003538 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3539 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003540 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3541 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003542 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003543 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003544 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003546 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3547 u.getWifiControllerActivity(), which);
3548
Bookatz867c0d72017-03-07 18:23:42 -08003549 final Timer bleTimer = u.getBluetoothScanTimer();
3550 if (bleTimer != null) {
3551 // Convert from microseconds to milliseconds with rounding
3552 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3553 / 1000;
3554 if (totalTime != 0) {
3555 final int count = bleTimer.getCountLocked(which);
3556 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3557 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003558 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3559 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3560 final long actualTimeBg = bleTimerBg != null ?
3561 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003562 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07003563 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3564 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07003565 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
3566 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
3567 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
3568 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
3569 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
3570 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3571 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
3572 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3573 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
3574 final Timer unoptimizedScanTimerBg =
3575 u.getBluetoothUnoptimizedScanBackgroundTimer();
3576 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
3577 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3578 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
3579 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
3580
Bookatz867c0d72017-03-07 18:23:42 -08003581 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatzb1f04f32017-05-19 13:57:32 -07003582 countBg, actualTime, actualTimeBg, resultCount, resultCountBg,
3583 unoptimizedScanTotalTime, unoptimizedScanTotalTimeBg,
3584 unoptimizedScanMaxTime, unoptimizedScanMaxTimeBg);
Bookatz867c0d72017-03-07 18:23:42 -08003585 }
3586 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003587
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003588 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3589 u.getBluetoothControllerActivity(), which);
3590
Dianne Hackborn617f8772009-03-31 15:04:46 -07003591 if (u.hasUserActivity()) {
3592 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3593 boolean hasData = false;
3594 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3595 int val = u.getUserActivityCount(i, which);
3596 args[i] = val;
3597 if (val != 0) hasData = true;
3598 }
3599 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003600 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003601 }
3602 }
Bookatzc8c44962017-05-11 12:12:54 -07003603
3604 if (u.getAggregatedPartialWakelockTimer() != null) {
3605 final Timer timer = u.getAggregatedPartialWakelockTimer();
Bookatz6d799932017-06-07 12:30:07 -07003606 // Times are since reset (regardless of 'which')
3607 final long totTimeMs = timer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07003608 final Timer bgTimer = timer.getSubTimer();
3609 final long bgTimeMs = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003610 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07003611 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3612 }
3613
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003614 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3615 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3616 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3617 String linePrefix = "";
3618 sb.setLength(0);
3619 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3620 rawRealtime, "f", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003621 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3622 linePrefix = printWakeLockCheckin(sb, pTimer,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003623 rawRealtime, "p", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003624 linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null,
3625 rawRealtime, "bp", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003626 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3627 rawRealtime, "w", which, linePrefix);
3628
3629 // Only log if we had at lease one wakelock...
3630 if (sb.length() > 0) {
3631 String name = wakelocks.keyAt(iw);
3632 if (name.indexOf(',') >= 0) {
3633 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 }
Yi Jin02483362017-08-04 11:30:44 -07003635 if (name.indexOf('\n') >= 0) {
3636 name = name.replace('\n', '_');
3637 }
3638 if (name.indexOf('\r') >= 0) {
3639 name = name.replace('\r', '_');
3640 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003641 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 }
3643 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003644
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003645 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3646 for (int isy=syncs.size()-1; isy>=0; isy--) {
3647 final Timer timer = syncs.valueAt(isy);
3648 // Convert from microseconds to milliseconds with rounding
3649 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3650 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003651 final Timer bgTimer = timer.getSubTimer();
3652 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003653 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07003654 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003655 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003656 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003657 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003658 }
3659 }
3660
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003661 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3662 for (int ij=jobs.size()-1; ij>=0; ij--) {
3663 final Timer timer = jobs.valueAt(ij);
3664 // Convert from microseconds to milliseconds with rounding
3665 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3666 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003667 final Timer bgTimer = timer.getSubTimer();
3668 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07003669 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07003670 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003671 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003672 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003673 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003674 }
3675 }
3676
Dianne Hackborn94326cb2017-06-28 16:17:20 -07003677 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
3678 for (int ic=completions.size()-1; ic>=0; ic--) {
3679 SparseIntArray types = completions.valueAt(ic);
3680 if (types != null) {
3681 dumpLine(pw, uid, category, JOB_COMPLETION_DATA,
3682 "\"" + completions.keyAt(ic) + "\"",
3683 types.get(JobParameters.REASON_CANCELED, 0),
3684 types.get(JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED, 0),
3685 types.get(JobParameters.REASON_PREEMPT, 0),
3686 types.get(JobParameters.REASON_TIMEOUT, 0),
3687 types.get(JobParameters.REASON_DEVICE_IDLE, 0));
3688 }
3689 }
3690
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003691 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3692 rawRealtime, which);
3693 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3694 rawRealtime, which);
3695 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3696 rawRealtime, which);
3697 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3698 rawRealtime, which);
3699
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003700 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3701 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003702 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003703 final Uid.Sensor se = sensors.valueAt(ise);
3704 final int sensorNumber = sensors.keyAt(ise);
3705 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003706 if (timer != null) {
3707 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003708 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3709 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003710 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003711 final int count = timer.getCountLocked(which);
3712 final Timer bgTimer = se.getSensorBackgroundTime();
3713 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003714 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3715 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3716 final long bgActualTime = bgTimer != null ?
3717 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3718 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3719 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003720 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003721 }
3722 }
3723
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003724 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3725 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003726
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07003727 dumpTimer(pw, uid, category, FOREGROUND_ACTIVITY_DATA, u.getForegroundActivityTimer(),
3728 rawRealtime, which);
3729
3730 dumpTimer(pw, uid, category, FOREGROUND_SERVICE_DATA, u.getForegroundServiceTimer(),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003731 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003732
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003733 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003734 long totalStateTime = 0;
3735 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003736 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3737 totalStateTime += time;
3738 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003739 }
3740 if (totalStateTime > 0) {
3741 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3742 }
3743
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003744 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3745 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003746 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003747 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003748 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003749 }
3750
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003751 // If the cpuFreqs is null, then don't bother checking for cpu freq times.
3752 if (cpuFreqs != null) {
3753 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3754 // If total cpuFreqTimes is null, then we don't need to check for
3755 // screenOffCpuFreqTimes.
3756 if (cpuFreqTimeMs != null && cpuFreqTimeMs.length == cpuFreqs.length) {
3757 sb.setLength(0);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003758 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003759 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003760 }
Sudheer Shankaa87245d2017-08-10 12:02:31 -07003761 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3762 if (screenOffCpuFreqTimeMs != null) {
3763 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3764 sb.append("," + screenOffCpuFreqTimeMs[i]);
3765 }
3766 } else {
3767 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3768 sb.append(",0");
3769 }
3770 }
3771 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
3772 cpuFreqTimeMs.length, sb.toString());
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003773 }
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003774 }
3775
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003776 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3777 = u.getProcessStats();
3778 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3779 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003780
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003781 final long userMillis = ps.getUserTime(which);
3782 final long systemMillis = ps.getSystemTime(which);
3783 final long foregroundMillis = ps.getForegroundTime(which);
3784 final int starts = ps.getStarts(which);
3785 final int numCrashes = ps.getNumCrashes(which);
3786 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003787
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003788 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3789 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003790 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
3791 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003792 }
3793 }
3794
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003795 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3796 = u.getPackageStats();
3797 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3798 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3799 int wakeups = 0;
3800 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3801 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003802 int count = alarms.valueAt(iwa).getCountLocked(which);
3803 wakeups += count;
3804 String name = alarms.keyAt(iwa).replace(',', '_');
3805 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003806 }
3807 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3808 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3809 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3810 final long startTime = ss.getStartTime(batteryUptime, which);
3811 final int starts = ss.getStarts(which);
3812 final int launches = ss.getLaunches(which);
3813 if (startTime != 0 || starts != 0 || launches != 0) {
3814 dumpLine(pw, uid, category, APK_DATA,
3815 wakeups, // wakeup alarms
3816 packageStats.keyAt(ipkg), // Apk
3817 serviceStats.keyAt(isvc), // service
3818 startTime / 1000, // time spent started, in ms
3819 starts,
3820 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 }
3822 }
3823 }
3824 }
3825 }
3826
Dianne Hackborn81038902012-11-26 17:04:09 -08003827 static final class TimerEntry {
3828 final String mName;
3829 final int mId;
3830 final BatteryStats.Timer mTimer;
3831 final long mTime;
3832 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3833 mName = name;
3834 mId = id;
3835 mTimer = timer;
3836 mTime = time;
3837 }
3838 }
3839
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003840 private void printmAh(PrintWriter printer, double power) {
3841 printer.print(BatteryStatsHelper.makemAh(power));
3842 }
3843
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003844 private void printmAh(StringBuilder sb, double power) {
3845 sb.append(BatteryStatsHelper.makemAh(power));
3846 }
3847
Dianne Hackbornd953c532014-08-16 18:17:38 -07003848 /**
3849 * Temporary for settings.
3850 */
3851 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3852 int reqUid) {
3853 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3854 }
3855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003857 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003858 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3860 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
Bookatz6d799932017-06-07 12:30:07 -07003861 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003862 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003863
3864 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3865 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3866 final long totalRealtime = computeRealtime(rawRealtime, which);
3867 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003868 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3869 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3870 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003871 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3872 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Mike Mac2f518a2017-09-19 16:06:03 -07003873 final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003874
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003875 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003876
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003877 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003878 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003880 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3881 if (estimatedBatteryCapacity > 0) {
3882 sb.setLength(0);
3883 sb.append(prefix);
3884 sb.append(" Estimated battery capacity: ");
3885 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3886 sb.append(" mAh");
3887 pw.println(sb.toString());
3888 }
3889
Jocelyn Dangc627d102017-04-14 13:15:14 -07003890 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
3891 if (minLearnedBatteryCapacity > 0) {
3892 sb.setLength(0);
3893 sb.append(prefix);
3894 sb.append(" Min learned battery capacity: ");
3895 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
3896 sb.append(" mAh");
3897 pw.println(sb.toString());
3898 }
3899 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
3900 if (maxLearnedBatteryCapacity > 0) {
3901 sb.setLength(0);
3902 sb.append(prefix);
3903 sb.append(" Max learned battery capacity: ");
3904 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
3905 sb.append(" mAh");
3906 pw.println(sb.toString());
3907 }
3908
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003909 sb.setLength(0);
3910 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07003911 sb.append(" Time on battery: ");
3912 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3913 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3914 sb.append(") realtime, ");
3915 formatTimeMs(sb, whichBatteryUptime / 1000);
3916 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime));
3917 sb.append(") uptime");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003918 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07003919
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003920 sb.setLength(0);
3921 sb.append(prefix);
Mike Mac2f518a2017-09-19 16:06:03 -07003922 sb.append(" Time on battery screen off: ");
3923 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3924 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime));
3925 sb.append(") realtime, ");
3926 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3927 sb.append("(");
3928 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime));
3929 sb.append(") uptime");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003930 pw.println(sb.toString());
Mike Mac2f518a2017-09-19 16:06:03 -07003931
3932 sb.setLength(0);
3933 sb.append(prefix);
3934 sb.append(" Time on battery screen doze: ");
3935 formatTimeMs(sb, screenDozeTime / 1000); sb.append("(");
3936 sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime));
3937 sb.append(")");
3938 pw.println(sb.toString());
3939
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003940 sb.setLength(0);
3941 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003942 sb.append(" Total run time: ");
3943 formatTimeMs(sb, totalRealtime / 1000);
3944 sb.append("realtime, ");
3945 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003946 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003947 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003948 if (batteryTimeRemaining >= 0) {
3949 sb.setLength(0);
3950 sb.append(prefix);
3951 sb.append(" Battery time remaining: ");
3952 formatTimeMs(sb, batteryTimeRemaining / 1000);
3953 pw.println(sb.toString());
3954 }
3955 if (chargeTimeRemaining >= 0) {
3956 sb.setLength(0);
3957 sb.append(prefix);
3958 sb.append(" Charge time remaining: ");
3959 formatTimeMs(sb, chargeTimeRemaining / 1000);
3960 pw.println(sb.toString());
3961 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003962
Mike Mac2f518a2017-09-19 16:06:03 -07003963 final long dischargeCount = getMahDischarge(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003964 if (dischargeCount >= 0) {
3965 sb.setLength(0);
3966 sb.append(prefix);
3967 sb.append(" Discharge: ");
3968 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3969 sb.append(" mAh");
3970 pw.println(sb.toString());
3971 }
3972
Mike Mac2f518a2017-09-19 16:06:03 -07003973 final long dischargeScreenOffCount = getMahDischargeScreenOff(which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003974 if (dischargeScreenOffCount >= 0) {
3975 sb.setLength(0);
3976 sb.append(prefix);
3977 sb.append(" Screen off discharge: ");
3978 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3979 sb.append(" mAh");
3980 pw.println(sb.toString());
3981 }
3982
Mike Mac2f518a2017-09-19 16:06:03 -07003983 final long dischargeScreenDozeCount = getMahDischargeScreenDoze(which);
3984 if (dischargeScreenDozeCount >= 0) {
3985 sb.setLength(0);
3986 sb.append(prefix);
3987 sb.append(" Screen doze discharge: ");
3988 sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0));
3989 sb.append(" mAh");
3990 pw.println(sb.toString());
3991 }
3992
3993 final long dischargeScreenOnCount =
3994 dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount;
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003995 if (dischargeScreenOnCount >= 0) {
3996 sb.setLength(0);
3997 sb.append(prefix);
3998 sb.append(" Screen on discharge: ");
3999 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
4000 sb.append(" mAh");
4001 pw.println(sb.toString());
4002 }
4003
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08004004 pw.print(" Start clock time: ");
4005 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
4006
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004007 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07004008 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004009 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004010 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
4011 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004012 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004013 rawRealtime, which);
4014 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
4015 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004016 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004017 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004018 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
4019 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
4020 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004021 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004022 sb.append(prefix);
4023 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
4024 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004025 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004026 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
4027 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07004028 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004029 pw.println(sb.toString());
4030 sb.setLength(0);
4031 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004032 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004033 boolean didOne = false;
4034 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004035 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004036 if (time == 0) {
4037 continue;
4038 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004039 sb.append("\n ");
4040 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004041 didOne = true;
4042 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
4043 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004044 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004045 sb.append("(");
4046 sb.append(formatRatioLocked(time, screenOnTime));
4047 sb.append(")");
4048 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004049 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004050 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004051 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004052 sb.setLength(0);
4053 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004054 sb.append(" Power save mode enabled: ");
4055 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004056 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004057 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004058 sb.append(")");
4059 pw.println(sb.toString());
4060 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004061 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004062 sb.setLength(0);
4063 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004064 sb.append(" Device light idling: ");
4065 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004066 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004067 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
4068 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004069 sb.append("x");
4070 pw.println(sb.toString());
4071 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004072 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004073 sb.setLength(0);
4074 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004075 sb.append(" Idle mode light time: ");
4076 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004077 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004078 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
4079 sb.append(") ");
4080 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004081 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004082 sb.append(" -- longest ");
4083 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
4084 pw.println(sb.toString());
4085 }
4086 if (deviceIdlingTime != 0) {
4087 sb.setLength(0);
4088 sb.append(prefix);
4089 sb.append(" Device full idling: ");
4090 formatTimeMs(sb, deviceIdlingTime / 1000);
4091 sb.append("(");
4092 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004093 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004094 sb.append("x");
4095 pw.println(sb.toString());
4096 }
4097 if (deviceIdleModeFullTime != 0) {
4098 sb.setLength(0);
4099 sb.append(prefix);
4100 sb.append(" Idle mode full time: ");
4101 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
4102 sb.append("(");
4103 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
4104 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004105 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07004106 sb.append("x");
4107 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07004108 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004109 pw.println(sb.toString());
4110 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004111 if (phoneOnTime != 0) {
4112 sb.setLength(0);
4113 sb.append(prefix);
4114 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
4115 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004116 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004117 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004118 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08004119 if (connChanges != 0) {
4120 pw.print(prefix);
4121 pw.print(" Connectivity changes: "); pw.println(connChanges);
4122 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004123
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004124 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07004125 long fullWakeLockTimeTotalMicros = 0;
4126 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08004127
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004128 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08004129
Evan Millar22ac0432009-03-31 11:33:18 -07004130 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004131 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004132
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004133 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4134 = u.getWakelockStats();
4135 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4136 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07004137
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004138 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
4139 if (fullWakeTimer != null) {
4140 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
4141 rawRealtime, which);
4142 }
4143
4144 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4145 if (partialWakeTimer != null) {
4146 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
4147 rawRealtime, which);
4148 if (totalTimeMicros > 0) {
4149 if (reqUid < 0) {
4150 // Only show the ordered list of all wake
4151 // locks if the caller is not asking for data
4152 // about a specific uid.
4153 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
4154 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08004155 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004156 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07004157 }
4158 }
4159 }
4160 }
Bookatzc8c44962017-05-11 12:12:54 -07004161
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004162 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4163 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4164 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4165 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
4166 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4167 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
4168 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4169 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004170 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4171 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004172
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004173 if (fullWakeLockTimeTotalMicros != 0) {
4174 sb.setLength(0);
4175 sb.append(prefix);
4176 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
4177 (fullWakeLockTimeTotalMicros + 500) / 1000);
4178 pw.println(sb.toString());
4179 }
4180
4181 if (partialWakeLockTimeTotalMicros != 0) {
4182 sb.setLength(0);
4183 sb.append(prefix);
4184 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
4185 (partialWakeLockTimeTotalMicros + 500) / 1000);
4186 pw.println(sb.toString());
4187 }
4188
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004189 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004190 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
4191 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
4192 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
4193 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004194 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004195 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004196 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004197 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08004198 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004199 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004200 if (time == 0) {
4201 continue;
4202 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004203 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004204 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004205 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08004206 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004207 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004208 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004209 sb.append("(");
4210 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004211 sb.append(") ");
4212 sb.append(getPhoneSignalStrengthCount(i, which));
4213 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004214 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004215 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004216 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004217
4218 sb.setLength(0);
4219 sb.append(prefix);
4220 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004221 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07004222 pw.println(sb.toString());
4223
Dianne Hackborn627bba72009-03-24 22:32:56 -07004224 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004225 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004226 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004227 didOne = false;
4228 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004229 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004230 if (time == 0) {
4231 continue;
4232 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004233 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004234 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004235 didOne = true;
4236 sb.append(DATA_CONNECTION_NAMES[i]);
4237 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004238 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004239 sb.append("(");
4240 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004241 sb.append(") ");
4242 sb.append(getPhoneDataConnectionCount(i, which));
4243 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004244 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004245 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004246 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004247
4248 sb.setLength(0);
4249 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08004250 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004251 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004252 formatTimeMs(sb, mobileActiveTime / 1000);
4253 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4254 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
4255 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004256 pw.println(sb.toString());
4257
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004258 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
4259 if (mobileActiveUnknownTime != 0) {
4260 sb.setLength(0);
4261 sb.append(prefix);
4262 sb.append(" Mobile radio active unknown time: ");
4263 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
4264 sb.append("(");
4265 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
4266 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
4267 sb.append("x");
4268 pw.println(sb.toString());
4269 }
4270
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004271 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
4272 if (mobileActiveAdjustedTime != 0) {
4273 sb.setLength(0);
4274 sb.append(prefix);
4275 sb.append(" Mobile radio active adjusted time: ");
4276 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
4277 sb.append("(");
4278 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
4279 sb.append(")");
4280 pw.println(sb.toString());
4281 }
4282
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004283 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
4284
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004285 pw.print(prefix);
4286 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
4287 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
4288 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
4289 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004290 sb.setLength(0);
4291 sb.append(prefix);
4292 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
4293 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
4294 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
4295 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004296 sb.append(")");
4297 pw.println(sb.toString());
4298
4299 sb.setLength(0);
4300 sb.append(prefix);
4301 sb.append(" Wifi states:");
4302 didOne = false;
4303 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004304 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004305 if (time == 0) {
4306 continue;
4307 }
4308 sb.append("\n ");
4309 didOne = true;
4310 sb.append(WIFI_STATE_NAMES[i]);
4311 sb.append(" ");
4312 formatTimeMs(sb, time/1000);
4313 sb.append("(");
4314 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4315 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004316 sb.append(getWifiStateCount(i, which));
4317 sb.append("x");
4318 }
4319 if (!didOne) sb.append(" (no activity)");
4320 pw.println(sb.toString());
4321
4322 sb.setLength(0);
4323 sb.append(prefix);
4324 sb.append(" Wifi supplicant states:");
4325 didOne = false;
4326 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4327 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4328 if (time == 0) {
4329 continue;
4330 }
4331 sb.append("\n ");
4332 didOne = true;
4333 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4334 sb.append(" ");
4335 formatTimeMs(sb, time/1000);
4336 sb.append("(");
4337 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4338 sb.append(") ");
4339 sb.append(getWifiSupplStateCount(i, which));
4340 sb.append("x");
4341 }
4342 if (!didOne) sb.append(" (no activity)");
4343 pw.println(sb.toString());
4344
4345 sb.setLength(0);
4346 sb.append(prefix);
4347 sb.append(" Wifi signal levels:");
4348 didOne = false;
4349 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
4350 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4351 if (time == 0) {
4352 continue;
4353 }
4354 sb.append("\n ");
4355 sb.append(prefix);
4356 didOne = true;
4357 sb.append("level(");
4358 sb.append(i);
4359 sb.append(") ");
4360 formatTimeMs(sb, time/1000);
4361 sb.append("(");
4362 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4363 sb.append(") ");
4364 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004365 sb.append("x");
4366 }
4367 if (!didOne) sb.append(" (no activity)");
4368 pw.println(sb.toString());
4369
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004370 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004371
Adam Lesinski50e47602015-12-04 17:04:54 -08004372 pw.print(prefix);
4373 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4374 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4375
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004376 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4377 sb.setLength(0);
4378 sb.append(prefix);
4379 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4380 pw.println(sb.toString());
4381
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004382 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4383 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004384
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004385 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004386
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004387 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004388 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004389 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004390 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004391 pw.println(getDischargeStartLevel());
4392 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4393 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004394 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004395 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004396 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004397 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004398 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004399 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004400 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004401 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004402 pw.println(getDischargeAmountScreenOn());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004403 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004404 pw.println(getDischargeAmountScreenOff());
4405 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4406 pw.println(getDischargeAmountScreenDoze());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004407 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004408 } else {
4409 pw.print(prefix); pw.println(" Device battery use since last full charge");
4410 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004411 pw.println(getLowDischargeAmountSinceCharge());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004412 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
Mike Mac2f518a2017-09-19 16:06:03 -07004413 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004414 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004415 pw.println(getDischargeAmountScreenOnSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004416 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
Mike Mac2f518a2017-09-19 16:06:03 -07004417 pw.println(getDischargeAmountScreenOffSinceCharge());
4418 pw.print(prefix); pw.print(" Amount discharged while screen doze: ");
4419 pw.println(getDischargeAmountScreenDozeSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004420 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004421 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004422
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004423 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004424 helper.create(this);
4425 helper.refreshStats(which, UserHandle.USER_ALL);
4426 List<BatterySipper> sippers = helper.getUsageList();
4427 if (sippers != null && sippers.size() > 0) {
4428 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4429 pw.print(prefix); pw.print(" Capacity: ");
4430 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004431 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004432 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4433 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4434 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4435 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004436 pw.println();
4437 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004438 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004439 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004440 switch (bs.drainType) {
4441 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004442 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004443 break;
4444 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004445 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004446 break;
4447 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004448 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004449 break;
4450 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004451 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004452 break;
4453 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004454 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004455 break;
4456 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004457 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004458 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004459 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004460 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004461 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004462 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004463 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004464 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004465 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004466 break;
4467 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004468 pw.print(" User "); pw.print(bs.userId);
4469 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004470 break;
4471 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004472 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004473 break;
4474 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004475 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004476 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004477 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004478 pw.print(" Camera: ");
4479 break;
4480 default:
4481 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004482 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004483 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004484 printmAh(pw, bs.totalPowerMah);
4485
Adam Lesinski57123002015-06-12 16:12:07 -07004486 if (bs.usagePowerMah != bs.totalPowerMah) {
4487 // If the usage (generic power) isn't the whole amount, we list out
4488 // what components are involved in the calculation.
4489
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004490 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004491 if (bs.usagePowerMah != 0) {
4492 pw.print(" usage=");
4493 printmAh(pw, bs.usagePowerMah);
4494 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004495 if (bs.cpuPowerMah != 0) {
4496 pw.print(" cpu=");
4497 printmAh(pw, bs.cpuPowerMah);
4498 }
4499 if (bs.wakeLockPowerMah != 0) {
4500 pw.print(" wake=");
4501 printmAh(pw, bs.wakeLockPowerMah);
4502 }
4503 if (bs.mobileRadioPowerMah != 0) {
4504 pw.print(" radio=");
4505 printmAh(pw, bs.mobileRadioPowerMah);
4506 }
4507 if (bs.wifiPowerMah != 0) {
4508 pw.print(" wifi=");
4509 printmAh(pw, bs.wifiPowerMah);
4510 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004511 if (bs.bluetoothPowerMah != 0) {
4512 pw.print(" bt=");
4513 printmAh(pw, bs.bluetoothPowerMah);
4514 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004515 if (bs.gpsPowerMah != 0) {
4516 pw.print(" gps=");
4517 printmAh(pw, bs.gpsPowerMah);
4518 }
4519 if (bs.sensorPowerMah != 0) {
4520 pw.print(" sensor=");
4521 printmAh(pw, bs.sensorPowerMah);
4522 }
4523 if (bs.cameraPowerMah != 0) {
4524 pw.print(" camera=");
4525 printmAh(pw, bs.cameraPowerMah);
4526 }
4527 if (bs.flashlightPowerMah != 0) {
4528 pw.print(" flash=");
4529 printmAh(pw, bs.flashlightPowerMah);
4530 }
4531 pw.print(" )");
4532 }
Bookatz17d7d9d2017-06-08 14:50:46 -07004533
4534 // If there is additional smearing information, include it.
4535 if (bs.totalSmearedPowerMah != bs.totalPowerMah) {
4536 pw.print(" Including smearing: ");
4537 printmAh(pw, bs.totalSmearedPowerMah);
4538 pw.print(" (");
4539 if (bs.screenPowerMah != 0) {
4540 pw.print(" screen=");
4541 printmAh(pw, bs.screenPowerMah);
4542 }
4543 if (bs.proportionalSmearMah != 0) {
4544 pw.print(" proportional=");
4545 printmAh(pw, bs.proportionalSmearMah);
4546 }
4547 pw.print(" )");
4548 }
4549 if (bs.shouldHide) {
4550 pw.print(" Excluded from smearing");
4551 }
4552
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004553 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004554 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004555 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004556 }
4557
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004558 sippers = helper.getMobilemsppList();
4559 if (sippers != null && sippers.size() > 0) {
4560 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004561 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004562 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004563 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004564 sb.setLength(0);
4565 sb.append(prefix); sb.append(" Uid ");
4566 UserHandle.formatUid(sb, bs.uidObj.getUid());
4567 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4568 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4569 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004570 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004571 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004572 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004573 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004574 sb.setLength(0);
4575 sb.append(prefix);
4576 sb.append(" TOTAL TIME: ");
4577 formatTimeMs(sb, totalTime);
4578 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4579 sb.append(")");
4580 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004581 pw.println();
4582 }
4583
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004584 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4585 @Override
4586 public int compare(TimerEntry lhs, TimerEntry rhs) {
4587 long lhsTime = lhs.mTime;
4588 long rhsTime = rhs.mTime;
4589 if (lhsTime < rhsTime) {
4590 return 1;
4591 }
4592 if (lhsTime > rhsTime) {
4593 return -1;
4594 }
4595 return 0;
4596 }
4597 };
4598
4599 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004600 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4601 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004602 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004603 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4604 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4605 : kernelWakelocks.entrySet()) {
4606 final BatteryStats.Timer timer = ent.getValue();
4607 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004608 if (totalTimeMillis > 0) {
4609 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4610 }
4611 }
4612 if (ktimers.size() > 0) {
4613 Collections.sort(ktimers, timerComparator);
4614 pw.print(prefix); pw.println(" All kernel wake locks:");
4615 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004616 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004617 String linePrefix = ": ";
4618 sb.setLength(0);
4619 sb.append(prefix);
4620 sb.append(" Kernel Wake lock ");
4621 sb.append(timer.mName);
4622 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4623 which, linePrefix);
4624 if (!linePrefix.equals(": ")) {
4625 sb.append(" realtime");
4626 // Only print out wake locks that were held
4627 pw.println(sb.toString());
4628 }
4629 }
4630 pw.println();
4631 }
4632 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004633
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004634 if (timers.size() > 0) {
4635 Collections.sort(timers, timerComparator);
4636 pw.print(prefix); pw.println(" All partial wake locks:");
4637 for (int i=0; i<timers.size(); i++) {
4638 TimerEntry timer = timers.get(i);
4639 sb.setLength(0);
4640 sb.append(" Wake lock ");
4641 UserHandle.formatUid(sb, timer.mId);
4642 sb.append(" ");
4643 sb.append(timer.mName);
4644 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4645 sb.append(" realtime");
4646 pw.println(sb.toString());
4647 }
4648 timers.clear();
4649 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004650 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004651
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004652 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004653 if (wakeupReasons.size() > 0) {
4654 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004655 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004656 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004657 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004658 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4659 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004660 }
4661 Collections.sort(reasons, timerComparator);
4662 for (int i=0; i<reasons.size(); i++) {
4663 TimerEntry timer = reasons.get(i);
4664 String linePrefix = ": ";
4665 sb.setLength(0);
4666 sb.append(prefix);
4667 sb.append(" Wakeup reason ");
4668 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004669 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4670 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004671 pw.println(sb.toString());
4672 }
4673 pw.println();
4674 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004675 }
Evan Millar22ac0432009-03-31 11:33:18 -07004676
James Carr2dd7e5e2016-07-20 18:48:39 -07004677 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
Bookatz50df7112017-08-04 14:53:26 -07004678 if (mMemoryStats.size() > 0) {
4679 pw.println(" Memory Stats");
4680 for (int i = 0; i < mMemoryStats.size(); i++) {
4681 sb.setLength(0);
4682 sb.append(" Bandwidth ");
4683 sb.append(mMemoryStats.keyAt(i));
4684 sb.append(" Time ");
4685 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4686 pw.println(sb.toString());
4687 }
4688 pw.println();
4689 }
4690
4691 final Map<String, ? extends Timer> rpmStats = getRpmStats();
4692 if (rpmStats.size() > 0) {
4693 pw.print(prefix); pw.println(" Resource Power Manager Stats");
4694 if (rpmStats.size() > 0) {
4695 for (Map.Entry<String, ? extends Timer> ent : rpmStats.entrySet()) {
4696 final String timerName = ent.getKey();
4697 final Timer timer = ent.getValue();
4698 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4699 }
4700 }
4701 pw.println();
4702 }
Bookatz82b341172017-09-07 19:06:08 -07004703 if (SCREEN_OFF_RPM_STATS_ENABLED) {
4704 final Map<String, ? extends Timer> screenOffRpmStats = getScreenOffRpmStats();
Bookatz50df7112017-08-04 14:53:26 -07004705 if (screenOffRpmStats.size() > 0) {
Bookatz82b341172017-09-07 19:06:08 -07004706 pw.print(prefix);
4707 pw.println(" Resource Power Manager Stats for when screen was off");
4708 if (screenOffRpmStats.size() > 0) {
4709 for (Map.Entry<String, ? extends Timer> ent : screenOffRpmStats.entrySet()) {
4710 final String timerName = ent.getKey();
4711 final Timer timer = ent.getValue();
4712 printTimer(pw, sb, timer, rawRealtime, which, prefix, timerName);
4713 }
Bookatz50df7112017-08-04 14:53:26 -07004714 }
Bookatz82b341172017-09-07 19:06:08 -07004715 pw.println();
Bookatz50df7112017-08-04 14:53:26 -07004716 }
James Carr2dd7e5e2016-07-20 18:48:39 -07004717 }
4718
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004719 final long[] cpuFreqs = getCpuFreqs();
4720 if (cpuFreqs != null) {
4721 sb.setLength(0);
Bookatz50df7112017-08-04 14:53:26 -07004722 sb.append(" CPU freqs:");
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004723 for (int i = 0; i < cpuFreqs.length; ++i) {
4724 sb.append(" " + cpuFreqs[i]);
4725 }
4726 pw.println(sb.toString());
Bookatz50df7112017-08-04 14:53:26 -07004727 pw.println();
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004728 }
4729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004730 for (int iu=0; iu<NU; iu++) {
4731 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004732 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004733 continue;
4734 }
Bookatzc8c44962017-05-11 12:12:54 -07004735
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004736 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004737
4738 pw.print(prefix);
4739 pw.print(" ");
4740 UserHandle.formatUid(pw, uid);
4741 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004742 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004743
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004744 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4745 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4746 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4747 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004748 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4749 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4750
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004751 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4752 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004753 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4754 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004755
4756 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4757 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4758
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004759 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4760 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4761 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08004762 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
4763 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4764 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
4765 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004766 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004767
Adam Lesinski5f056f62016-07-14 16:56:08 -07004768 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4769 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4770
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004771 if (mobileRxBytes > 0 || mobileTxBytes > 0
4772 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004773 pw.print(prefix); pw.print(" Mobile network: ");
4774 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004775 pw.print(formatBytesLocked(mobileTxBytes));
4776 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4777 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004778 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004779 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4780 sb.setLength(0);
4781 sb.append(prefix); sb.append(" Mobile radio active: ");
4782 formatTimeMs(sb, uidMobileActiveTime / 1000);
4783 sb.append("(");
4784 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4785 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4786 long packets = mobileRxPackets + mobileTxPackets;
4787 if (packets == 0) {
4788 packets = 1;
4789 }
4790 sb.append(" @ ");
4791 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4792 sb.append(" mspp");
4793 pw.println(sb.toString());
4794 }
4795
Adam Lesinski5f056f62016-07-14 16:56:08 -07004796 if (mobileWakeup > 0) {
4797 sb.setLength(0);
4798 sb.append(prefix);
4799 sb.append(" Mobile radio AP wakeups: ");
4800 sb.append(mobileWakeup);
4801 pw.println(sb.toString());
4802 }
4803
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004804 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4805 u.getModemControllerActivity(), which);
4806
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004807 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004808 pw.print(prefix); pw.print(" Wi-Fi network: ");
4809 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004810 pw.print(formatBytesLocked(wifiTxBytes));
4811 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4812 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004813 }
4814
Dianne Hackborn62793e42015-03-09 11:15:41 -07004815 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08004816 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004817 || uidWifiRunningTime != 0) {
4818 sb.setLength(0);
4819 sb.append(prefix); sb.append(" Wifi Running: ");
4820 formatTimeMs(sb, uidWifiRunningTime / 1000);
4821 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4822 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07004823 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004824 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4825 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4826 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08004827 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004828 formatTimeMs(sb, wifiScanTime / 1000);
4829 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004830 whichBatteryRealtime)); sb.append(") ");
4831 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08004832 sb.append("x\n");
4833 // actual and background times are unpooled and since reset (regardless of 'which')
4834 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
4835 formatTimeMs(sb, wifiScanActualTime / 1000);
4836 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
4837 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4838 sb.append(") ");
4839 sb.append(wifiScanCount);
4840 sb.append("x\n");
4841 sb.append(prefix); sb.append(" Background Wifi Scan: ");
4842 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
4843 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
4844 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4845 sb.append(") ");
4846 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07004847 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004848 pw.println(sb.toString());
4849 }
4850
Adam Lesinski5f056f62016-07-14 16:56:08 -07004851 if (wifiWakeup > 0) {
4852 sb.setLength(0);
4853 sb.append(prefix);
4854 sb.append(" WiFi AP wakeups: ");
4855 sb.append(wifiWakeup);
4856 pw.println(sb.toString());
4857 }
4858
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004859 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4860 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004861
Adam Lesinski50e47602015-12-04 17:04:54 -08004862 if (btRxBytes > 0 || btTxBytes > 0) {
4863 pw.print(prefix); pw.print(" Bluetooth network: ");
4864 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4865 pw.print(formatBytesLocked(btTxBytes));
4866 pw.println(" sent");
4867 }
4868
Bookatz867c0d72017-03-07 18:23:42 -08004869 final Timer bleTimer = u.getBluetoothScanTimer();
4870 if (bleTimer != null) {
4871 // Convert from microseconds to milliseconds with rounding
4872 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
4873 / 1000;
4874 if (totalTimeMs != 0) {
4875 final int count = bleTimer.getCountLocked(which);
4876 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
4877 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004878 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4879 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
4880 final long actualTimeMsBg = bleTimerBg != null ?
4881 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004882 // Result counters
Bookatz956f36bf2017-04-28 09:48:17 -07004883 final int resultCount = u.getBluetoothScanResultCounter() != null ?
4884 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatzb1f04f32017-05-19 13:57:32 -07004885 final int resultCountBg = u.getBluetoothScanResultBgCounter() != null ?
4886 u.getBluetoothScanResultBgCounter().getCountLocked(which) : 0;
4887 // Unoptimized scan timer. Unpooled and since reset (regardless of 'which').
4888 final Timer unoptimizedScanTimer = u.getBluetoothUnoptimizedScanTimer();
4889 final long unoptimizedScanTotalTime = unoptimizedScanTimer != null ?
4890 unoptimizedScanTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4891 final long unoptimizedScanMaxTime = unoptimizedScanTimer != null ?
4892 unoptimizedScanTimer.getMaxDurationMsLocked(rawRealtimeMs) : 0;
4893 // Unoptimized bg scan timer. Unpooled and since reset (regardless of 'which').
4894 final Timer unoptimizedScanTimerBg =
4895 u.getBluetoothUnoptimizedScanBackgroundTimer();
4896 final long unoptimizedScanTotalTimeBg = unoptimizedScanTimerBg != null ?
4897 unoptimizedScanTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4898 final long unoptimizedScanMaxTimeBg = unoptimizedScanTimerBg != null ?
4899 unoptimizedScanTimerBg.getMaxDurationMsLocked(rawRealtimeMs) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004900
4901 sb.setLength(0);
Bookatz867c0d72017-03-07 18:23:42 -08004902 if (actualTimeMs != totalTimeMs) {
Bookatzb1f04f32017-05-19 13:57:32 -07004903 sb.append(prefix);
4904 sb.append(" Bluetooth Scan (total blamed realtime): ");
Bookatz867c0d72017-03-07 18:23:42 -08004905 formatTimeMs(sb, totalTimeMs);
Bookatzb1f04f32017-05-19 13:57:32 -07004906 sb.append(" (");
4907 sb.append(count);
4908 sb.append(" times)");
4909 if (bleTimer.isRunningLocked()) {
4910 sb.append(" (currently running)");
4911 }
4912 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08004913 }
Bookatzb1f04f32017-05-19 13:57:32 -07004914
4915 sb.append(prefix);
4916 sb.append(" Bluetooth Scan (total actual realtime): ");
4917 formatTimeMs(sb, actualTimeMs); // since reset, ignores 'which'
4918 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08004919 sb.append(count);
4920 sb.append(" times)");
4921 if (bleTimer.isRunningLocked()) {
Bookatzb1f04f32017-05-19 13:57:32 -07004922 sb.append(" (currently running)");
Bookatz867c0d72017-03-07 18:23:42 -08004923 }
Bookatzb1f04f32017-05-19 13:57:32 -07004924 sb.append("\n");
4925 if (actualTimeMsBg > 0 || countBg > 0) {
4926 sb.append(prefix);
4927 sb.append(" Bluetooth Scan (background realtime): ");
4928 formatTimeMs(sb, actualTimeMsBg); // since reset, ignores 'which'
4929 sb.append(" (");
Bookatz867c0d72017-03-07 18:23:42 -08004930 sb.append(countBg);
4931 sb.append(" times)");
Bookatzb1f04f32017-05-19 13:57:32 -07004932 if (bleTimerBg != null && bleTimerBg.isRunningLocked()) {
4933 sb.append(" (currently running in background)");
4934 }
4935 sb.append("\n");
Bookatz867c0d72017-03-07 18:23:42 -08004936 }
Bookatzb1f04f32017-05-19 13:57:32 -07004937
4938 sb.append(prefix);
4939 sb.append(" Bluetooth Scan Results: ");
Bookatz956f36bf2017-04-28 09:48:17 -07004940 sb.append(resultCount);
Bookatzb1f04f32017-05-19 13:57:32 -07004941 sb.append(" (");
4942 sb.append(resultCountBg);
4943 sb.append(" in background)");
4944
4945 if (unoptimizedScanTotalTime > 0 || unoptimizedScanTotalTimeBg > 0) {
4946 sb.append("\n");
4947 sb.append(prefix);
4948 sb.append(" Unoptimized Bluetooth Scan (realtime): ");
4949 formatTimeMs(sb, unoptimizedScanTotalTime); // since reset, ignores 'which'
4950 sb.append(" (max ");
4951 formatTimeMs(sb, unoptimizedScanMaxTime); // since reset, ignores 'which'
4952 sb.append(")");
4953 if (unoptimizedScanTimer != null
4954 && unoptimizedScanTimer.isRunningLocked()) {
4955 sb.append(" (currently running unoptimized)");
4956 }
4957 if (unoptimizedScanTimerBg != null && unoptimizedScanTotalTimeBg > 0) {
4958 sb.append("\n");
4959 sb.append(prefix);
4960 sb.append(" Unoptimized Bluetooth Scan (background realtime): ");
4961 formatTimeMs(sb, unoptimizedScanTotalTimeBg); // since reset
4962 sb.append(" (max ");
4963 formatTimeMs(sb, unoptimizedScanMaxTimeBg); // since reset
4964 sb.append(")");
4965 if (unoptimizedScanTimerBg.isRunningLocked()) {
4966 sb.append(" (currently running unoptimized in background)");
4967 }
4968 }
4969 }
Bookatz867c0d72017-03-07 18:23:42 -08004970 pw.println(sb.toString());
4971 uidActivity = true;
4972 }
4973 }
4974
4975
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004976
Dianne Hackborn617f8772009-03-31 15:04:46 -07004977 if (u.hasUserActivity()) {
4978 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004979 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004980 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004981 if (val != 0) {
4982 if (!hasData) {
4983 sb.setLength(0);
4984 sb.append(" User activity: ");
4985 hasData = true;
4986 } else {
4987 sb.append(", ");
4988 }
4989 sb.append(val);
4990 sb.append(" ");
4991 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4992 }
4993 }
4994 if (hasData) {
4995 pw.println(sb.toString());
4996 }
4997 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004998
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004999 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
5000 = u.getWakelockStats();
5001 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005002 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005003 int countWakelock = 0;
5004 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
5005 final Uid.Wakelock wl = wakelocks.valueAt(iw);
5006 String linePrefix = ": ";
5007 sb.setLength(0);
5008 sb.append(prefix);
5009 sb.append(" Wake lock ");
5010 sb.append(wakelocks.keyAt(iw));
5011 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
5012 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005013 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
5014 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005015 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07005016 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
5017 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005018 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
5019 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005020 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
5021 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07005022 sb.append(" realtime");
5023 pw.println(sb.toString());
5024 uidActivity = true;
5025 countWakelock++;
5026
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005027 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
5028 rawRealtime, which);
5029 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
5030 rawRealtime, which);
5031 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
5032 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005033 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07005034 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005035 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005036 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07005037 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
5038 // pooled and therefore just a lower bound)
5039 long actualTotalPartialWakelock = 0;
5040 long actualBgPartialWakelock = 0;
5041 if (u.getAggregatedPartialWakelockTimer() != null) {
5042 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
5043 // Convert from microseconds to milliseconds with rounding
5044 actualTotalPartialWakelock =
Bookatz6d799932017-06-07 12:30:07 -07005045 aggTimer.getTotalDurationMsLocked(rawRealtimeMs);
Bookatzc8c44962017-05-11 12:12:54 -07005046 final Timer bgAggTimer = aggTimer.getSubTimer();
5047 actualBgPartialWakelock = bgAggTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005048 bgAggTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatzc8c44962017-05-11 12:12:54 -07005049 }
5050
5051 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
5052 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
5053 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005054 sb.setLength(0);
5055 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005056 sb.append(" TOTAL wake: ");
5057 boolean needComma = false;
5058 if (totalFullWakelock != 0) {
5059 needComma = true;
5060 formatTimeMs(sb, totalFullWakelock);
5061 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005062 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005063 if (totalPartialWakelock != 0) {
5064 if (needComma) {
5065 sb.append(", ");
5066 }
5067 needComma = true;
5068 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07005069 sb.append("blamed partial");
5070 }
5071 if (actualTotalPartialWakelock != 0) {
5072 if (needComma) {
5073 sb.append(", ");
5074 }
5075 needComma = true;
5076 formatTimeMs(sb, actualTotalPartialWakelock);
5077 sb.append("actual partial");
5078 }
5079 if (actualBgPartialWakelock != 0) {
5080 if (needComma) {
5081 sb.append(", ");
5082 }
5083 needComma = true;
5084 formatTimeMs(sb, actualBgPartialWakelock);
5085 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005086 }
5087 if (totalWindowWakelock != 0) {
5088 if (needComma) {
5089 sb.append(", ");
5090 }
5091 needComma = true;
5092 formatTimeMs(sb, totalWindowWakelock);
5093 sb.append("window");
5094 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005095 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07005096 if (needComma) {
5097 sb.append(",");
5098 }
5099 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07005100 formatTimeMs(sb, totalDrawWakelock);
5101 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07005102 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005103 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005104 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07005105 }
5106 }
5107
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005108 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
5109 for (int isy=syncs.size()-1; isy>=0; isy--) {
5110 final Timer timer = syncs.valueAt(isy);
5111 // Convert from microseconds to milliseconds with rounding
5112 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5113 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07005114 final Timer bgTimer = timer.getSubTimer();
5115 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005116 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatz2bffb5b2017-04-13 11:59:33 -07005117 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005118 sb.setLength(0);
5119 sb.append(prefix);
5120 sb.append(" Sync ");
5121 sb.append(syncs.keyAt(isy));
5122 sb.append(": ");
5123 if (totalTime != 0) {
5124 formatTimeMs(sb, totalTime);
5125 sb.append("realtime (");
5126 sb.append(count);
5127 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07005128 if (bgTime > 0) {
5129 sb.append(", ");
5130 formatTimeMs(sb, bgTime);
5131 sb.append("background (");
5132 sb.append(bgCount);
5133 sb.append(" times)");
5134 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005135 } else {
5136 sb.append("(not used)");
5137 }
5138 pw.println(sb.toString());
5139 uidActivity = true;
5140 }
5141
5142 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
5143 for (int ij=jobs.size()-1; ij>=0; ij--) {
5144 final Timer timer = jobs.valueAt(ij);
5145 // Convert from microseconds to milliseconds with rounding
5146 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
5147 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07005148 final Timer bgTimer = timer.getSubTimer();
5149 final long bgTime = bgTimer != null ?
Bookatz6d799932017-06-07 12:30:07 -07005150 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : -1;
Bookatzaa4594a2017-03-24 12:39:56 -07005151 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005152 sb.setLength(0);
5153 sb.append(prefix);
5154 sb.append(" Job ");
5155 sb.append(jobs.keyAt(ij));
5156 sb.append(": ");
5157 if (totalTime != 0) {
5158 formatTimeMs(sb, totalTime);
5159 sb.append("realtime (");
5160 sb.append(count);
5161 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07005162 if (bgTime > 0) {
5163 sb.append(", ");
5164 formatTimeMs(sb, bgTime);
5165 sb.append("background (");
5166 sb.append(bgCount);
5167 sb.append(" times)");
5168 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005169 } else {
5170 sb.append("(not used)");
5171 }
5172 pw.println(sb.toString());
5173 uidActivity = true;
5174 }
5175
Dianne Hackborn94326cb2017-06-28 16:17:20 -07005176 final ArrayMap<String, SparseIntArray> completions = u.getJobCompletionStats();
5177 for (int ic=completions.size()-1; ic>=0; ic--) {
5178 SparseIntArray types = completions.valueAt(ic);
5179 if (types != null) {
5180 pw.print(prefix);
5181 pw.print(" Job Completions ");
5182 pw.print(completions.keyAt(ic));
5183 pw.print(":");
5184 for (int it=0; it<types.size(); it++) {
5185 pw.print(" ");
5186 pw.print(JobParameters.getReasonName(types.keyAt(it)));
5187 pw.print("(");
5188 pw.print(types.valueAt(it));
5189 pw.print("x)");
5190 }
5191 pw.println();
5192 }
5193 }
5194
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005195 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
5196 prefix, "Flashlight");
5197 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
5198 prefix, "Camera");
5199 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
5200 prefix, "Video");
5201 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
5202 prefix, "Audio");
5203
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005204 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
5205 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005206 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005207 final Uid.Sensor se = sensors.valueAt(ise);
5208 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005209 sb.setLength(0);
5210 sb.append(prefix);
5211 sb.append(" Sensor ");
5212 int handle = se.getHandle();
5213 if (handle == Uid.Sensor.GPS) {
5214 sb.append("GPS");
5215 } else {
5216 sb.append(handle);
5217 }
5218 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005219
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005220 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07005221 if (timer != null) {
5222 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08005223 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
5224 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005225 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08005226 final Timer bgTimer = se.getSensorBackgroundTime();
5227 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08005228 // 'actualTime' are unpooled and always since reset (regardless of 'which')
5229 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
5230 final long bgActualTime = bgTimer != null ?
5231 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
5232
Dianne Hackborn61659e52014-07-09 16:13:01 -07005233 //timer.logState();
5234 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08005235 if (actualTime != totalTime) {
5236 formatTimeMs(sb, totalTime);
5237 sb.append("blamed realtime, ");
5238 }
5239
5240 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07005241 sb.append("realtime (");
5242 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08005243 sb.append(" times)");
5244
5245 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005246 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08005247 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
5248 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005249 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08005250 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08005251 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005252 } else {
5253 sb.append("(not used)");
5254 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005255 } else {
5256 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005257 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005258
5259 pw.println(sb.toString());
5260 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005261 }
5262
Ruben Brunk6d2c3632015-05-26 17:32:16 -07005263 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
5264 "Vibrator");
5265 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
5266 prefix, "Foreground activities");
Michael Wachenschwanzb05a3c52017-07-07 17:47:04 -07005267 uidActivity |= printTimer(pw, sb, u.getForegroundServiceTimer(), rawRealtime, which,
5268 prefix, "Foreground services");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07005269
Dianne Hackborn61659e52014-07-09 16:13:01 -07005270 long totalStateTime = 0;
5271 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
5272 long time = u.getProcessStateTime(ips, rawRealtime, which);
5273 if (time > 0) {
5274 totalStateTime += time;
5275 sb.setLength(0);
5276 sb.append(prefix);
5277 sb.append(" ");
5278 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
5279 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08005280 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07005281 pw.println(sb.toString());
5282 uidActivity = true;
5283 }
5284 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08005285 if (totalStateTime > 0) {
5286 sb.setLength(0);
5287 sb.append(prefix);
5288 sb.append(" Total running: ");
5289 formatTimeMs(sb, (totalStateTime + 500) / 1000);
5290 pw.println(sb.toString());
5291 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07005292
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005293 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
5294 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07005295 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005296 sb.setLength(0);
5297 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07005298 sb.append(" Total cpu time: u=");
5299 formatTimeMs(sb, userCpuTimeUs / 1000);
5300 sb.append("s=");
5301 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07005302 pw.println(sb.toString());
5303 }
5304
Sudheer Shanka9b735c52017-05-09 18:26:18 -07005305 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
5306 if (cpuFreqTimes != null) {
5307 sb.setLength(0);
5308 sb.append(" Total cpu time per freq:");
5309 for (int i = 0; i < cpuFreqTimes.length; ++i) {
5310 sb.append(" " + cpuFreqTimes[i]);
5311 }
5312 pw.println(sb.toString());
5313 }
5314 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
5315 if (screenOffCpuFreqTimes != null) {
5316 sb.setLength(0);
5317 sb.append(" Total screen-off cpu time per freq:");
5318 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
5319 sb.append(" " + screenOffCpuFreqTimes[i]);
5320 }
5321 pw.println(sb.toString());
5322 }
5323
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005324 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
5325 = u.getProcessStats();
5326 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
5327 final Uid.Proc ps = processStats.valueAt(ipr);
5328 long userTime;
5329 long systemTime;
5330 long foregroundTime;
5331 int starts;
5332 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005333
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005334 userTime = ps.getUserTime(which);
5335 systemTime = ps.getSystemTime(which);
5336 foregroundTime = ps.getForegroundTime(which);
5337 starts = ps.getStarts(which);
5338 final int numCrashes = ps.getNumCrashes(which);
5339 final int numAnrs = ps.getNumAnrs(which);
5340 numExcessive = which == STATS_SINCE_CHARGED
5341 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005342
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005343 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5344 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5345 sb.setLength(0);
5346 sb.append(prefix); sb.append(" Proc ");
5347 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5348 sb.append(prefix); sb.append(" CPU: ");
5349 formatTimeMs(sb, userTime); sb.append("usr + ");
5350 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5351 formatTimeMs(sb, foregroundTime); sb.append("fg");
5352 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5353 sb.append("\n"); sb.append(prefix); sb.append(" ");
5354 boolean hasOne = false;
5355 if (starts != 0) {
5356 hasOne = true;
5357 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005358 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005359 if (numCrashes != 0) {
5360 if (hasOne) {
5361 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005362 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005363 hasOne = true;
5364 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005365 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005366 if (numAnrs != 0) {
5367 if (hasOne) {
5368 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005369 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005370 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005371 }
5372 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005373 pw.println(sb.toString());
5374 for (int e=0; e<numExcessive; e++) {
5375 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5376 if (ew != null) {
5377 pw.print(prefix); pw.print(" * Killed for ");
Dianne Hackbornffca58b2017-05-24 16:15:45 -07005378 if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005379 pw.print("cpu");
5380 } else {
5381 pw.print("unknown");
5382 }
5383 pw.print(" use: ");
5384 TimeUtils.formatDuration(ew.usedTime, pw);
5385 pw.print(" over ");
5386 TimeUtils.formatDuration(ew.overTime, pw);
5387 if (ew.overTime != 0) {
5388 pw.print(" (");
5389 pw.print((ew.usedTime*100)/ew.overTime);
5390 pw.println("%)");
5391 }
5392 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005393 }
5394 uidActivity = true;
5395 }
5396 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005397
5398 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5399 = u.getPackageStats();
5400 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5401 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5402 pw.println(":");
5403 boolean apkActivity = false;
5404 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5405 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5406 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5407 pw.print(prefix); pw.print(" Wakeup alarm ");
5408 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5409 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5410 pw.println(" times");
5411 apkActivity = true;
5412 }
5413 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5414 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5415 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5416 final long startTime = ss.getStartTime(batteryUptime, which);
5417 final int starts = ss.getStarts(which);
5418 final int launches = ss.getLaunches(which);
5419 if (startTime != 0 || starts != 0 || launches != 0) {
5420 sb.setLength(0);
5421 sb.append(prefix); sb.append(" Service ");
5422 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5423 sb.append(prefix); sb.append(" Created for: ");
5424 formatTimeMs(sb, startTime / 1000);
5425 sb.append("uptime\n");
5426 sb.append(prefix); sb.append(" Starts: ");
5427 sb.append(starts);
5428 sb.append(", launches: "); sb.append(launches);
5429 pw.println(sb.toString());
5430 apkActivity = true;
5431 }
5432 }
5433 if (!apkActivity) {
5434 pw.print(prefix); pw.println(" (nothing executed)");
5435 }
5436 uidActivity = true;
5437 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005438 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005439 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005440 }
5441 }
5442 }
5443
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005444 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005445 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005446 int diff = oldval ^ newval;
5447 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005448 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005449 for (int i=0; i<descriptions.length; i++) {
5450 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005451 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005452 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005453 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005454 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005455 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005456 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5457 didWake = true;
5458 pw.print("=");
5459 if (longNames) {
5460 UserHandle.formatUid(pw, wakelockTag.uid);
5461 pw.print(":\"");
5462 pw.print(wakelockTag.string);
5463 pw.print("\"");
5464 } else {
5465 pw.print(wakelockTag.poolIdx);
5466 }
5467 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005468 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005469 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005470 pw.print("=");
5471 int val = (newval&bd.mask)>>bd.shift;
5472 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005473 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005474 } else {
5475 pw.print(val);
5476 }
5477 }
5478 }
5479 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005480 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005481 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005482 if (longNames) {
5483 UserHandle.formatUid(pw, wakelockTag.uid);
5484 pw.print(":\"");
5485 pw.print(wakelockTag.string);
5486 pw.print("\"");
5487 } else {
5488 pw.print(wakelockTag.poolIdx);
5489 }
5490 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005491 }
Mike Mac2f518a2017-09-19 16:06:03 -07005492
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005493 public void prepareForDumpLocked() {
5494 }
5495
5496 public static class HistoryPrinter {
5497 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005498 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005499 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005500 int oldStatus = -1;
5501 int oldHealth = -1;
5502 int oldPlug = -1;
5503 int oldTemp = -1;
5504 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005505 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005506 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005507
Dianne Hackborn3251b902014-06-20 14:40:53 -07005508 void reset() {
5509 oldState = oldState2 = 0;
5510 oldLevel = -1;
5511 oldStatus = -1;
5512 oldHealth = -1;
5513 oldPlug = -1;
5514 oldTemp = -1;
5515 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005516 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005517 }
5518
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005519 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005520 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005521 if (!checkin) {
5522 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005523 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005524 pw.print(" (");
5525 pw.print(rec.numReadInts);
5526 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005527 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005528 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5529 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005530 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005531 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005532 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005533 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005534 }
5535 lastTime = rec.time;
5536 }
5537 if (rec.cmd == HistoryItem.CMD_START) {
5538 if (checkin) {
5539 pw.print(":");
5540 }
5541 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005542 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005543 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5544 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005545 if (checkin) {
5546 pw.print(":");
5547 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005548 if (rec.cmd == HistoryItem.CMD_RESET) {
5549 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005550 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005551 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005552 pw.print("TIME:");
5553 if (checkin) {
5554 pw.println(rec.currentTime);
5555 } else {
5556 pw.print(" ");
5557 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5558 rec.currentTime).toString());
5559 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005560 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5561 if (checkin) {
5562 pw.print(":");
5563 }
5564 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005565 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5566 if (checkin) {
5567 pw.print(":");
5568 }
5569 pw.println("*OVERFLOW*");
5570 } else {
5571 if (!checkin) {
5572 if (rec.batteryLevel < 10) pw.print("00");
5573 else if (rec.batteryLevel < 100) pw.print("0");
5574 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005575 if (verbose) {
5576 pw.print(" ");
5577 if (rec.states < 0) ;
5578 else if (rec.states < 0x10) pw.print("0000000");
5579 else if (rec.states < 0x100) pw.print("000000");
5580 else if (rec.states < 0x1000) pw.print("00000");
5581 else if (rec.states < 0x10000) pw.print("0000");
5582 else if (rec.states < 0x100000) pw.print("000");
5583 else if (rec.states < 0x1000000) pw.print("00");
5584 else if (rec.states < 0x10000000) pw.print("0");
5585 pw.print(Integer.toHexString(rec.states));
5586 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005587 } else {
5588 if (oldLevel != rec.batteryLevel) {
5589 oldLevel = rec.batteryLevel;
5590 pw.print(",Bl="); pw.print(rec.batteryLevel);
5591 }
5592 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005593 if (oldStatus != rec.batteryStatus) {
5594 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005595 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005596 switch (oldStatus) {
5597 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005598 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005599 break;
5600 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005601 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005602 break;
5603 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005604 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005605 break;
5606 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005607 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005608 break;
5609 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005610 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005611 break;
5612 default:
5613 pw.print(oldStatus);
5614 break;
5615 }
5616 }
5617 if (oldHealth != rec.batteryHealth) {
5618 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005619 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005620 switch (oldHealth) {
5621 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005622 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005623 break;
5624 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005625 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005626 break;
5627 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005628 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005629 break;
5630 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005631 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005632 break;
5633 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005634 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005635 break;
5636 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005637 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005638 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005639 case BatteryManager.BATTERY_HEALTH_COLD:
5640 pw.print(checkin ? "c" : "cold");
5641 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005642 default:
5643 pw.print(oldHealth);
5644 break;
5645 }
5646 }
5647 if (oldPlug != rec.batteryPlugType) {
5648 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005649 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005650 switch (oldPlug) {
5651 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005652 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005653 break;
5654 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005655 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005656 break;
5657 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005658 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005659 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005660 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005661 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005662 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005663 default:
5664 pw.print(oldPlug);
5665 break;
5666 }
5667 }
5668 if (oldTemp != rec.batteryTemperature) {
5669 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005670 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005671 pw.print(oldTemp);
5672 }
5673 if (oldVolt != rec.batteryVoltage) {
5674 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005675 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005676 pw.print(oldVolt);
5677 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005678 final int chargeMAh = rec.batteryChargeUAh / 1000;
5679 if (oldChargeMAh != chargeMAh) {
5680 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005681 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005682 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005683 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005684 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005685 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005686 printBitDescriptions(pw, oldState2, rec.states2, null,
5687 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005688 if (rec.wakeReasonTag != null) {
5689 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005690 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005691 pw.print(rec.wakeReasonTag.poolIdx);
5692 } else {
5693 pw.print(" wake_reason=");
5694 pw.print(rec.wakeReasonTag.uid);
5695 pw.print(":\"");
5696 pw.print(rec.wakeReasonTag.string);
5697 pw.print("\"");
5698 }
5699 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005700 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005701 pw.print(checkin ? "," : " ");
5702 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5703 pw.print("+");
5704 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5705 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005706 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005707 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
5708 : HISTORY_EVENT_NAMES;
5709 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
5710 | HistoryItem.EVENT_FLAG_FINISH);
5711 if (idx >= 0 && idx < eventNames.length) {
5712 pw.print(eventNames[idx]);
5713 } else {
5714 pw.print(checkin ? "Ev" : "event");
5715 pw.print(idx);
5716 }
5717 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005718 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005719 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08005720 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08005721 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
5722 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005723 pw.print(":\"");
5724 pw.print(rec.eventTag.string);
5725 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005726 }
5727 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005728 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005729 if (rec.stepDetails != null) {
5730 if (!checkin) {
5731 pw.print(" Details: cpu=");
5732 pw.print(rec.stepDetails.userTime);
5733 pw.print("u+");
5734 pw.print(rec.stepDetails.systemTime);
5735 pw.print("s");
5736 if (rec.stepDetails.appCpuUid1 >= 0) {
5737 pw.print(" (");
5738 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
5739 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5740 if (rec.stepDetails.appCpuUid2 >= 0) {
5741 pw.print(", ");
5742 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
5743 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5744 }
5745 if (rec.stepDetails.appCpuUid3 >= 0) {
5746 pw.print(", ");
5747 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
5748 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5749 }
5750 pw.print(')');
5751 }
5752 pw.println();
5753 pw.print(" /proc/stat=");
5754 pw.print(rec.stepDetails.statUserTime);
5755 pw.print(" usr, ");
5756 pw.print(rec.stepDetails.statSystemTime);
5757 pw.print(" sys, ");
5758 pw.print(rec.stepDetails.statIOWaitTime);
5759 pw.print(" io, ");
5760 pw.print(rec.stepDetails.statIrqTime);
5761 pw.print(" irq, ");
5762 pw.print(rec.stepDetails.statSoftIrqTime);
5763 pw.print(" sirq, ");
5764 pw.print(rec.stepDetails.statIdlTime);
5765 pw.print(" idle");
5766 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
5767 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
5768 + rec.stepDetails.statSoftIrqTime;
5769 int total = totalRun + rec.stepDetails.statIdlTime;
5770 if (total > 0) {
5771 pw.print(" (");
5772 float perc = ((float)totalRun) / ((float)total) * 100;
5773 pw.print(String.format("%.1f%%", perc));
5774 pw.print(" of ");
5775 StringBuilder sb = new StringBuilder(64);
5776 formatTimeMsNoSpace(sb, total*10);
5777 pw.print(sb);
5778 pw.print(")");
5779 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005780 pw.print(", PlatformIdleStat ");
5781 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005782 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005783
5784 pw.print(", SubsystemPowerState ");
5785 pw.print(rec.stepDetails.statSubsystemPowerState);
5786 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005787 } else {
5788 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5789 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
5790 pw.print(rec.stepDetails.userTime);
5791 pw.print(":");
5792 pw.print(rec.stepDetails.systemTime);
5793 if (rec.stepDetails.appCpuUid1 >= 0) {
5794 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
5795 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5796 if (rec.stepDetails.appCpuUid2 >= 0) {
5797 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
5798 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5799 }
5800 if (rec.stepDetails.appCpuUid3 >= 0) {
5801 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
5802 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5803 }
5804 }
5805 pw.println();
5806 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5807 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
5808 pw.print(rec.stepDetails.statUserTime);
5809 pw.print(',');
5810 pw.print(rec.stepDetails.statSystemTime);
5811 pw.print(',');
5812 pw.print(rec.stepDetails.statIOWaitTime);
5813 pw.print(',');
5814 pw.print(rec.stepDetails.statIrqTime);
5815 pw.print(',');
5816 pw.print(rec.stepDetails.statSoftIrqTime);
5817 pw.print(',');
5818 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005819 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005820 if (rec.stepDetails.statPlatformIdleState != null) {
5821 pw.print(rec.stepDetails.statPlatformIdleState);
Ahmed ElArabawy307edcd2017-07-07 17:48:13 -07005822 if (rec.stepDetails.statSubsystemPowerState != null) {
5823 pw.print(',');
5824 }
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005825 }
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005826
5827 if (rec.stepDetails.statSubsystemPowerState != null) {
5828 pw.print(rec.stepDetails.statSubsystemPowerState);
5829 }
5830 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005831 }
5832 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005833 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005834 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005835 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005836 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005837
5838 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
5839 UserHandle.formatUid(pw, uid);
5840 pw.print("=");
5841 pw.print(utime);
5842 pw.print("u+");
5843 pw.print(stime);
5844 pw.print("s");
5845 }
5846
5847 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5848 pw.print('/');
5849 pw.print(uid);
5850 pw.print(":");
5851 pw.print(utime);
5852 pw.print(":");
5853 pw.print(stime);
5854 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005855 }
5856
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005857 private void printSizeValue(PrintWriter pw, long size) {
5858 float result = size;
5859 String suffix = "";
5860 if (result >= 10*1024) {
5861 suffix = "KB";
5862 result = result / 1024;
5863 }
5864 if (result >= 10*1024) {
5865 suffix = "MB";
5866 result = result / 1024;
5867 }
5868 if (result >= 10*1024) {
5869 suffix = "GB";
5870 result = result / 1024;
5871 }
5872 if (result >= 10*1024) {
5873 suffix = "TB";
5874 result = result / 1024;
5875 }
5876 if (result >= 10*1024) {
5877 suffix = "PB";
5878 result = result / 1024;
5879 }
5880 pw.print((int)result);
5881 pw.print(suffix);
5882 }
5883
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005884 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5885 String label3, long estimatedTime) {
5886 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005887 return false;
5888 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005889 pw.print(label1);
5890 pw.print(label2);
5891 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005892 StringBuilder sb = new StringBuilder(64);
5893 formatTimeMs(sb, estimatedTime);
5894 pw.print(sb);
5895 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005896 return true;
5897 }
5898
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005899 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5900 LevelStepTracker steps, boolean checkin) {
5901 if (steps == null) {
5902 return false;
5903 }
5904 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005905 if (count <= 0) {
5906 return false;
5907 }
5908 if (!checkin) {
5909 pw.println(header);
5910 }
Kweku Adams030980a2015-04-01 16:07:48 -07005911 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005912 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005913 long duration = steps.getDurationAt(i);
5914 int level = steps.getLevelAt(i);
5915 long initMode = steps.getInitModeAt(i);
5916 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005917 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005918 lineArgs[0] = Long.toString(duration);
5919 lineArgs[1] = Integer.toString(level);
5920 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5921 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5922 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5923 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5924 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5925 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005926 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005927 }
5928 } else {
5929 lineArgs[2] = "";
5930 }
5931 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5932 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5933 } else {
5934 lineArgs[3] = "";
5935 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005936 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005937 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005938 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005939 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005940 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005941 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5942 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005943 pw.print(prefix);
5944 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005945 TimeUtils.formatDuration(duration, pw);
5946 pw.print(" to "); pw.print(level);
5947 boolean haveModes = false;
5948 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5949 pw.print(" (");
5950 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5951 case Display.STATE_OFF: pw.print("screen-off"); break;
5952 case Display.STATE_ON: pw.print("screen-on"); break;
5953 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5954 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005955 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005956 }
5957 haveModes = true;
5958 }
5959 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5960 pw.print(haveModes ? ", " : " (");
5961 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5962 ? "power-save-on" : "power-save-off");
5963 haveModes = true;
5964 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005965 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5966 pw.print(haveModes ? ", " : " (");
5967 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5968 ? "device-idle-on" : "device-idle-off");
5969 haveModes = true;
5970 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005971 if (haveModes) {
5972 pw.print(")");
5973 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005974 pw.println();
5975 }
5976 }
5977 return true;
5978 }
5979
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005980 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005981 public static final int DUMP_DAILY_ONLY = 1<<2;
5982 public static final int DUMP_HISTORY_ONLY = 1<<3;
5983 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5984 public static final int DUMP_VERBOSE = 1<<5;
5985 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005986
Dianne Hackborn37de0982014-05-09 09:32:18 -07005987 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5988 final HistoryPrinter hprinter = new HistoryPrinter();
5989 final HistoryItem rec = new HistoryItem();
5990 long lastTime = -1;
5991 long baseTime = -1;
5992 boolean printed = false;
5993 HistoryEventTracker tracker = null;
5994 while (getNextHistoryLocked(rec)) {
5995 lastTime = rec.time;
5996 if (baseTime < 0) {
5997 baseTime = lastTime;
5998 }
5999 if (rec.time >= histStart) {
6000 if (histStart >= 0 && !printed) {
6001 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07006002 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08006003 || rec.cmd == HistoryItem.CMD_START
6004 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006005 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006006 hprinter.printNextItem(pw, rec, baseTime, checkin,
6007 (flags&DUMP_VERBOSE) != 0);
6008 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006009 } else if (rec.currentTime != 0) {
6010 printed = true;
6011 byte cmd = rec.cmd;
6012 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006013 hprinter.printNextItem(pw, rec, baseTime, checkin,
6014 (flags&DUMP_VERBOSE) != 0);
6015 rec.cmd = cmd;
6016 }
6017 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006018 if (rec.cmd != HistoryItem.CMD_UPDATE) {
6019 hprinter.printNextItem(pw, rec, baseTime, checkin,
6020 (flags&DUMP_VERBOSE) != 0);
6021 rec.cmd = HistoryItem.CMD_UPDATE;
6022 }
6023 int oldEventCode = rec.eventCode;
6024 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006025 rec.eventTag = new HistoryTag();
6026 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
6027 HashMap<String, SparseIntArray> active
6028 = tracker.getStateForEvent(i);
6029 if (active == null) {
6030 continue;
6031 }
6032 for (HashMap.Entry<String, SparseIntArray> ent
6033 : active.entrySet()) {
6034 SparseIntArray uids = ent.getValue();
6035 for (int j=0; j<uids.size(); j++) {
6036 rec.eventCode = i;
6037 rec.eventTag.string = ent.getKey();
6038 rec.eventTag.uid = uids.keyAt(j);
6039 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07006040 hprinter.printNextItem(pw, rec, baseTime, checkin,
6041 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006042 rec.wakeReasonTag = null;
6043 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006044 }
6045 }
6046 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07006047 rec.eventCode = oldEventCode;
6048 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07006049 tracker = null;
6050 }
6051 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006052 hprinter.printNextItem(pw, rec, baseTime, checkin,
6053 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07006054 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
6055 // This is an attempt to aggregate the previous state and generate
6056 // fake events to reflect that state at the point where we start
6057 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07006058 if (tracker == null) {
6059 tracker = new HistoryEventTracker();
6060 }
6061 tracker.updateState(rec.eventCode, rec.eventTag.string,
6062 rec.eventTag.uid, rec.eventTag.poolIdx);
6063 }
6064 }
6065 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07006066 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07006067 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
6068 }
6069 }
6070
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006071 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
6072 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
6073 if (steps == null) {
6074 return;
6075 }
6076 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
6077 if (timeRemaining >= 0) {
6078 pw.print(prefix); pw.print(label); pw.print(" total time: ");
6079 tmpSb.setLength(0);
6080 formatTimeMs(tmpSb, timeRemaining);
6081 pw.print(tmpSb);
6082 pw.print(" (from "); pw.print(tmpOutInt[0]);
6083 pw.println(" steps)");
6084 }
6085 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6086 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6087 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
6088 if (estimatedTime > 0) {
6089 pw.print(prefix); pw.print(label); pw.print(" ");
6090 pw.print(STEP_LEVEL_MODE_LABELS[i]);
6091 pw.print(" time: ");
6092 tmpSb.setLength(0);
6093 formatTimeMs(tmpSb, estimatedTime);
6094 pw.print(tmpSb);
6095 pw.print(" (from "); pw.print(tmpOutInt[0]);
6096 pw.println(" steps)");
6097 }
6098 }
6099 }
6100
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006101 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
6102 ArrayList<PackageChange> changes) {
6103 if (changes == null) {
6104 return;
6105 }
6106 pw.print(prefix); pw.println("Package changes:");
6107 for (int i=0; i<changes.size(); i++) {
6108 PackageChange pc = changes.get(i);
6109 if (pc.mUpdate) {
6110 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
6111 pw.print(" vers="); pw.println(pc.mVersionCode);
6112 } else {
6113 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
6114 }
6115 }
6116 }
6117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006118 /**
6119 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
6120 *
6121 * @param pw a Printer to receive the dump output.
6122 */
6123 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006124 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006125 prepareForDumpLocked();
6126
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006127 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006128 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006129
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006130 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006131 final long historyTotalSize = getHistoryTotalSize();
6132 final long historyUsedSize = getHistoryUsedSize();
6133 if (startIteratingHistoryLocked()) {
6134 try {
6135 pw.print("Battery History (");
6136 pw.print((100*historyUsedSize)/historyTotalSize);
6137 pw.print("% used, ");
6138 printSizeValue(pw, historyUsedSize);
6139 pw.print(" used of ");
6140 printSizeValue(pw, historyTotalSize);
6141 pw.print(", ");
6142 pw.print(getHistoryStringPoolSize());
6143 pw.print(" strings using ");
6144 printSizeValue(pw, getHistoryStringPoolBytes());
6145 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07006146 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006147 pw.println();
6148 } finally {
6149 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006150 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006151 }
6152
6153 if (startIteratingOldHistoryLocked()) {
6154 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07006155 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006156 pw.println("Old battery History:");
6157 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006158 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006159 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006160 if (baseTime < 0) {
6161 baseTime = rec.time;
6162 }
6163 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006164 }
6165 pw.println();
6166 } finally {
6167 finishIteratingOldHistoryLocked();
6168 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07006169 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006170 }
6171
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006172 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006173 return;
6174 }
6175
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006176 if (!filtering) {
6177 SparseArray<? extends Uid> uidStats = getUidStats();
6178 final int NU = uidStats.size();
6179 boolean didPid = false;
6180 long nowRealtime = SystemClock.elapsedRealtime();
6181 for (int i=0; i<NU; i++) {
6182 Uid uid = uidStats.valueAt(i);
6183 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
6184 if (pids != null) {
6185 for (int j=0; j<pids.size(); j++) {
6186 Uid.Pid pid = pids.valueAt(j);
6187 if (!didPid) {
6188 pw.println("Per-PID Stats:");
6189 didPid = true;
6190 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08006191 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
6192 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006193 pw.print(" PID "); pw.print(pids.keyAt(j));
6194 pw.print(" wake time: ");
6195 TimeUtils.formatDuration(time, pw);
6196 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006197 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07006198 }
6199 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006200 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006201 pw.println();
6202 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006203 }
6204
6205 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006206 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
6207 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006208 long timeRemaining = computeBatteryTimeRemaining(
6209 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006210 if (timeRemaining >= 0) {
6211 pw.print(" Estimated discharge time remaining: ");
6212 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6213 pw.println();
6214 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006215 final LevelStepTracker steps = getDischargeLevelStepTracker();
6216 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
6217 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
6218 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
6219 STEP_LEVEL_MODE_VALUES[i], null));
6220 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006221 pw.println();
6222 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006223 if (dumpDurationSteps(pw, " ", "Charge step durations:",
6224 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07006225 long timeRemaining = computeChargeTimeRemaining(
6226 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006227 if (timeRemaining >= 0) {
6228 pw.print(" Estimated charge time remaining: ");
6229 TimeUtils.formatDuration(timeRemaining / 1000, pw);
6230 pw.println();
6231 }
6232 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006233 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006234 }
6235 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
6236 pw.println("Daily stats:");
6237 pw.print(" Current start time: ");
6238 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6239 getCurrentDailyStartTime()).toString());
6240 pw.print(" Next min deadline: ");
6241 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6242 getNextMinDailyDeadline()).toString());
6243 pw.print(" Next max deadline: ");
6244 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
6245 getNextMaxDailyDeadline()).toString());
6246 StringBuilder sb = new StringBuilder(64);
6247 int[] outInt = new int[1];
6248 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
6249 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006250 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
6251 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006252 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006253 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
6254 dsteps, false)) {
6255 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6256 sb, outInt);
6257 }
6258 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
6259 csteps, false)) {
6260 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6261 sb, outInt);
6262 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006263 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006264 } else {
6265 pw.println(" Current daily steps:");
6266 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
6267 sb, outInt);
6268 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
6269 sb, outInt);
6270 }
6271 }
6272 DailyItem dit;
6273 int curIndex = 0;
6274 while ((dit=getDailyItemLocked(curIndex)) != null) {
6275 curIndex++;
6276 if ((flags&DUMP_DAILY_ONLY) != 0) {
6277 pw.println();
6278 }
6279 pw.print(" Daily from ");
6280 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
6281 pw.print(" to ");
6282 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
6283 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006284 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006285 if (dumpDurationSteps(pw, " ",
6286 " Discharge step durations:", dit.mDischargeSteps, false)) {
6287 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6288 sb, outInt);
6289 }
6290 if (dumpDurationSteps(pw, " ",
6291 " Charge step durations:", dit.mChargeSteps, false)) {
6292 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6293 sb, outInt);
6294 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07006295 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006296 } else {
6297 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
6298 sb, outInt);
6299 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
6300 sb, outInt);
6301 }
6302 }
6303 pw.println();
6304 }
6305 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006306 pw.println("Statistics since last charge:");
6307 pw.println(" System starts: " + getStartCount()
6308 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07006309 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
6310 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07006311 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07006312 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006313 }
Mike Mac2f518a2017-09-19 16:06:03 -07006314
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006315 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006316 public void dumpCheckinLocked(Context context, PrintWriter pw,
6317 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07006318 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006319
6320 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07006321 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
6322 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006323
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006324 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
6325
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006326 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006327 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006328
6329 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07006330 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006331 try {
6332 for (int i=0; i<getHistoryStringPoolSize(); i++) {
6333 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6334 pw.print(HISTORY_STRING_POOL); pw.print(',');
6335 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006336 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006337 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006338 pw.print(",\"");
6339 String str = getHistoryTagPoolString(i);
6340 str = str.replace("\\", "\\\\");
6341 str = str.replace("\"", "\\\"");
6342 pw.print(str);
6343 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006344 pw.println();
6345 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006346 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006347 } finally {
6348 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006349 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006350 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006351 }
6352
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006353 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006354 return;
6355 }
6356
Dianne Hackborne4a59512010-12-07 11:08:07 -08006357 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006358 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006359 for (int i=0; i<apps.size(); i++) {
6360 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006361 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6362 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006363 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006364 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6365 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006366 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006367 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006368 }
6369 SparseArray<? extends Uid> uidStats = getUidStats();
6370 final int NU = uidStats.size();
6371 String[] lineArgs = new String[2];
6372 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006373 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6374 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6375 if (pkgs != null && !pkgs.second.value) {
6376 pkgs.second.value = true;
6377 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006378 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006379 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006380 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6381 (Object[])lineArgs);
6382 }
6383 }
6384 }
6385 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006386 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006387 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006388 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006389 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006390 if (timeRemaining >= 0) {
6391 lineArgs[0] = Long.toString(timeRemaining);
6392 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6393 (Object[])lineArgs);
6394 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006395 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006396 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006397 if (timeRemaining >= 0) {
6398 lineArgs[0] = Long.toString(timeRemaining);
6399 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6400 (Object[])lineArgs);
6401 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006402 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6403 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006404 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006405 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006406}