blob: 370f7f97ba8f0d09282fd4318117e448adf7956d [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.os;
18
19import java.io.PrintWriter;
Dianne Hackborne4a59512010-12-07 11:08:07 -080020import java.util.ArrayList;
Dianne Hackborn81038902012-11-26 17:04:09 -080021import java.util.Collections;
22import java.util.Comparator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import java.util.Formatter;
Dianne Hackborn37de0982014-05-09 09:32:18 -070024import java.util.HashMap;
Dianne Hackborne4a59512010-12-07 11:08:07 -080025import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import java.util.Map;
27
Dianne Hackborna7c837f2014-01-15 16:20:44 -080028import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080029import android.content.pm.ApplicationInfo;
Wink Saville52840902011-02-18 12:40:47 -080030import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080031import android.text.format.DateFormat;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070032import android.util.ArrayMap;
James Carr2dd7e5e2016-07-20 18:48:39 -070033import android.util.LongSparseArray;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070034import android.util.MutableBoolean;
35import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.util.Printer;
37import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070038import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070039import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070040import android.view.Display;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080041import com.android.internal.os.BatterySipper;
42import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
44/**
45 * A class providing access to battery usage statistics, including information on
46 * wakelocks, processes, packages, and services. All times are represented in microseconds
47 * except where indicated otherwise.
48 * @hide
49 */
50public abstract class BatteryStats implements Parcelable {
51
52 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070053
54 /** @hide */
55 public static final String SERVICE_NAME = "batterystats";
56
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 /**
58 * A constant indicating a partial wake lock timer.
59 */
60 public static final int WAKE_TYPE_PARTIAL = 0;
61
62 /**
63 * A constant indicating a full wake lock timer.
64 */
65 public static final int WAKE_TYPE_FULL = 1;
66
67 /**
68 * A constant indicating a window wake lock timer.
69 */
70 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 /**
73 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 */
75 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070076
77 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070078 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070079 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070080 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070081
82 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070083 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070084 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070085 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070086
87 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070088 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070089 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070090 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091
Dianne Hackborn62793e42015-03-09 11:15:41 -070092 /**
93 * A constant indicating a wifi multicast timer
94 */
95 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070098 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070099 */
100 public static final int VIDEO_TURNED_ON = 8;
101
102 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800103 * A constant indicating a vibrator on timer
104 */
105 public static final int VIBRATOR_ON = 9;
106
107 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700108 * A constant indicating a foreground activity timer
109 */
110 public static final int FOREGROUND_ACTIVITY = 10;
111
112 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700113 * A constant indicating a wifi batched scan is active
114 */
115 public static final int WIFI_BATCHED_SCAN = 11;
116
117 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700118 * A constant indicating a process state timer
119 */
120 public static final int PROCESS_STATE = 12;
121
122 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700123 * A constant indicating a sync timer
124 */
125 public static final int SYNC = 13;
126
127 /**
128 * A constant indicating a job timer
129 */
130 public static final int JOB = 14;
131
132 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800133 * A constant indicating an audio turn on timer
134 */
135 public static final int AUDIO_TURNED_ON = 15;
136
137 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700138 * A constant indicating a flashlight turn on timer
139 */
140 public static final int FLASHLIGHT_TURNED_ON = 16;
141
142 /**
143 * A constant indicating a camera turn on timer
144 */
145 public static final int CAMERA_TURNED_ON = 17;
146
147 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700148 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700149 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700150 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700151
152 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800153 * A constant indicating a bluetooth scan timer.
154 */
155 public static final int BLUETOOTH_SCAN_ON = 19;
156
157 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 * Include all of the data in the stats, including previously saved data.
159 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700160 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161
162 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 * Include only the current run in the stats.
164 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700165 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166
167 /**
168 * Include only the run since the last time the device was unplugged in the stats.
169 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700170 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700171
172 // NOTE: Update this list if you add/change any stats above.
173 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700174 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700175 private static final String[] STAT_NAMES = { "l", "c", "u" };
176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700178 * Current version of checkin data format.
179 */
Adam Lesinskib55d7412016-06-09 17:46:19 -0700180 static final String CHECKIN_VERSION = "18";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700181
182 /**
183 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700185 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700186
Evan Millar22ac0432009-03-31 11:33:18 -0700187 private static final long BYTES_PER_KB = 1024;
188 private static final long BYTES_PER_MB = 1048576; // 1024^2
189 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700191 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800192 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700193 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700195 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700196 private static final String CPU_DATA = "cpu";
Evan Millare84de8d2009-04-02 22:16:12 -0700197 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800198 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700199 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700200 private static final String STATE_TIME_DATA = "st";
Evan Millare84de8d2009-04-02 22:16:12 -0700201 private static final String WAKELOCK_DATA = "wl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700202 private static final String SYNC_DATA = "sy";
203 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700204 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700205 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700206 private static final String NETWORK_DATA = "nt";
207 private static final String USER_ACTIVITY_DATA = "ua";
208 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800209 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700210 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700211 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700212 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800213 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
214 private static final String WIFI_CONTROLLER_DATA = "wfcd";
215 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
216 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700217 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700218 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800219 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800220 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
221 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800222 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700223 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700224 private static final String SCREEN_BRIGHTNESS_DATA = "br";
225 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700226 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700227 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
228 private static final String DATA_CONNECTION_TIME_DATA = "dct";
229 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800230 private static final String WIFI_STATE_TIME_DATA = "wst";
231 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700232 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
233 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
234 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
235 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800236 private static final String POWER_USE_SUMMARY_DATA = "pws";
237 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700238 private static final String DISCHARGE_STEP_DATA = "dsd";
239 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700240 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
241 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700242 private static final String FLASHLIGHT_DATA = "fla";
243 private static final String CAMERA_DATA = "cam";
244 private static final String VIDEO_DATA = "vid";
245 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246
Adam Lesinski010bf372016-04-11 12:18:18 -0700247 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
248
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700249 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 private final Formatter mFormatter = new Formatter(mFormatBuilder);
251
252 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700253 * State for keeping track of counting information.
254 */
255 public static abstract class Counter {
256
257 /**
258 * Returns the count associated with this Counter for the
259 * selected type of statistics.
260 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700261 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700262 */
Evan Millarc64edde2009-04-18 12:26:32 -0700263 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700264
265 /**
266 * Temporary for debugging.
267 */
268 public abstract void logState(Printer pw, String prefix);
269 }
270
271 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700272 * State for keeping track of long counting information.
273 */
274 public static abstract class LongCounter {
275
276 /**
277 * Returns the count associated with this Counter for the
278 * selected type of statistics.
279 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700280 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700281 */
282 public abstract long getCountLocked(int which);
283
284 /**
285 * Temporary for debugging.
286 */
287 public abstract void logState(Printer pw, String prefix);
288 }
289
290 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800291 * Container class that aggregates counters for transmit, receive, and idle state of a
292 * radio controller.
293 */
294 public static abstract class ControllerActivityCounter {
295 /**
296 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
297 * idle state.
298 */
299 public abstract LongCounter getIdleTimeCounter();
300
301 /**
302 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
303 * receive state.
304 */
305 public abstract LongCounter getRxTimeCounter();
306
307 /**
308 * An array of {@link LongCounter}, representing various transmit levels, where each level
309 * may draw a different amount of power. The levels themselves are controller-specific.
310 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
311 * various transmit level states.
312 */
313 public abstract LongCounter[] getTxTimeCounters();
314
315 /**
316 * @return a non-null {@link LongCounter} representing the power consumed by the controller
317 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
318 * yield a value of 0 if the device doesn't support power calculations.
319 */
320 public abstract LongCounter getPowerCounter();
321 }
322
323 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 * State for keeping track of timing information.
325 */
326 public static abstract class Timer {
327
328 /**
329 * Returns the count associated with this Timer for the
330 * selected type of statistics.
331 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700332 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 */
Evan Millarc64edde2009-04-18 12:26:32 -0700334 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335
336 /**
337 * Returns the total time in microseconds associated with this Timer for the
338 * selected type of statistics.
339 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800340 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700341 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 * @return a time in microseconds
343 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800344 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700347 * Returns the total time in microseconds associated with this Timer since the
348 * 'mark' was last set.
349 *
350 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
351 * @return a time in microseconds
352 */
353 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
354
355 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 * Temporary for debugging.
357 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700358 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 }
360
361 /**
362 * The statistics associated with a particular uid.
363 */
364 public static abstract class Uid {
365
366 /**
367 * Returns a mapping containing wakelock statistics.
368 *
369 * @return a Map from Strings to Uid.Wakelock objects.
370 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700371 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372
373 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700374 * Returns a mapping containing sync statistics.
375 *
376 * @return a Map from Strings to Timer objects.
377 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700378 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700379
380 /**
381 * Returns a mapping containing scheduled job statistics.
382 *
383 * @return a Map from Strings to Timer objects.
384 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700385 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700386
387 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 * The statistics associated with a particular wake lock.
389 */
390 public static abstract class Wakelock {
391 public abstract Timer getWakeTime(int type);
392 }
393
394 /**
395 * Returns a mapping containing sensor statistics.
396 *
397 * @return a Map from Integer sensor ids to Uid.Sensor objects.
398 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700399 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400
401 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700402 * Returns a mapping containing active process data.
403 */
404 public abstract SparseArray<? extends Pid> getPidStats();
405
406 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 * Returns a mapping containing process statistics.
408 *
409 * @return a Map from Strings to Uid.Proc objects.
410 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700411 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412
413 /**
414 * Returns a mapping containing package statistics.
415 *
416 * @return a Map from Strings to Uid.Pkg objects.
417 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700418 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700419
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800420 public abstract ControllerActivityCounter getWifiControllerActivity();
421 public abstract ControllerActivityCounter getBluetoothControllerActivity();
422 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800423
424 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 * {@hide}
426 */
427 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700428
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800429 public abstract void noteWifiRunningLocked(long elapsedRealtime);
430 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
431 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
432 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
433 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
434 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
435 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
436 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
437 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
438 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800439 public abstract void noteActivityResumedLocked(long elapsedRealtime);
440 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800441 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
442 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
443 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700444 public abstract int getWifiScanCount(int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800445 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700446 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800447 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700448 public abstract Timer getAudioTurnedOnTimer();
449 public abstract Timer getVideoTurnedOnTimer();
450 public abstract Timer getFlashlightTurnedOnTimer();
451 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700452 public abstract Timer getForegroundActivityTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800453 public abstract Timer getBluetoothScanTimer();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700454
Dianne Hackborna0200e32016-03-30 18:01:41 -0700455 // Note: the following times are disjoint. They can be added together to find the
456 // total time a uid has had any processes running at all.
457
458 /**
459 * Time this uid has any processes in the top state (or above such as persistent).
460 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800461 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700462 /**
463 * Time this uid has any process with a started out bound foreground service, but
464 * none in the "top" state.
465 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800466 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700467 /**
468 * Time this uid has any process that is top while the device is sleeping, but none
469 * in the "foreground service" or better state.
470 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800471 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700472 /**
473 * Time this uid has any process in an active foreground state, but none in the
474 * "top sleeping" or better state.
475 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800476 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700477 /**
478 * Time this uid has any process in an active background state, but none in the
479 * "foreground" or better state.
480 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800481 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700482 /**
483 * Time this uid has any processes that are sitting around cached, not in one of the
484 * other active states.
485 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800486 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700487 /**
488 * Total number of process states we track.
489 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800490 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700491
492 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800493 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700494 };
495
496 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800497 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700498
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800499 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500
Robert Greenwalta029ea12013-09-25 16:38:12 -0700501 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
502
Dianne Hackborn617f8772009-03-31 15:04:46 -0700503 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700504 * Note that these must match the constants in android.os.PowerManager.
505 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
506 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700507 */
508 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700509 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700510 };
511
Phil Weaverda80d672016-03-15 16:25:46 -0700512 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700513
Dianne Hackborn617f8772009-03-31 15:04:46 -0700514 public abstract void noteUserActivityLocked(int type);
515 public abstract boolean hasUserActivity();
516 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700517
518 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800519 public abstract long getNetworkActivityBytes(int type, int which);
520 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800521 public abstract long getMobileRadioActiveTime(int which);
522 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700523
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700524 /**
525 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
526 */
527 public abstract long getUserCpuTimeUs(int which);
528
529 /**
530 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
531 */
532 public abstract long getSystemCpuTimeUs(int which);
533
534 /**
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700535 * Get the total cpu power consumed (in milli-ampere-microseconds).
536 */
537 public abstract long getCpuPowerMaUs(int which);
538
539 /**
Adam Lesinski6832f392015-09-05 18:05:40 -0700540 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a
541 * given CPU cluster.
542 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700543 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700544 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700545 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
546 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700547 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700548 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700549
Adam Lesinski5f056f62016-07-14 16:56:08 -0700550 /**
551 * Returns the number of times this UID woke up the Application Processor to
552 * process a mobile radio packet.
553 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
554 */
555 public abstract long getMobileRadioApWakeupCount(int which);
556
557 /**
558 * Returns the number of times this UID woke up the Application Processor to
559 * process a WiFi packet.
560 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
561 */
562 public abstract long getWifiRadioApWakeupCount(int which);
563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800565 /*
566 * FIXME: it's not correct to use this magic value because it
567 * could clash with a sensor handle (which are defined by
568 * the sensor HAL, and therefore out of our control
569 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 // Magic sensor number for the GPS.
571 public static final int GPS = -10000;
572
573 public abstract int getHandle();
574
575 public abstract Timer getSensorTime();
576 }
577
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700578 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800579 public int mWakeNesting;
580 public long mWakeSumMs;
581 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700582 }
583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 /**
585 * The statistics associated with a particular process.
586 */
587 public static abstract class Proc {
588
Dianne Hackborn287952c2010-09-22 22:34:31 -0700589 public static class ExcessivePower {
590 public static final int TYPE_WAKE = 1;
591 public static final int TYPE_CPU = 2;
592
593 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700594 public long overTime;
595 public long usedTime;
596 }
597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800599 * Returns true if this process is still active in the battery stats.
600 */
601 public abstract boolean isActive();
602
603 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700604 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700606 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 */
608 public abstract long getUserTime(int which);
609
610 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700611 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700613 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 */
615 public abstract long getSystemTime(int which);
616
617 /**
618 * Returns the number of times the process has been started.
619 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700620 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 */
622 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700623
624 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800625 * Returns the number of times the process has crashed.
626 *
627 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
628 */
629 public abstract int getNumCrashes(int which);
630
631 /**
632 * Returns the number of times the process has ANRed.
633 *
634 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
635 */
636 public abstract int getNumAnrs(int which);
637
638 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700639 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700640 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700641 * @return foreground cpu time in microseconds
642 */
643 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700644
Dianne Hackborn287952c2010-09-22 22:34:31 -0700645 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700646
Dianne Hackborn287952c2010-09-22 22:34:31 -0700647 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 }
649
650 /**
651 * The statistics associated with a particular package.
652 */
653 public static abstract class Pkg {
654
655 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700656 * Returns information about all wakeup alarms that have been triggered for this
657 * package. The mapping keys are tag names for the alarms, the counter contains
658 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700660 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661
662 /**
663 * Returns a mapping containing service statistics.
664 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700665 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666
667 /**
668 * The statistics associated with a particular service.
669 */
Joe Onoratoabded112016-02-08 16:49:39 -0800670 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671
672 /**
673 * Returns the amount of time spent started.
674 *
675 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700676 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 * @return
678 */
679 public abstract long getStartTime(long batteryUptime, int which);
680
681 /**
682 * Returns the total number of times startService() has been called.
683 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700684 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 */
686 public abstract int getStarts(int which);
687
688 /**
689 * Returns the total number times the service has been launched.
690 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700691 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 */
693 public abstract int getLaunches(int which);
694 }
695 }
696 }
697
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800698 public static final class LevelStepTracker {
699 public long mLastStepTime = -1;
700 public int mNumStepDurations;
701 public final long[] mStepDurations;
702
703 public LevelStepTracker(int maxLevelSteps) {
704 mStepDurations = new long[maxLevelSteps];
705 }
706
707 public LevelStepTracker(int numSteps, long[] steps) {
708 mNumStepDurations = numSteps;
709 mStepDurations = new long[numSteps];
710 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
711 }
712
713 public long getDurationAt(int index) {
714 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
715 }
716
717 public int getLevelAt(int index) {
718 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
719 >> STEP_LEVEL_LEVEL_SHIFT);
720 }
721
722 public int getInitModeAt(int index) {
723 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
724 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
725 }
726
727 public int getModModeAt(int index) {
728 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
729 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
730 }
731
732 private void appendHex(long val, int topOffset, StringBuilder out) {
733 boolean hasData = false;
734 while (topOffset >= 0) {
735 int digit = (int)( (val>>topOffset) & 0xf );
736 topOffset -= 4;
737 if (!hasData && digit == 0) {
738 continue;
739 }
740 hasData = true;
741 if (digit >= 0 && digit <= 9) {
742 out.append((char)('0' + digit));
743 } else {
744 out.append((char)('a' + digit - 10));
745 }
746 }
747 }
748
749 public void encodeEntryAt(int index, StringBuilder out) {
750 long item = mStepDurations[index];
751 long duration = item & STEP_LEVEL_TIME_MASK;
752 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
753 >> STEP_LEVEL_LEVEL_SHIFT);
754 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
755 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
756 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
757 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
758 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
759 case Display.STATE_OFF: out.append('f'); break;
760 case Display.STATE_ON: out.append('o'); break;
761 case Display.STATE_DOZE: out.append('d'); break;
762 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
763 }
764 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
765 out.append('p');
766 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700767 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
768 out.append('i');
769 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800770 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
771 case Display.STATE_OFF: out.append('F'); break;
772 case Display.STATE_ON: out.append('O'); break;
773 case Display.STATE_DOZE: out.append('D'); break;
774 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
775 }
776 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
777 out.append('P');
778 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700779 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
780 out.append('I');
781 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800782 out.append('-');
783 appendHex(level, 4, out);
784 out.append('-');
785 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
786 }
787
788 public void decodeEntryAt(int index, String value) {
789 final int N = value.length();
790 int i = 0;
791 char c;
792 long out = 0;
793 while (i < N && (c=value.charAt(i)) != '-') {
794 i++;
795 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800796 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800797 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800798 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800799 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800800 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800801 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800802 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
803 << STEP_LEVEL_INITIAL_MODE_SHIFT);
804 break;
805 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
806 << STEP_LEVEL_INITIAL_MODE_SHIFT);
807 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700808 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
809 << STEP_LEVEL_INITIAL_MODE_SHIFT);
810 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800811 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
812 break;
813 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
814 break;
815 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
816 break;
817 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
818 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
819 break;
820 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
821 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800822 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700823 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
824 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
825 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800826 }
827 }
828 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800829 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800830 while (i < N && (c=value.charAt(i)) != '-') {
831 i++;
832 level <<= 4;
833 if (c >= '0' && c <= '9') {
834 level += c - '0';
835 } else if (c >= 'a' && c <= 'f') {
836 level += c - 'a' + 10;
837 } else if (c >= 'A' && c <= 'F') {
838 level += c - 'A' + 10;
839 }
840 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800841 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800842 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
843 long duration = 0;
844 while (i < N && (c=value.charAt(i)) != '-') {
845 i++;
846 duration <<= 4;
847 if (c >= '0' && c <= '9') {
848 duration += c - '0';
849 } else if (c >= 'a' && c <= 'f') {
850 duration += c - 'a' + 10;
851 } else if (c >= 'A' && c <= 'F') {
852 duration += c - 'A' + 10;
853 }
854 }
855 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
856 }
857
858 public void init() {
859 mLastStepTime = -1;
860 mNumStepDurations = 0;
861 }
862
863 public void clearTime() {
864 mLastStepTime = -1;
865 }
866
867 public long computeTimePerLevel() {
868 final long[] steps = mStepDurations;
869 final int numSteps = mNumStepDurations;
870
871 // For now we'll do a simple average across all steps.
872 if (numSteps <= 0) {
873 return -1;
874 }
875 long total = 0;
876 for (int i=0; i<numSteps; i++) {
877 total += steps[i] & STEP_LEVEL_TIME_MASK;
878 }
879 return total / numSteps;
880 /*
881 long[] buckets = new long[numSteps];
882 int numBuckets = 0;
883 int numToAverage = 4;
884 int i = 0;
885 while (i < numSteps) {
886 long totalTime = 0;
887 int num = 0;
888 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
889 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
890 num++;
891 }
892 buckets[numBuckets] = totalTime / num;
893 numBuckets++;
894 numToAverage *= 2;
895 i += num;
896 }
897 if (numBuckets < 1) {
898 return -1;
899 }
900 long averageTime = buckets[numBuckets-1];
901 for (i=numBuckets-2; i>=0; i--) {
902 averageTime = (averageTime + buckets[i]) / 2;
903 }
904 return averageTime;
905 */
906 }
907
908 public long computeTimeEstimate(long modesOfInterest, long modeValues,
909 int[] outNumOfInterest) {
910 final long[] steps = mStepDurations;
911 final int count = mNumStepDurations;
912 if (count <= 0) {
913 return -1;
914 }
915 long total = 0;
916 int numOfInterest = 0;
917 for (int i=0; i<count; i++) {
918 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
919 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
920 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
921 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
922 // If the modes of interest didn't change during this step period...
923 if ((modMode&modesOfInterest) == 0) {
924 // And the mode values during this period match those we are measuring...
925 if ((initMode&modesOfInterest) == modeValues) {
926 // Then this can be used to estimate the total time!
927 numOfInterest++;
928 total += steps[i] & STEP_LEVEL_TIME_MASK;
929 }
930 }
931 }
932 if (numOfInterest <= 0) {
933 return -1;
934 }
935
936 if (outNumOfInterest != null) {
937 outNumOfInterest[0] = numOfInterest;
938 }
939
940 // The estimated time is the average time we spend in each level, multipled
941 // by 100 -- the total number of battery levels
942 return (total / numOfInterest) * 100;
943 }
944
945 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
946 int stepCount = mNumStepDurations;
947 final long lastStepTime = mLastStepTime;
948 if (lastStepTime >= 0 && numStepLevels > 0) {
949 final long[] steps = mStepDurations;
950 long duration = elapsedRealtime - lastStepTime;
951 for (int i=0; i<numStepLevels; i++) {
952 System.arraycopy(steps, 0, steps, 1, steps.length-1);
953 long thisDuration = duration / (numStepLevels-i);
954 duration -= thisDuration;
955 if (thisDuration > STEP_LEVEL_TIME_MASK) {
956 thisDuration = STEP_LEVEL_TIME_MASK;
957 }
958 steps[0] = thisDuration | modeBits;
959 }
960 stepCount += numStepLevels;
961 if (stepCount > steps.length) {
962 stepCount = steps.length;
963 }
964 }
965 mNumStepDurations = stepCount;
966 mLastStepTime = elapsedRealtime;
967 }
968
969 public void readFromParcel(Parcel in) {
970 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -0700971 if (N > mStepDurations.length) {
972 throw new ParcelFormatException("more step durations than available: " + N);
973 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800974 mNumStepDurations = N;
975 for (int i=0; i<N; i++) {
976 mStepDurations[i] = in.readLong();
977 }
978 }
979
980 public void writeToParcel(Parcel out) {
981 final int N = mNumStepDurations;
982 out.writeInt(N);
983 for (int i=0; i<N; i++) {
984 out.writeLong(mStepDurations[i]);
985 }
986 }
987 }
988
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700989 public static final class PackageChange {
990 public String mPackageName;
991 public boolean mUpdate;
992 public int mVersionCode;
993 }
994
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800995 public static final class DailyItem {
996 public long mStartTime;
997 public long mEndTime;
998 public LevelStepTracker mDischargeSteps;
999 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001000 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001001 }
1002
1003 public abstract DailyItem getDailyItemLocked(int daysAgo);
1004
1005 public abstract long getCurrentDailyStartTime();
1006
1007 public abstract long getNextMinDailyDeadline();
1008
1009 public abstract long getNextMaxDailyDeadline();
1010
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001011 public final static class HistoryTag {
1012 public String string;
1013 public int uid;
1014
1015 public int poolIdx;
1016
1017 public void setTo(HistoryTag o) {
1018 string = o.string;
1019 uid = o.uid;
1020 poolIdx = o.poolIdx;
1021 }
1022
1023 public void setTo(String _string, int _uid) {
1024 string = _string;
1025 uid = _uid;
1026 poolIdx = -1;
1027 }
1028
1029 public void writeToParcel(Parcel dest, int flags) {
1030 dest.writeString(string);
1031 dest.writeInt(uid);
1032 }
1033
1034 public void readFromParcel(Parcel src) {
1035 string = src.readString();
1036 uid = src.readInt();
1037 poolIdx = -1;
1038 }
1039
1040 @Override
1041 public boolean equals(Object o) {
1042 if (this == o) return true;
1043 if (o == null || getClass() != o.getClass()) return false;
1044
1045 HistoryTag that = (HistoryTag) o;
1046
1047 if (uid != that.uid) return false;
1048 if (!string.equals(that.string)) return false;
1049
1050 return true;
1051 }
1052
1053 @Override
1054 public int hashCode() {
1055 int result = string.hashCode();
1056 result = 31 * result + uid;
1057 return result;
1058 }
1059 }
1060
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001061 /**
1062 * Optional detailed information that can go into a history step. This is typically
1063 * generated each time the battery level changes.
1064 */
1065 public final static class HistoryStepDetails {
1066 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1067 public int userTime;
1068 public int systemTime;
1069
1070 // Top three apps using CPU in the last step, with times in 1/100 second.
1071 public int appCpuUid1;
1072 public int appCpuUTime1;
1073 public int appCpuSTime1;
1074 public int appCpuUid2;
1075 public int appCpuUTime2;
1076 public int appCpuSTime2;
1077 public int appCpuUid3;
1078 public int appCpuUTime3;
1079 public int appCpuSTime3;
1080
1081 // Information from /proc/stat
1082 public int statUserTime;
1083 public int statSystemTime;
1084 public int statIOWaitTime;
1085 public int statIrqTime;
1086 public int statSoftIrqTime;
1087 public int statIdlTime;
1088
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001089 // Platform-level low power state stats
1090 public String statPlatformIdleState;
1091
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001092 public HistoryStepDetails() {
1093 clear();
1094 }
1095
1096 public void clear() {
1097 userTime = systemTime = 0;
1098 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1099 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1100 = appCpuUTime3 = appCpuSTime3 = 0;
1101 }
1102
1103 public void writeToParcel(Parcel out) {
1104 out.writeInt(userTime);
1105 out.writeInt(systemTime);
1106 out.writeInt(appCpuUid1);
1107 out.writeInt(appCpuUTime1);
1108 out.writeInt(appCpuSTime1);
1109 out.writeInt(appCpuUid2);
1110 out.writeInt(appCpuUTime2);
1111 out.writeInt(appCpuSTime2);
1112 out.writeInt(appCpuUid3);
1113 out.writeInt(appCpuUTime3);
1114 out.writeInt(appCpuSTime3);
1115 out.writeInt(statUserTime);
1116 out.writeInt(statSystemTime);
1117 out.writeInt(statIOWaitTime);
1118 out.writeInt(statIrqTime);
1119 out.writeInt(statSoftIrqTime);
1120 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001121 out.writeString(statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001122 }
1123
1124 public void readFromParcel(Parcel in) {
1125 userTime = in.readInt();
1126 systemTime = in.readInt();
1127 appCpuUid1 = in.readInt();
1128 appCpuUTime1 = in.readInt();
1129 appCpuSTime1 = in.readInt();
1130 appCpuUid2 = in.readInt();
1131 appCpuUTime2 = in.readInt();
1132 appCpuSTime2 = in.readInt();
1133 appCpuUid3 = in.readInt();
1134 appCpuUTime3 = in.readInt();
1135 appCpuSTime3 = in.readInt();
1136 statUserTime = in.readInt();
1137 statSystemTime = in.readInt();
1138 statIOWaitTime = in.readInt();
1139 statIrqTime = in.readInt();
1140 statSoftIrqTime = in.readInt();
1141 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001142 statPlatformIdleState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001143 }
1144 }
1145
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001146 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001147 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001148
1149 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001150 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001151
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001152 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001153 public static final byte CMD_NULL = -1;
1154 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001155 public static final byte CMD_CURRENT_TIME = 5;
1156 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001157 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001158 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001159
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001160 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001161
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001162 /**
1163 * Return whether the command code is a delta data update.
1164 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001165 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001166 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001167 }
1168
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001169 public byte batteryLevel;
1170 public byte batteryStatus;
1171 public byte batteryHealth;
1172 public byte batteryPlugType;
1173
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001174 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001175 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001176
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001177 // The charge of the battery in micro-Ampere-hours.
1178 public int batteryChargeUAh;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001179
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001180 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001181 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001182 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001183 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001184 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1185 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001186 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001187 public static final int STATE_PHONE_STATE_SHIFT = 6;
1188 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001189 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001190 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001191 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001192
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001193 // These states always appear directly in the first int token
1194 // of a delta change; they should be ones that change relatively
1195 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001196 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1197 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001198 public static final int STATE_GPS_ON_FLAG = 1<<29;
1199 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001200 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001201 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001202 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001203 // Do not use, this is used for coulomb delta count.
1204 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001205 // These are on the lower bits used for the command; if they change
1206 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001207 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001208 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001209 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001210 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1211 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1212 // empty slot
1213 // empty slot
1214 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001215
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001216 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001217 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1218
1219 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001220
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001221 public int states;
1222
Dianne Hackborn3251b902014-06-20 14:40:53 -07001223 // Constants from WIFI_SUPPL_STATE_*
1224 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1225 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1226 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1227 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1228 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1229 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1230
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001231 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001232 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1233 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1234 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001235 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001236 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1237 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1238 public static final int STATE2_CHARGING_FLAG = 1<<24;
1239 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1240 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1241 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001242 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001243
1244 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001245 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001246 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1247
1248 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001249
Dianne Hackborn40c87252014-03-19 16:55:40 -07001250 public int states2;
1251
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001252 // The wake lock that was acquired at this point.
1253 public HistoryTag wakelockTag;
1254
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001255 // Kernel wakeup reason at this point.
1256 public HistoryTag wakeReasonTag;
1257
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001258 // Non-null when there is more detailed information at this step.
1259 public HistoryStepDetails stepDetails;
1260
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001261 public static final int EVENT_FLAG_START = 0x8000;
1262 public static final int EVENT_FLAG_FINISH = 0x4000;
1263
1264 // No event in this item.
1265 public static final int EVENT_NONE = 0x0000;
1266 // Event is about a process that is running.
1267 public static final int EVENT_PROC = 0x0001;
1268 // Event is about an application package that is in the foreground.
1269 public static final int EVENT_FOREGROUND = 0x0002;
1270 // Event is about an application package that is at the top of the screen.
1271 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001272 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001273 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001274 // Events for all additional wake locks aquired/release within a wake block.
1275 // These are not generated by default.
1276 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001277 // Event is about an application executing a scheduled job.
1278 public static final int EVENT_JOB = 0x0006;
1279 // Events for users running.
1280 public static final int EVENT_USER_RUNNING = 0x0007;
1281 // Events for foreground user.
1282 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001283 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001284 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001285 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001286 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001287 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001288 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001289 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001290 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001291 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001292 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001293 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001294 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001295 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001296 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001297 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001298 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001299 // Event for a package being on the temporary whitelist.
1300 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001301 // Event for the screen waking up.
1302 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001303 // Event for the UID that woke up the application processor.
1304 // Used for wakeups coming from WiFi, modem, etc.
1305 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001306 // Event for reporting that a specific partial wake lock has been held for a long duration.
1307 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001308
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001309 // Number of event types.
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001310 public static final int EVENT_COUNT = 0x0015;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001311 // Mask to extract out only the type part of the event.
1312 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001313
1314 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1315 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1316 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1317 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1318 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1319 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001320 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1321 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001322 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1323 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001324 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1325 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1326 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1327 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1328 public static final int EVENT_USER_FOREGROUND_START =
1329 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1330 public static final int EVENT_USER_FOREGROUND_FINISH =
1331 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001332 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1333 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001334 public static final int EVENT_TEMP_WHITELIST_START =
1335 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1336 public static final int EVENT_TEMP_WHITELIST_FINISH =
1337 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001338 public static final int EVENT_LONG_WAKE_LOCK_START =
1339 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1340 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1341 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001342
1343 // For CMD_EVENT.
1344 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001345 public HistoryTag eventTag;
1346
Dianne Hackborn9a755432014-05-15 17:05:22 -07001347 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001348 public long currentTime;
1349
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001350 // Meta-data when reading.
1351 public int numReadInts;
1352
1353 // Pre-allocated objects.
1354 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001355 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001356 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001357
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001358 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001359 }
1360
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001361 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001362 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001363 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001364 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001365 }
1366
1367 public int describeContents() {
1368 return 0;
1369 }
1370
1371 public void writeToParcel(Parcel dest, int flags) {
1372 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001373 int bat = (((int)cmd)&0xff)
1374 | ((((int)batteryLevel)<<8)&0xff00)
1375 | ((((int)batteryStatus)<<16)&0xf0000)
1376 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001377 | ((((int)batteryPlugType)<<24)&0xf000000)
1378 | (wakelockTag != null ? 0x10000000 : 0)
1379 | (wakeReasonTag != null ? 0x20000000 : 0)
1380 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001381 dest.writeInt(bat);
1382 bat = (((int)batteryTemperature)&0xffff)
1383 | ((((int)batteryVoltage)<<16)&0xffff0000);
1384 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001385 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001386 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001387 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001388 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001389 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001390 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001391 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001392 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001393 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001394 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001395 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001396 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001397 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001398 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001399 dest.writeLong(currentTime);
1400 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001401 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001402
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001403 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001404 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001405 int bat = src.readInt();
1406 cmd = (byte)(bat&0xff);
1407 batteryLevel = (byte)((bat>>8)&0xff);
1408 batteryStatus = (byte)((bat>>16)&0xf);
1409 batteryHealth = (byte)((bat>>20)&0xf);
1410 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001411 int bat2 = src.readInt();
1412 batteryTemperature = (short)(bat2&0xffff);
1413 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001414 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001415 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001416 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001417 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001418 wakelockTag = localWakelockTag;
1419 wakelockTag.readFromParcel(src);
1420 } else {
1421 wakelockTag = null;
1422 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001423 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001424 wakeReasonTag = localWakeReasonTag;
1425 wakeReasonTag.readFromParcel(src);
1426 } else {
1427 wakeReasonTag = null;
1428 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001429 if ((bat&0x40000000) != 0) {
1430 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001431 eventTag = localEventTag;
1432 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001433 } else {
1434 eventCode = EVENT_NONE;
1435 eventTag = null;
1436 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001437 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001438 currentTime = src.readLong();
1439 } else {
1440 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001441 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001442 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001443 }
1444
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001445 public void clear() {
1446 time = 0;
1447 cmd = CMD_NULL;
1448 batteryLevel = 0;
1449 batteryStatus = 0;
1450 batteryHealth = 0;
1451 batteryPlugType = 0;
1452 batteryTemperature = 0;
1453 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001454 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001455 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001456 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001457 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001458 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001459 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001460 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001461 }
1462
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001463 public void setTo(HistoryItem o) {
1464 time = o.time;
1465 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001466 setToCommon(o);
1467 }
1468
1469 public void setTo(long time, byte cmd, HistoryItem o) {
1470 this.time = time;
1471 this.cmd = cmd;
1472 setToCommon(o);
1473 }
1474
1475 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001476 batteryLevel = o.batteryLevel;
1477 batteryStatus = o.batteryStatus;
1478 batteryHealth = o.batteryHealth;
1479 batteryPlugType = o.batteryPlugType;
1480 batteryTemperature = o.batteryTemperature;
1481 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001482 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001483 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001484 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001485 if (o.wakelockTag != null) {
1486 wakelockTag = localWakelockTag;
1487 wakelockTag.setTo(o.wakelockTag);
1488 } else {
1489 wakelockTag = null;
1490 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001491 if (o.wakeReasonTag != null) {
1492 wakeReasonTag = localWakeReasonTag;
1493 wakeReasonTag.setTo(o.wakeReasonTag);
1494 } else {
1495 wakeReasonTag = null;
1496 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001497 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001498 if (o.eventTag != null) {
1499 eventTag = localEventTag;
1500 eventTag.setTo(o.eventTag);
1501 } else {
1502 eventTag = null;
1503 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001504 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001505 }
1506
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001507 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001508 return batteryLevel == o.batteryLevel
1509 && batteryStatus == o.batteryStatus
1510 && batteryHealth == o.batteryHealth
1511 && batteryPlugType == o.batteryPlugType
1512 && batteryTemperature == o.batteryTemperature
1513 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001514 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001515 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001516 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001517 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001518 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001519
1520 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001521 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001522 return false;
1523 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001524 if (wakelockTag != o.wakelockTag) {
1525 if (wakelockTag == null || o.wakelockTag == null) {
1526 return false;
1527 }
1528 if (!wakelockTag.equals(o.wakelockTag)) {
1529 return false;
1530 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001531 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001532 if (wakeReasonTag != o.wakeReasonTag) {
1533 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1534 return false;
1535 }
1536 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1537 return false;
1538 }
1539 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001540 if (eventTag != o.eventTag) {
1541 if (eventTag == null || o.eventTag == null) {
1542 return false;
1543 }
1544 if (!eventTag.equals(o.eventTag)) {
1545 return false;
1546 }
1547 }
1548 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001549 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001550 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001551
1552 public final static class HistoryEventTracker {
1553 private final HashMap<String, SparseIntArray>[] mActiveEvents
1554 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1555
1556 public boolean updateState(int code, String name, int uid, int poolIdx) {
1557 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1558 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1559 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1560 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001561 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001562 mActiveEvents[idx] = active;
1563 }
1564 SparseIntArray uids = active.get(name);
1565 if (uids == null) {
1566 uids = new SparseIntArray();
1567 active.put(name, uids);
1568 }
1569 if (uids.indexOfKey(uid) >= 0) {
1570 // Already set, nothing to do!
1571 return false;
1572 }
1573 uids.put(uid, poolIdx);
1574 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1575 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1576 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1577 if (active == null) {
1578 // not currently active, nothing to do.
1579 return false;
1580 }
1581 SparseIntArray uids = active.get(name);
1582 if (uids == null) {
1583 // not currently active, nothing to do.
1584 return false;
1585 }
1586 idx = uids.indexOfKey(uid);
1587 if (idx < 0) {
1588 // not currently active, nothing to do.
1589 return false;
1590 }
1591 uids.removeAt(idx);
1592 if (uids.size() <= 0) {
1593 active.remove(name);
1594 }
1595 }
1596 return true;
1597 }
1598
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001599 public void removeEvents(int code) {
1600 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1601 mActiveEvents[idx] = null;
1602 }
1603
Dianne Hackborn37de0982014-05-09 09:32:18 -07001604 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1605 return mActiveEvents[code];
1606 }
1607 }
1608
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001609 public static final class BitDescription {
1610 public final int mask;
1611 public final int shift;
1612 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001613 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001614 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001615 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001616
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001617 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001618 this.mask = mask;
1619 this.shift = -1;
1620 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001621 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001622 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001623 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001624 }
1625
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001626 public BitDescription(int mask, int shift, String name, String shortName,
1627 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001628 this.mask = mask;
1629 this.shift = shift;
1630 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001631 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001632 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001633 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001634 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001635 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001636
Dianne Hackbornfc064132014-06-02 12:42:12 -07001637 /**
1638 * Don't allow any more batching in to the current history event. This
1639 * is called when printing partial histories, so to ensure that the next
1640 * history event will go in to a new batch after what was printed in the
1641 * last partial history.
1642 */
1643 public abstract void commitCurrentHistoryBatchLocked();
1644
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001645 public abstract int getHistoryTotalSize();
1646
1647 public abstract int getHistoryUsedSize();
1648
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001649 public abstract boolean startIteratingHistoryLocked();
1650
Dianne Hackborn099bc622014-01-22 13:39:16 -08001651 public abstract int getHistoryStringPoolSize();
1652
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001653 public abstract int getHistoryStringPoolBytes();
1654
1655 public abstract String getHistoryTagPoolString(int index);
1656
1657 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001658
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001659 public abstract boolean getNextHistoryLocked(HistoryItem out);
1660
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001661 public abstract void finishIteratingHistoryLocked();
1662
1663 public abstract boolean startIteratingOldHistoryLocked();
1664
1665 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1666
1667 public abstract void finishIteratingOldHistoryLocked();
1668
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001670 * Return the base time offset for the battery history.
1671 */
1672 public abstract long getHistoryBaseTime();
1673
1674 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 * Returns the number of times the device has been started.
1676 */
1677 public abstract int getStartCount();
1678
1679 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001680 * 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 -08001681 * running on battery.
1682 *
1683 * {@hide}
1684 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001685 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001686
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001687 /**
1688 * Returns the number of times the screen was turned on.
1689 *
1690 * {@hide}
1691 */
1692 public abstract int getScreenOnCount(int which);
1693
Jeff Browne95c3cd2014-05-02 16:59:26 -07001694 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1695
Dianne Hackborn617f8772009-03-31 15:04:46 -07001696 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1697 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1698 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1699 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1700 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1701
1702 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1703 "dark", "dim", "medium", "light", "bright"
1704 };
1705
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001706 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1707 "0", "1", "2", "3", "4"
1708 };
1709
Dianne Hackborn617f8772009-03-31 15:04:46 -07001710 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001711
Dianne Hackborn617f8772009-03-31 15:04:46 -07001712 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001713 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001714 * the given brightness
1715 *
1716 * {@hide}
1717 */
1718 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001719 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001720
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001721 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001722 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001723 * running on battery.
1724 *
1725 * {@hide}
1726 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001727 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001728
1729 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001730 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001731 *
1732 * {@hide}
1733 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001734 public abstract int getPowerSaveModeEnabledCount(int which);
1735
1736 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001737 * Constant for device idle mode: not active.
1738 */
1739 public static final int DEVICE_IDLE_MODE_OFF = 0;
1740
1741 /**
1742 * Constant for device idle mode: active in lightweight mode.
1743 */
1744 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1745
1746 /**
1747 * Constant for device idle mode: active in full mode.
1748 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001749 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001750
1751 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001752 * Returns the time in microseconds that device has been in idle mode while
1753 * running on battery.
1754 *
1755 * {@hide}
1756 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001757 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001758
1759 /**
1760 * Returns the number of times that the devie has gone in to idle mode.
1761 *
1762 * {@hide}
1763 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001764 public abstract int getDeviceIdleModeCount(int mode, int which);
1765
1766 /**
1767 * Return the longest duration we spent in a particular device idle mode (fully in the
1768 * mode, not in idle maintenance etc).
1769 */
1770 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001771
1772 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001773 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001774 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001775 * counts all of the time that we consider the device to be idle, whether or not
1776 * it is currently in the actual device idle mode.
1777 *
1778 * {@hide}
1779 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001780 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001781
1782 /**
1783 * Returns the number of times that the devie has started idling.
1784 *
1785 * {@hide}
1786 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001787 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001788
1789 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001790 * Returns the number of times that connectivity state changed.
1791 *
1792 * {@hide}
1793 */
1794 public abstract int getNumConnectivityChange(int which);
1795
1796 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001797 * 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 -08001798 * running on battery.
1799 *
1800 * {@hide}
1801 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001802 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001803
1804 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001805 * Returns the number of times a phone call was activated.
1806 *
1807 * {@hide}
1808 */
1809 public abstract int getPhoneOnCount(int which);
1810
1811 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001812 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001813 * the given signal strength.
1814 *
1815 * {@hide}
1816 */
1817 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001818 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001819
Dianne Hackborn617f8772009-03-31 15:04:46 -07001820 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001821 * Returns the time in microseconds that the phone has been trying to
1822 * acquire a signal.
1823 *
1824 * {@hide}
1825 */
1826 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001827 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001828
1829 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001830 * Returns the number of times the phone has entered the given signal strength.
1831 *
1832 * {@hide}
1833 */
1834 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1835
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001836 /**
1837 * Returns the time in microseconds that the mobile network has been active
1838 * (in a high power state).
1839 *
1840 * {@hide}
1841 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001842 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001843
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001844 /**
1845 * Returns the number of times that the mobile network has transitioned to the
1846 * active state.
1847 *
1848 * {@hide}
1849 */
1850 public abstract int getMobileRadioActiveCount(int which);
1851
1852 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001853 * Returns the time in microseconds that is the difference between the mobile radio
1854 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1855 * from the radio.
1856 *
1857 * {@hide}
1858 */
1859 public abstract long getMobileRadioActiveAdjustedTime(int which);
1860
1861 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001862 * Returns the time in microseconds that the mobile network has been active
1863 * (in a high power state) but not being able to blame on an app.
1864 *
1865 * {@hide}
1866 */
1867 public abstract long getMobileRadioActiveUnknownTime(int which);
1868
1869 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001870 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001871 *
1872 * {@hide}
1873 */
1874 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001875
Dianne Hackborn627bba72009-03-24 22:32:56 -07001876 public static final int DATA_CONNECTION_NONE = 0;
1877 public static final int DATA_CONNECTION_GPRS = 1;
1878 public static final int DATA_CONNECTION_EDGE = 2;
1879 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001880 public static final int DATA_CONNECTION_CDMA = 4;
1881 public static final int DATA_CONNECTION_EVDO_0 = 5;
1882 public static final int DATA_CONNECTION_EVDO_A = 6;
1883 public static final int DATA_CONNECTION_1xRTT = 7;
1884 public static final int DATA_CONNECTION_HSDPA = 8;
1885 public static final int DATA_CONNECTION_HSUPA = 9;
1886 public static final int DATA_CONNECTION_HSPA = 10;
1887 public static final int DATA_CONNECTION_IDEN = 11;
1888 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001889 public static final int DATA_CONNECTION_LTE = 13;
1890 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001891 public static final int DATA_CONNECTION_HSPAP = 15;
1892 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001893
Dianne Hackborn627bba72009-03-24 22:32:56 -07001894 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001895 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001896 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001897 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001898 };
1899
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001900 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001901
1902 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001903 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001904 * the given data connection.
1905 *
1906 * {@hide}
1907 */
1908 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001909 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001910
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001912 * Returns the number of times the phone has entered the given data
1913 * connection type.
1914 *
1915 * {@hide}
1916 */
1917 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001918
Dianne Hackborn3251b902014-06-20 14:40:53 -07001919 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1920 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1921 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1922 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1923 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1924 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1925 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1926 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1927 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1928 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1929 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1930 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1931 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1932
1933 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1934
1935 static final String[] WIFI_SUPPL_STATE_NAMES = {
1936 "invalid", "disconn", "disabled", "inactive", "scanning",
1937 "authenticating", "associating", "associated", "4-way-handshake",
1938 "group-handshake", "completed", "dormant", "uninit"
1939 };
1940
1941 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1942 "inv", "dsc", "dis", "inact", "scan",
1943 "auth", "ascing", "asced", "4-way",
1944 "group", "compl", "dorm", "uninit"
1945 };
1946
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001947 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1948 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001949 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001950 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1951 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001952 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001953 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1954 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1955 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001956 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001957 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001958 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001959 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001960 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1961 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001962 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1963 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1964 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1965 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1966 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1967 new String[] {"in", "out", "emergency", "off"},
1968 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001969 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1970 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1971 SignalStrength.SIGNAL_STRENGTH_NAMES,
1972 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001973 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1974 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1975 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001976 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001977
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001978 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1979 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001980 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001981 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001982 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001983 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001984 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001985 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
1986 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
1987 new String[] { "off", "light", "full", "???" },
1988 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001989 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
1990 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
1991 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001992 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1993 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1994 new String[] { "0", "1", "2", "3", "4" },
1995 new String[] { "0", "1", "2", "3", "4" }),
1996 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1997 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1998 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07001999 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002000 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002001 };
2002
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002003 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002004 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002005 "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist",
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07002006 "screenwake", "wakeupap", "longwake"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002007 };
2008
2009 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002010 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002011 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07002012 "Esw", "Ewa", "Elw"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002013 };
2014
Dianne Hackborn617f8772009-03-31 15:04:46 -07002015 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002016 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002017 * running on battery.
2018 *
2019 * {@hide}
2020 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002021 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002022
2023 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002024 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002025 * been in the running state while the device was running on battery.
2026 *
2027 * {@hide}
2028 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002029 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002030
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002031 public static final int WIFI_STATE_OFF = 0;
2032 public static final int WIFI_STATE_OFF_SCANNING = 1;
2033 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2034 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2035 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2036 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2037 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2038 public static final int WIFI_STATE_SOFT_AP = 7;
2039
2040 static final String[] WIFI_STATE_NAMES = {
2041 "off", "scanning", "no_net", "disconn",
2042 "sta", "p2p", "sta_p2p", "soft_ap"
2043 };
2044
2045 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2046
2047 /**
2048 * Returns the time in microseconds that WiFi has been running in the given state.
2049 *
2050 * {@hide}
2051 */
2052 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002053 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002054
2055 /**
2056 * Returns the number of times that WiFi has entered the given state.
2057 *
2058 * {@hide}
2059 */
2060 public abstract int getWifiStateCount(int wifiState, int which);
2061
The Android Open Source Project10592532009-03-18 17:39:46 -07002062 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002063 * Returns the time in microseconds that the wifi supplicant has been
2064 * in a given state.
2065 *
2066 * {@hide}
2067 */
2068 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2069
2070 /**
2071 * Returns the number of times that the wifi supplicant has transitioned
2072 * to a given state.
2073 *
2074 * {@hide}
2075 */
2076 public abstract int getWifiSupplStateCount(int state, int which);
2077
2078 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2079
2080 /**
2081 * Returns the time in microseconds that WIFI has been running with
2082 * the given signal strength.
2083 *
2084 * {@hide}
2085 */
2086 public abstract long getWifiSignalStrengthTime(int strengthBin,
2087 long elapsedRealtimeUs, int which);
2088
2089 /**
2090 * Returns the number of times WIFI has entered the given signal strength.
2091 *
2092 * {@hide}
2093 */
2094 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2095
2096 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002097 * Returns the time in microseconds that the flashlight has been on while the device was
2098 * running on battery.
2099 *
2100 * {@hide}
2101 */
2102 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2103
2104 /**
2105 * Returns the number of times that the flashlight has been turned on while the device was
2106 * running on battery.
2107 *
2108 * {@hide}
2109 */
2110 public abstract long getFlashlightOnCount(int which);
2111
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002112 /**
2113 * Returns the time in microseconds that the camera has been on while the device was
2114 * running on battery.
2115 *
2116 * {@hide}
2117 */
2118 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2119
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002120 /**
2121 * Returns the time in microseconds that bluetooth scans were running while the device was
2122 * on battery.
2123 *
2124 * {@hide}
2125 */
2126 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002127
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002128 public static final int NETWORK_MOBILE_RX_DATA = 0;
2129 public static final int NETWORK_MOBILE_TX_DATA = 1;
2130 public static final int NETWORK_WIFI_RX_DATA = 2;
2131 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002132 public static final int NETWORK_BT_RX_DATA = 4;
2133 public static final int NETWORK_BT_TX_DATA = 5;
2134 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_BT_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002135
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002136 public abstract long getNetworkActivityBytes(int type, int which);
2137 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002138
Adam Lesinskie08af192015-03-25 16:42:59 -07002139 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002140 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002141 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002142 * actual power data.
2143 */
2144 public abstract boolean hasWifiActivityReporting();
2145
2146 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002147 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2148 * in various radio controller states, such as transmit, receive, and idle.
2149 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002150 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002151 public abstract ControllerActivityCounter getWifiControllerActivity();
2152
2153 /**
2154 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2155 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2156 * actual power data.
2157 */
2158 public abstract boolean hasBluetoothActivityReporting();
2159
2160 /**
2161 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2162 * in various radio controller states, such as transmit, receive, and idle.
2163 * @return non-null {@link ControllerActivityCounter}
2164 */
2165 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2166
2167 /**
2168 * Returns true if the BatteryStats object has detailed modem power reports.
2169 * When true, calling {@link #getModemControllerActivity()} will yield the
2170 * actual power data.
2171 */
2172 public abstract boolean hasModemActivityReporting();
2173
2174 /**
2175 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2176 * in various radio controller states, such as transmit, receive, and idle.
2177 * @return non-null {@link ControllerActivityCounter}
2178 */
2179 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002180
The Android Open Source Project10592532009-03-18 17:39:46 -07002181 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002182 * Return the wall clock time when battery stats data collection started.
2183 */
2184 public abstract long getStartClockTime();
2185
2186 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002187 * Return platform version tag that we were running in when the battery stats started.
2188 */
2189 public abstract String getStartPlatformVersion();
2190
2191 /**
2192 * Return platform version tag that we were running in when the battery stats ended.
2193 */
2194 public abstract String getEndPlatformVersion();
2195
2196 /**
2197 * Return the internal version code of the parcelled format.
2198 */
2199 public abstract int getParcelVersion();
2200
2201 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 * Return whether we are currently running on battery.
2203 */
2204 public abstract boolean getIsOnBattery();
2205
2206 /**
2207 * Returns a SparseArray containing the statistics for each uid.
2208 */
2209 public abstract SparseArray<? extends Uid> getUidStats();
2210
2211 /**
2212 * Returns the current battery uptime in microseconds.
2213 *
2214 * @param curTime the amount of elapsed realtime in microseconds.
2215 */
2216 public abstract long getBatteryUptime(long curTime);
2217
2218 /**
2219 * Returns the current battery realtime in microseconds.
2220 *
2221 * @param curTime the amount of elapsed realtime in microseconds.
2222 */
2223 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07002224
2225 /**
Evan Millar633a1742009-04-02 16:36:33 -07002226 * Returns the battery percentage level at the last time the device was unplugged from power, or
2227 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002228 */
Evan Millar633a1742009-04-02 16:36:33 -07002229 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07002230
2231 /**
Evan Millar633a1742009-04-02 16:36:33 -07002232 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2233 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002234 */
Evan Millar633a1742009-04-02 16:36:33 -07002235 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236
2237 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002238 * Get the amount the battery has discharged since the stats were
2239 * last reset after charging, as a lower-end approximation.
2240 */
2241 public abstract int getLowDischargeAmountSinceCharge();
2242
2243 /**
2244 * Get the amount the battery has discharged since the stats were
2245 * last reset after charging, as an upper-end approximation.
2246 */
2247 public abstract int getHighDischargeAmountSinceCharge();
2248
2249 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002250 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2251 */
2252 public abstract int getDischargeAmount(int which);
2253
2254 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002255 * Get the amount the battery has discharged while the screen was on,
2256 * since the last time power was unplugged.
2257 */
2258 public abstract int getDischargeAmountScreenOn();
2259
2260 /**
2261 * Get the amount the battery has discharged while the screen was on,
2262 * since the last time the device was charged.
2263 */
2264 public abstract int getDischargeAmountScreenOnSinceCharge();
2265
2266 /**
2267 * Get the amount the battery has discharged while the screen was off,
2268 * since the last time power was unplugged.
2269 */
2270 public abstract int getDischargeAmountScreenOff();
2271
2272 /**
2273 * Get the amount the battery has discharged while the screen was off,
2274 * since the last time the device was charged.
2275 */
2276 public abstract int getDischargeAmountScreenOffSinceCharge();
2277
2278 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 * Returns the total, last, or current battery uptime in microseconds.
2280 *
2281 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002282 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 */
2284 public abstract long computeBatteryUptime(long curTime, int which);
2285
2286 /**
2287 * Returns the total, last, or current battery realtime in microseconds.
2288 *
2289 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002290 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 */
2292 public abstract long computeBatteryRealtime(long curTime, int which);
2293
2294 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002295 * Returns the total, last, or current battery screen off uptime in microseconds.
2296 *
2297 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002298 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002299 */
2300 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2301
2302 /**
2303 * Returns the total, last, or current battery screen off realtime in microseconds.
2304 *
2305 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002306 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002307 */
2308 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2309
2310 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 * Returns the total, last, or current uptime in microseconds.
2312 *
2313 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002314 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 */
2316 public abstract long computeUptime(long curTime, int which);
2317
2318 /**
2319 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002320 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002322 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 */
2324 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002325
2326 /**
2327 * Compute an approximation for how much run time (in microseconds) is remaining on
2328 * the battery. Returns -1 if no time can be computed: either there is not
2329 * enough current data to make a decision, or the battery is currently
2330 * charging.
2331 *
2332 * @param curTime The current elepsed realtime in microseconds.
2333 */
2334 public abstract long computeBatteryTimeRemaining(long curTime);
2335
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002336 // The part of a step duration that is the actual time.
2337 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2338
2339 // Bits in a step duration that are the new battery level we are at.
2340 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002341 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002342
2343 // Bits in a step duration that are the initial mode we were in at that step.
2344 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002345 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002346
2347 // Bits in a step duration that indicate which modes changed during that step.
2348 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002349 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002350
2351 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2352 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2353
2354 // Step duration mode: power save is on.
2355 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2356
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002357 // Step duration mode: device is currently in idle mode.
2358 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2359
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002360 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2361 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002362 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2363 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002364 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2365 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2366 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2367 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2368 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002369 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2370 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002371 };
2372 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2373 (Display.STATE_OFF-1),
2374 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002375 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002376 (Display.STATE_ON-1),
2377 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2378 (Display.STATE_DOZE-1),
2379 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2380 (Display.STATE_DOZE_SUSPEND-1),
2381 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002382 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002383 };
2384 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2385 "screen off",
2386 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002387 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002388 "screen on",
2389 "screen on power save",
2390 "screen doze",
2391 "screen doze power save",
2392 "screen doze-suspend",
2393 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002394 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002395 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002396
2397 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002398 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2399 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2400 * a coulomb counter.
2401 */
2402 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2403
2404 /**
2405 * Return the counter keeping track of the amount of battery discharge measured in
2406 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2407 * a coulomb counter.
2408 */
2409 public abstract LongCounter getDischargeCoulombCounter();
2410
2411 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002412 * Returns the estimated real battery capacity, which may be less than the capacity
2413 * declared by the PowerProfile.
2414 * @return The estimated battery capacity in mAh.
2415 */
2416 public abstract int getEstimatedBatteryCapacity();
2417
2418 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002419 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002420 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002421 public abstract LevelStepTracker getDischargeLevelStepTracker();
2422
2423 /**
2424 * Return the array of daily discharge step durations.
2425 */
2426 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002427
2428 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002429 * Compute an approximation for how much time (in microseconds) remains until the battery
2430 * is fully charged. Returns -1 if no time can be computed: either there is not
2431 * enough current data to make a decision, or the battery is currently
2432 * discharging.
2433 *
2434 * @param curTime The current elepsed realtime in microseconds.
2435 */
2436 public abstract long computeChargeTimeRemaining(long curTime);
2437
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002438 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002439 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002440 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002441 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002442
2443 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002444 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002445 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002446 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002447
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002448 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2449
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002450 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002451
Evan Millarc64edde2009-04-18 12:26:32 -07002452 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453
James Carr2dd7e5e2016-07-20 18:48:39 -07002454 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2455
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002456 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2457
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002458 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 long days = seconds / (60 * 60 * 24);
2460 if (days != 0) {
2461 out.append(days);
2462 out.append("d ");
2463 }
2464 long used = days * 60 * 60 * 24;
2465
2466 long hours = (seconds - used) / (60 * 60);
2467 if (hours != 0 || used != 0) {
2468 out.append(hours);
2469 out.append("h ");
2470 }
2471 used += hours * 60 * 60;
2472
2473 long mins = (seconds-used) / 60;
2474 if (mins != 0 || used != 0) {
2475 out.append(mins);
2476 out.append("m ");
2477 }
2478 used += mins * 60;
2479
2480 if (seconds != 0 || used != 0) {
2481 out.append(seconds-used);
2482 out.append("s ");
2483 }
2484 }
2485
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002486 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002488 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 sb.append(time - (sec * 1000));
2490 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 }
2492
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002493 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002494 long sec = time / 1000;
2495 formatTimeRaw(sb, sec);
2496 sb.append(time - (sec * 1000));
2497 sb.append("ms");
2498 }
2499
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002500 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002502 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 }
2504 float perc = ((float)num) / ((float)den) * 100;
2505 mFormatBuilder.setLength(0);
2506 mFormatter.format("%.1f%%", perc);
2507 return mFormatBuilder.toString();
2508 }
2509
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002510 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002511 mFormatBuilder.setLength(0);
2512
2513 if (bytes < BYTES_PER_KB) {
2514 return bytes + "B";
2515 } else if (bytes < BYTES_PER_MB) {
2516 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2517 return mFormatBuilder.toString();
2518 } else if (bytes < BYTES_PER_GB){
2519 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2520 return mFormatBuilder.toString();
2521 } else {
2522 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2523 return mFormatBuilder.toString();
2524 }
2525 }
2526
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002527 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002528 if (timer != null) {
2529 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002530 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002531 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2532 return totalTimeMillis;
2533 }
2534 return 0;
2535 }
2536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 /**
2538 *
2539 * @param sb a StringBuilder object.
2540 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002541 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002543 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 * @param linePrefix a String to be prepended to each line of output.
2545 * @return the line prefix
2546 */
2547 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002548 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002551 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002552
Evan Millarc64edde2009-04-18 12:26:32 -07002553 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 if (totalTimeMillis != 0) {
2555 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002556 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002557 if (name != null) {
2558 sb.append(name);
2559 sb.append(' ');
2560 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 sb.append('(');
2562 sb.append(count);
2563 sb.append(" times)");
2564 return ", ";
2565 }
2566 }
2567 return linePrefix;
2568 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002569
2570 /**
2571 *
2572 * @param pw a PrintWriter object to print to.
2573 * @param sb a StringBuilder object.
2574 * @param timer a Timer object contining the wakelock times.
2575 * @param rawRealtime the current on-battery time in microseconds.
2576 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2577 * @param prefix a String to be prepended to each line of output.
2578 * @param type the name of the timer.
2579 */
2580 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
2581 long rawRealtime, int which, String prefix, String type) {
2582 if (timer != null) {
2583 // Convert from microseconds to milliseconds with rounding
2584 final long totalTime = (timer.getTotalTimeLocked(
2585 rawRealtime, which) + 500) / 1000;
2586 final int count = timer.getCountLocked(which);
2587 if (totalTime != 0) {
2588 sb.setLength(0);
2589 sb.append(prefix);
2590 sb.append(" ");
2591 sb.append(type);
2592 sb.append(": ");
2593 formatTimeMs(sb, totalTime);
2594 sb.append("realtime (");
2595 sb.append(count);
2596 sb.append(" times)");
2597 pw.println(sb.toString());
2598 return true;
2599 }
2600 }
2601 return false;
2602 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603
2604 /**
2605 * Checkin version of wakelock printer. Prints simple comma-separated list.
2606 *
2607 * @param sb a StringBuilder object.
2608 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002609 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002611 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 * @param linePrefix a String to be prepended to each line of output.
2613 * @return the line prefix
2614 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002615 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2616 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 long totalTimeMicros = 0;
2618 int count = 0;
2619 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002620 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002621 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002622 }
2623 sb.append(linePrefix);
2624 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2625 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002626 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 sb.append(count);
2628 return ",";
2629 }
2630
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002631 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2632 String type) {
2633 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2634 pw.print(',');
2635 pw.print(uid);
2636 pw.print(',');
2637 pw.print(category);
2638 pw.print(',');
2639 pw.print(type);
2640 }
2641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 /**
2643 * Dump a comma-separated line of values for terse checkin mode.
2644 *
2645 * @param pw the PageWriter to dump log to
2646 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2647 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2648 * @param args type-dependent data arguments
2649 */
2650 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2651 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002652 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002653 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002654 pw.print(',');
2655 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002656 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002657 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002658 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002659
2660 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002661 * Dump a given timer stat for terse checkin mode.
2662 *
2663 * @param pw the PageWriter to dump log to
2664 * @param uid the UID to log
2665 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2666 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2667 * @param timer a {@link Timer} to dump stats for
2668 * @param rawRealtime the current elapsed realtime of the system in microseconds
2669 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2670 */
2671 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2672 Timer timer, long rawRealtime, int which) {
2673 if (timer != null) {
2674 // Convert from microseconds to milliseconds with rounding
2675 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2676 / 1000;
2677 final int count = timer.getCountLocked(which);
2678 if (totalTime != 0) {
2679 dumpLine(pw, uid, category, type, totalTime, count);
2680 }
2681 }
2682 }
2683
2684 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002685 * Checks if the ControllerActivityCounter has any data worth dumping.
2686 */
2687 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2688 if (counter == null) {
2689 return false;
2690 }
2691
2692 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2693 || counter.getRxTimeCounter().getCountLocked(which) != 0
2694 || counter.getPowerCounter().getCountLocked(which) != 0) {
2695 return true;
2696 }
2697
2698 for (LongCounter c : counter.getTxTimeCounters()) {
2699 if (c.getCountLocked(which) != 0) {
2700 return true;
2701 }
2702 }
2703 return false;
2704 }
2705
2706 /**
2707 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2708 * The order of the arguments in the final check in line is:
2709 *
2710 * idle, rx, power, tx...
2711 *
2712 * where tx... is one or more transmit level times.
2713 */
2714 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2715 String type,
2716 ControllerActivityCounter counter,
2717 int which) {
2718 if (!controllerActivityHasData(counter, which)) {
2719 return;
2720 }
2721
2722 dumpLineHeader(pw, uid, category, type);
2723 pw.print(",");
2724 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2725 pw.print(",");
2726 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2727 pw.print(",");
2728 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2729 for (LongCounter c : counter.getTxTimeCounters()) {
2730 pw.print(",");
2731 pw.print(c.getCountLocked(which));
2732 }
2733 pw.println();
2734 }
2735
2736 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2737 String prefix, String controllerName,
2738 ControllerActivityCounter counter,
2739 int which) {
2740 if (controllerActivityHasData(counter, which)) {
2741 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2742 }
2743 }
2744
2745 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2746 String controllerName,
2747 ControllerActivityCounter counter, int which) {
2748 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2749 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2750 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2751 long totalTxTimeMs = 0;
2752 for (LongCounter txState : counter.getTxTimeCounters()) {
2753 totalTxTimeMs += txState.getCountLocked(which);
2754 }
2755
2756 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2757
2758 sb.setLength(0);
2759 sb.append(prefix);
2760 sb.append(" ");
2761 sb.append(controllerName);
2762 sb.append(" Idle time: ");
2763 formatTimeMs(sb, idleTimeMs);
2764 sb.append("(");
2765 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2766 sb.append(")");
2767 pw.println(sb.toString());
2768
2769 sb.setLength(0);
2770 sb.append(prefix);
2771 sb.append(" ");
2772 sb.append(controllerName);
2773 sb.append(" Rx time: ");
2774 formatTimeMs(sb, rxTimeMs);
2775 sb.append("(");
2776 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
2777 sb.append(")");
2778 pw.println(sb.toString());
2779
2780 sb.setLength(0);
2781 sb.append(prefix);
2782 sb.append(" ");
2783 sb.append(controllerName);
2784 sb.append(" Tx time: ");
2785 formatTimeMs(sb, totalTxTimeMs);
2786 sb.append("(");
2787 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
2788 sb.append(")");
2789 pw.println(sb.toString());
2790
2791 final int numTxLvls = counter.getTxTimeCounters().length;
2792 if (numTxLvls > 1) {
2793 for (int lvl = 0; lvl < numTxLvls; lvl++) {
2794 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
2795 sb.setLength(0);
2796 sb.append(prefix);
2797 sb.append(" [");
2798 sb.append(lvl);
2799 sb.append("] ");
2800 formatTimeMs(sb, txLvlTimeMs);
2801 sb.append("(");
2802 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
2803 sb.append(")");
2804 pw.println(sb.toString());
2805 }
2806 }
2807
2808 sb.setLength(0);
2809 sb.append(prefix);
2810 sb.append(" ");
2811 sb.append(controllerName);
2812 sb.append(" Power drain: ").append(
2813 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
2814 sb.append("mAh");
2815 pw.println(sb.toString());
2816 }
2817
2818 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07002819 * Temporary for settings.
2820 */
2821 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2822 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2823 }
2824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 /**
2826 * Checkin server version of dump to produce more compact, computer-readable log.
2827 *
2828 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002830 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2831 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2833 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2834 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2836 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002837 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2838 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2839 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 final long totalRealtime = computeRealtime(rawRealtime, which);
2841 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002842 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002843 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002844 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002845 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
2846 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002847 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002848 rawRealtime, which);
2849 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
2850 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002851 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002852 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002853 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002854 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002855 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
2856 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
2857 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002858
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002859 final StringBuilder sb = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002861 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07002862 final int NU = uidStats.size();
2863
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002864 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 // Dump "battery" stat
2867 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002868 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002869 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002870 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002871 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002872 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
2873 getEstimatedBatteryCapacity());
Adam Lesinski67c134f2016-06-10 15:15:08 -07002874
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002876 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002877 long fullWakeLockTimeTotal = 0;
2878 long partialWakeLockTimeTotal = 0;
2879
2880 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002881 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002882
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002883 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
2884 = u.getWakelockStats();
2885 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2886 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07002887
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002888 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2889 if (fullWakeTimer != null) {
2890 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2891 which);
2892 }
2893
2894 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2895 if (partialWakeTimer != null) {
2896 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
2897 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002898 }
2899 }
2900 }
Adam Lesinskie283d332015-04-16 12:29:25 -07002901
2902 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002903 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2904 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2905 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2906 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2907 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2908 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2909 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2910 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002911 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
2912 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002913 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2914 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002915 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
2916 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002917
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002918 // Dump Modem controller stats
2919 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
2920 getModemControllerActivity(), which);
2921
Adam Lesinskie283d332015-04-16 12:29:25 -07002922 // Dump Wifi controller stats
2923 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2924 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002925 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08002926 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002927
2928 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
2929 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002930
2931 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002932 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
2933 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 // Dump misc stats
2936 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07002937 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002938 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07002939 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002940 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002941 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002942 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
2943 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07002944 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002945 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
2946 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
2947 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
2948 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002949 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002950
2951 // Dump screen brightness stats
2952 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2953 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002954 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002955 }
2956 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002957
Dianne Hackborn627bba72009-03-24 22:32:56 -07002958 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002959 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2960 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002961 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002962 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002963 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002964 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002965 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002966 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002967 args[i] = getPhoneSignalStrengthCount(i, which);
2968 }
2969 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002970
Dianne Hackborn627bba72009-03-24 22:32:56 -07002971 // Dump network type stats
2972 args = new Object[NUM_DATA_CONNECTION_TYPES];
2973 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002974 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002975 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002976 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2977 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2978 args[i] = getPhoneDataConnectionCount(i, which);
2979 }
2980 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002981
2982 // Dump wifi state stats
2983 args = new Object[NUM_WIFI_STATES];
2984 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002985 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002986 }
2987 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2988 for (int i=0; i<NUM_WIFI_STATES; i++) {
2989 args[i] = getWifiStateCount(i, which);
2990 }
2991 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2992
Dianne Hackborn3251b902014-06-20 14:40:53 -07002993 // Dump wifi suppl state stats
2994 args = new Object[NUM_WIFI_SUPPL_STATES];
2995 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2996 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2997 }
2998 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2999 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3000 args[i] = getWifiSupplStateCount(i, which);
3001 }
3002 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3003
3004 // Dump wifi signal strength stats
3005 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3006 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3007 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3008 }
3009 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3010 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3011 args[i] = getWifiSignalStrengthCount(i, which);
3012 }
3013 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3014
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003015 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003016 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003017 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003020 if (which == STATS_SINCE_UNPLUGGED) {
3021 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3022 getDischargeStartLevel()-getDischargeCurrentLevel(),
3023 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003024 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
3025 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003026 } else {
3027 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3028 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003029 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003030 getDischargeAmountScreenOffSinceCharge(),
3031 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003032 }
3033
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003034 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003035 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003036 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003037 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003038 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003039 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003040 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003041 sb.toString());
3042 }
Evan Millarc64edde2009-04-18 12:26:32 -07003043 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003044 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003045 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003046 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3047 // Not doing the regular wake lock formatting to remain compatible
3048 // with the old checkin format.
3049 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3050 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003051 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003052 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003053 }
3054 }
Evan Millarc64edde2009-04-18 12:26:32 -07003055 }
3056
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003057 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003058 helper.create(this);
3059 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003060 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003061 if (sippers != null && sippers.size() > 0) {
3062 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3063 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003064 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003065 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3066 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3067 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003068 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003069 int uid = 0;
3070 String label;
3071 switch (bs.drainType) {
3072 case IDLE:
3073 label="idle";
3074 break;
3075 case CELL:
3076 label="cell";
3077 break;
3078 case PHONE:
3079 label="phone";
3080 break;
3081 case WIFI:
3082 label="wifi";
3083 break;
3084 case BLUETOOTH:
3085 label="blue";
3086 break;
3087 case SCREEN:
3088 label="scrn";
3089 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003090 case FLASHLIGHT:
3091 label="flashlight";
3092 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003093 case APP:
3094 uid = bs.uidObj.getUid();
3095 label = "uid";
3096 break;
3097 case USER:
3098 uid = UserHandle.getUid(bs.userId, 0);
3099 label = "user";
3100 break;
3101 case UNACCOUNTED:
3102 label = "unacc";
3103 break;
3104 case OVERCOUNTED:
3105 label = "over";
3106 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003107 case CAMERA:
3108 label = "camera";
3109 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003110 default:
3111 label = "???";
3112 }
3113 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07003114 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003115 }
3116 }
3117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003118 for (int iu = 0; iu < NU; iu++) {
3119 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003120 if (reqUid >= 0 && uid != reqUid) {
3121 continue;
3122 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003123 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003126 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3127 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3128 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3129 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3130 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3131 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3132 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3133 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003134 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003135 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3136 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003137 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003138 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3139 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003140 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3141 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003142 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Adam Lesinski5f056f62016-07-14 16:56:08 -07003143 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003144 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3145 wifiBytesRx, wifiBytesTx,
3146 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003147 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003148 mobileActiveTime, mobileActiveCount,
Adam Lesinski5f056f62016-07-14 16:56:08 -07003149 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003150 }
3151
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003152 // Dump modem controller data, per UID.
3153 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3154 u.getModemControllerActivity(), which);
3155
3156 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003157 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3158 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3159 final int wifiScanCount = u.getWifiScanCount(which);
3160 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003161 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003162 || uidWifiRunningTime != 0) {
3163 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3164 uidWifiRunningTime, wifiScanCount,
Kweku Adams5b2747e2016-04-25 10:44:05 -07003165 /* legacy fields follow, keep at 0 */ 0, 0, 0);
The Android Open Source Project10592532009-03-18 17:39:46 -07003166 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003168 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3169 u.getWifiControllerActivity(), which);
3170
Adam Lesinskiba9d8932016-04-12 12:06:03 -07003171 dumpTimer(pw, uid, category, BLUETOOTH_MISC_DATA, u.getBluetoothScanTimer(),
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003172 rawRealtime, which);
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003173
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003174 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3175 u.getBluetoothControllerActivity(), which);
3176
Dianne Hackborn617f8772009-03-31 15:04:46 -07003177 if (u.hasUserActivity()) {
3178 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3179 boolean hasData = false;
3180 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3181 int val = u.getUserActivityCount(i, which);
3182 args[i] = val;
3183 if (val != 0) hasData = true;
3184 }
3185 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003186 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003187 }
3188 }
3189
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003190 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3191 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3192 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3193 String linePrefix = "";
3194 sb.setLength(0);
3195 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3196 rawRealtime, "f", which, linePrefix);
3197 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
3198 rawRealtime, "p", which, linePrefix);
3199 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3200 rawRealtime, "w", which, linePrefix);
3201
3202 // Only log if we had at lease one wakelock...
3203 if (sb.length() > 0) {
3204 String name = wakelocks.keyAt(iw);
3205 if (name.indexOf(',') >= 0) {
3206 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003207 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003208 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 }
3210 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003211
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003212 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3213 for (int isy=syncs.size()-1; isy>=0; isy--) {
3214 final Timer timer = syncs.valueAt(isy);
3215 // Convert from microseconds to milliseconds with rounding
3216 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3217 final int count = timer.getCountLocked(which);
3218 if (totalTime != 0) {
3219 dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003220 }
3221 }
3222
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003223 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3224 for (int ij=jobs.size()-1; ij>=0; ij--) {
3225 final Timer timer = jobs.valueAt(ij);
3226 // Convert from microseconds to milliseconds with rounding
3227 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3228 final int count = timer.getCountLocked(which);
3229 if (totalTime != 0) {
3230 dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003231 }
3232 }
3233
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003234 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3235 rawRealtime, which);
3236 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3237 rawRealtime, which);
3238 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3239 rawRealtime, which);
3240 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3241 rawRealtime, which);
3242
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003243 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3244 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003245 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003246 final Uid.Sensor se = sensors.valueAt(ise);
3247 final int sensorNumber = sensors.keyAt(ise);
3248 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003249 if (timer != null) {
3250 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003251 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3252 / 1000;
3253 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003254 if (totalTime != 0) {
3255 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
3256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003257 }
3258 }
3259
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003260 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3261 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003262
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003263 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3264 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003265
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003266 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003267 long totalStateTime = 0;
3268 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003269 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3270 totalStateTime += time;
3271 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003272 }
3273 if (totalStateTime > 0) {
3274 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3275 }
3276
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003277 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3278 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
3279 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
3280 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
3281 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
3282 powerCpuMaUs / 1000);
3283 }
3284
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003285 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3286 = u.getProcessStats();
3287 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3288 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003289
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003290 final long userMillis = ps.getUserTime(which);
3291 final long systemMillis = ps.getSystemTime(which);
3292 final long foregroundMillis = ps.getForegroundTime(which);
3293 final int starts = ps.getStarts(which);
3294 final int numCrashes = ps.getNumCrashes(which);
3295 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003296
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003297 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3298 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
3299 dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis,
3300 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003301 }
3302 }
3303
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003304 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3305 = u.getPackageStats();
3306 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3307 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3308 int wakeups = 0;
3309 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3310 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003311 int count = alarms.valueAt(iwa).getCountLocked(which);
3312 wakeups += count;
3313 String name = alarms.keyAt(iwa).replace(',', '_');
3314 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003315 }
3316 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3317 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3318 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3319 final long startTime = ss.getStartTime(batteryUptime, which);
3320 final int starts = ss.getStarts(which);
3321 final int launches = ss.getLaunches(which);
3322 if (startTime != 0 || starts != 0 || launches != 0) {
3323 dumpLine(pw, uid, category, APK_DATA,
3324 wakeups, // wakeup alarms
3325 packageStats.keyAt(ipkg), // Apk
3326 serviceStats.keyAt(isvc), // service
3327 startTime / 1000, // time spent started, in ms
3328 starts,
3329 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 }
3331 }
3332 }
3333 }
3334 }
3335
Dianne Hackborn81038902012-11-26 17:04:09 -08003336 static final class TimerEntry {
3337 final String mName;
3338 final int mId;
3339 final BatteryStats.Timer mTimer;
3340 final long mTime;
3341 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3342 mName = name;
3343 mId = id;
3344 mTimer = timer;
3345 mTime = time;
3346 }
3347 }
3348
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003349 private void printmAh(PrintWriter printer, double power) {
3350 printer.print(BatteryStatsHelper.makemAh(power));
3351 }
3352
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003353 private void printmAh(StringBuilder sb, double power) {
3354 sb.append(BatteryStatsHelper.makemAh(power));
3355 }
3356
Dianne Hackbornd953c532014-08-16 18:17:38 -07003357 /**
3358 * Temporary for settings.
3359 */
3360 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3361 int reqUid) {
3362 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3363 }
3364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003366 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003367 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3369 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3370 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371
3372 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3373 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3374 final long totalRealtime = computeRealtime(rawRealtime, which);
3375 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003376 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3377 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3378 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003379 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3380 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003381
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003382 final StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07003383
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003384 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003385 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003387 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3388 if (estimatedBatteryCapacity > 0) {
3389 sb.setLength(0);
3390 sb.append(prefix);
3391 sb.append(" Estimated battery capacity: ");
3392 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3393 sb.append(" mAh");
3394 pw.println(sb.toString());
3395 }
3396
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003397 sb.setLength(0);
3398 sb.append(prefix);
3399 sb.append(" Time on battery: ");
3400 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3401 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3402 sb.append(") realtime, ");
3403 formatTimeMs(sb, whichBatteryUptime / 1000);
3404 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3405 sb.append(") uptime");
3406 pw.println(sb.toString());
3407 sb.setLength(0);
3408 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003409 sb.append(" Time on battery screen off: ");
3410 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3411 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3412 sb.append(") realtime, ");
3413 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3414 sb.append("(");
3415 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3416 sb.append(") uptime");
3417 pw.println(sb.toString());
3418 sb.setLength(0);
3419 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003420 sb.append(" Total run time: ");
3421 formatTimeMs(sb, totalRealtime / 1000);
3422 sb.append("realtime, ");
3423 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003424 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003425 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003426 if (batteryTimeRemaining >= 0) {
3427 sb.setLength(0);
3428 sb.append(prefix);
3429 sb.append(" Battery time remaining: ");
3430 formatTimeMs(sb, batteryTimeRemaining / 1000);
3431 pw.println(sb.toString());
3432 }
3433 if (chargeTimeRemaining >= 0) {
3434 sb.setLength(0);
3435 sb.append(prefix);
3436 sb.append(" Charge time remaining: ");
3437 formatTimeMs(sb, chargeTimeRemaining / 1000);
3438 pw.println(sb.toString());
3439 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003440
3441 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3442 final long dischargeCount = dischargeCounter.getCountLocked(which);
3443 if (dischargeCount >= 0) {
3444 sb.setLength(0);
3445 sb.append(prefix);
3446 sb.append(" Discharge: ");
3447 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3448 sb.append(" mAh");
3449 pw.println(sb.toString());
3450 }
3451
3452 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3453 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3454 if (dischargeScreenOffCount >= 0) {
3455 sb.setLength(0);
3456 sb.append(prefix);
3457 sb.append(" Screen off discharge: ");
3458 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3459 sb.append(" mAh");
3460 pw.println(sb.toString());
3461 }
3462
3463 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3464 if (dischargeScreenOnCount >= 0) {
3465 sb.setLength(0);
3466 sb.append(prefix);
3467 sb.append(" Screen on discharge: ");
3468 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3469 sb.append(" mAh");
3470 pw.println(sb.toString());
3471 }
3472
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003473 pw.print(" Start clock time: ");
3474 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3475
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003476 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003477 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003478 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003479 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3480 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003481 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003482 rawRealtime, which);
3483 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3484 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003485 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003486 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003487 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3488 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3489 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003490 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003491 sb.append(prefix);
3492 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3493 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003494 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003495 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3496 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003497 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003498 pw.println(sb.toString());
3499 sb.setLength(0);
3500 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003501 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003502 boolean didOne = false;
3503 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003504 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003505 if (time == 0) {
3506 continue;
3507 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003508 sb.append("\n ");
3509 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003510 didOne = true;
3511 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3512 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003513 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003514 sb.append("(");
3515 sb.append(formatRatioLocked(time, screenOnTime));
3516 sb.append(")");
3517 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003518 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003519 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003520 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003521 sb.setLength(0);
3522 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003523 sb.append(" Power save mode enabled: ");
3524 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003525 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003526 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003527 sb.append(")");
3528 pw.println(sb.toString());
3529 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003530 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003531 sb.setLength(0);
3532 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003533 sb.append(" Device light idling: ");
3534 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003535 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003536 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3537 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003538 sb.append("x");
3539 pw.println(sb.toString());
3540 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003541 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003542 sb.setLength(0);
3543 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003544 sb.append(" Idle mode light time: ");
3545 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003546 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003547 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3548 sb.append(") ");
3549 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003550 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003551 sb.append(" -- longest ");
3552 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3553 pw.println(sb.toString());
3554 }
3555 if (deviceIdlingTime != 0) {
3556 sb.setLength(0);
3557 sb.append(prefix);
3558 sb.append(" Device full idling: ");
3559 formatTimeMs(sb, deviceIdlingTime / 1000);
3560 sb.append("(");
3561 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003562 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003563 sb.append("x");
3564 pw.println(sb.toString());
3565 }
3566 if (deviceIdleModeFullTime != 0) {
3567 sb.setLength(0);
3568 sb.append(prefix);
3569 sb.append(" Idle mode full time: ");
3570 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3571 sb.append("(");
3572 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3573 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003574 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003575 sb.append("x");
3576 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003577 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003578 pw.println(sb.toString());
3579 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003580 if (phoneOnTime != 0) {
3581 sb.setLength(0);
3582 sb.append(prefix);
3583 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3584 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003585 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003586 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003587 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003588 if (connChanges != 0) {
3589 pw.print(prefix);
3590 pw.print(" Connectivity changes: "); pw.println(connChanges);
3591 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003592
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003593 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003594 long fullWakeLockTimeTotalMicros = 0;
3595 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003596
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003597 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003598
Evan Millar22ac0432009-03-31 11:33:18 -07003599 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003600 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003601
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003602 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3603 = u.getWakelockStats();
3604 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3605 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003606
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003607 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3608 if (fullWakeTimer != null) {
3609 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3610 rawRealtime, which);
3611 }
3612
3613 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3614 if (partialWakeTimer != null) {
3615 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3616 rawRealtime, which);
3617 if (totalTimeMicros > 0) {
3618 if (reqUid < 0) {
3619 // Only show the ordered list of all wake
3620 // locks if the caller is not asking for data
3621 // about a specific uid.
3622 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3623 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003624 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003625 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003626 }
3627 }
3628 }
3629 }
3630
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003631 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3632 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3633 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3634 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3635 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3636 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3637 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3638 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08003639 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3640 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003641
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003642 if (fullWakeLockTimeTotalMicros != 0) {
3643 sb.setLength(0);
3644 sb.append(prefix);
3645 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3646 (fullWakeLockTimeTotalMicros + 500) / 1000);
3647 pw.println(sb.toString());
3648 }
3649
3650 if (partialWakeLockTimeTotalMicros != 0) {
3651 sb.setLength(0);
3652 sb.append(prefix);
3653 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3654 (partialWakeLockTimeTotalMicros + 500) / 1000);
3655 pw.println(sb.toString());
3656 }
3657
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003658 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003659 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3660 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3661 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3662 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003663 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003664 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003665 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003666 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003667 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003668 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003669 if (time == 0) {
3670 continue;
3671 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003672 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003673 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003674 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003675 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003676 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003677 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003678 sb.append("(");
3679 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003680 sb.append(") ");
3681 sb.append(getPhoneSignalStrengthCount(i, which));
3682 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003683 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003684 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003685 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003686
3687 sb.setLength(0);
3688 sb.append(prefix);
3689 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003690 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003691 pw.println(sb.toString());
3692
Dianne Hackborn627bba72009-03-24 22:32:56 -07003693 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003694 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003695 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003696 didOne = false;
3697 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003698 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003699 if (time == 0) {
3700 continue;
3701 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003702 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003703 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003704 didOne = true;
3705 sb.append(DATA_CONNECTION_NAMES[i]);
3706 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003707 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003708 sb.append("(");
3709 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003710 sb.append(") ");
3711 sb.append(getPhoneDataConnectionCount(i, which));
3712 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003713 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003714 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003715 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003716
3717 sb.setLength(0);
3718 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003719 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003720 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003721 formatTimeMs(sb, mobileActiveTime / 1000);
3722 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3723 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3724 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003725 pw.println(sb.toString());
3726
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003727 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3728 if (mobileActiveUnknownTime != 0) {
3729 sb.setLength(0);
3730 sb.append(prefix);
3731 sb.append(" Mobile radio active unknown time: ");
3732 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3733 sb.append("(");
3734 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3735 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3736 sb.append("x");
3737 pw.println(sb.toString());
3738 }
3739
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003740 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3741 if (mobileActiveAdjustedTime != 0) {
3742 sb.setLength(0);
3743 sb.append(prefix);
3744 sb.append(" Mobile radio active adjusted time: ");
3745 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3746 sb.append("(");
3747 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3748 sb.append(")");
3749 pw.println(sb.toString());
3750 }
3751
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003752 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
3753
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003754 pw.print(prefix);
3755 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3756 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3757 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3758 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003759 sb.setLength(0);
3760 sb.append(prefix);
3761 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3762 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3763 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3764 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003765 sb.append(")");
3766 pw.println(sb.toString());
3767
3768 sb.setLength(0);
3769 sb.append(prefix);
3770 sb.append(" Wifi states:");
3771 didOne = false;
3772 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003773 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003774 if (time == 0) {
3775 continue;
3776 }
3777 sb.append("\n ");
3778 didOne = true;
3779 sb.append(WIFI_STATE_NAMES[i]);
3780 sb.append(" ");
3781 formatTimeMs(sb, time/1000);
3782 sb.append("(");
3783 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3784 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003785 sb.append(getWifiStateCount(i, which));
3786 sb.append("x");
3787 }
3788 if (!didOne) sb.append(" (no activity)");
3789 pw.println(sb.toString());
3790
3791 sb.setLength(0);
3792 sb.append(prefix);
3793 sb.append(" Wifi supplicant states:");
3794 didOne = false;
3795 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3796 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3797 if (time == 0) {
3798 continue;
3799 }
3800 sb.append("\n ");
3801 didOne = true;
3802 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3803 sb.append(" ");
3804 formatTimeMs(sb, time/1000);
3805 sb.append("(");
3806 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3807 sb.append(") ");
3808 sb.append(getWifiSupplStateCount(i, which));
3809 sb.append("x");
3810 }
3811 if (!didOne) sb.append(" (no activity)");
3812 pw.println(sb.toString());
3813
3814 sb.setLength(0);
3815 sb.append(prefix);
3816 sb.append(" Wifi signal levels:");
3817 didOne = false;
3818 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3819 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3820 if (time == 0) {
3821 continue;
3822 }
3823 sb.append("\n ");
3824 sb.append(prefix);
3825 didOne = true;
3826 sb.append("level(");
3827 sb.append(i);
3828 sb.append(") ");
3829 formatTimeMs(sb, time/1000);
3830 sb.append("(");
3831 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3832 sb.append(") ");
3833 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003834 sb.append("x");
3835 }
3836 if (!didOne) sb.append(" (no activity)");
3837 pw.println(sb.toString());
3838
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003839 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07003840
Adam Lesinski50e47602015-12-04 17:04:54 -08003841 pw.print(prefix);
3842 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
3843 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
3844
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003845 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
3846 sb.setLength(0);
3847 sb.append(prefix);
3848 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
3849 pw.println(sb.toString());
3850
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003851 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
3852 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003853
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003854 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003855
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003856 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003857 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003858 pw.print(prefix); pw.println(" Device is currently unplugged");
3859 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3860 pw.println(getDischargeStartLevel());
3861 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3862 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003863 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003864 pw.print(prefix); pw.println(" Device is currently plugged into power");
3865 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3866 pw.println(getDischargeStartLevel());
3867 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3868 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003869 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003870 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3871 pw.println(getDischargeAmountScreenOn());
3872 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3873 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003874 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003875 } else {
3876 pw.print(prefix); pw.println(" Device battery use since last full charge");
3877 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3878 pw.println(getLowDischargeAmountSinceCharge());
3879 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3880 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003881 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3882 pw.println(getDischargeAmountScreenOnSinceCharge());
3883 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3884 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003885 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003886 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003887
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003888 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003889 helper.create(this);
3890 helper.refreshStats(which, UserHandle.USER_ALL);
3891 List<BatterySipper> sippers = helper.getUsageList();
3892 if (sippers != null && sippers.size() > 0) {
3893 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3894 pw.print(prefix); pw.print(" Capacity: ");
3895 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003896 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003897 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3898 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3899 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3900 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003901 pw.println();
3902 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003903 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003904 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003905 switch (bs.drainType) {
3906 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003907 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003908 break;
3909 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003910 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003911 break;
3912 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003913 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003914 break;
3915 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003916 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003917 break;
3918 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003919 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003920 break;
3921 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003922 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003923 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003924 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003925 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003926 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003927 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003928 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003929 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003930 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003931 break;
3932 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003933 pw.print(" User "); pw.print(bs.userId);
3934 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003935 break;
3936 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003937 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003938 break;
3939 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003940 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003941 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003942 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003943 pw.print(" Camera: ");
3944 break;
3945 default:
3946 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003947 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003948 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003949 printmAh(pw, bs.totalPowerMah);
3950
Adam Lesinski57123002015-06-12 16:12:07 -07003951 if (bs.usagePowerMah != bs.totalPowerMah) {
3952 // If the usage (generic power) isn't the whole amount, we list out
3953 // what components are involved in the calculation.
3954
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003955 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07003956 if (bs.usagePowerMah != 0) {
3957 pw.print(" usage=");
3958 printmAh(pw, bs.usagePowerMah);
3959 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003960 if (bs.cpuPowerMah != 0) {
3961 pw.print(" cpu=");
3962 printmAh(pw, bs.cpuPowerMah);
3963 }
3964 if (bs.wakeLockPowerMah != 0) {
3965 pw.print(" wake=");
3966 printmAh(pw, bs.wakeLockPowerMah);
3967 }
3968 if (bs.mobileRadioPowerMah != 0) {
3969 pw.print(" radio=");
3970 printmAh(pw, bs.mobileRadioPowerMah);
3971 }
3972 if (bs.wifiPowerMah != 0) {
3973 pw.print(" wifi=");
3974 printmAh(pw, bs.wifiPowerMah);
3975 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003976 if (bs.bluetoothPowerMah != 0) {
3977 pw.print(" bt=");
3978 printmAh(pw, bs.bluetoothPowerMah);
3979 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003980 if (bs.gpsPowerMah != 0) {
3981 pw.print(" gps=");
3982 printmAh(pw, bs.gpsPowerMah);
3983 }
3984 if (bs.sensorPowerMah != 0) {
3985 pw.print(" sensor=");
3986 printmAh(pw, bs.sensorPowerMah);
3987 }
3988 if (bs.cameraPowerMah != 0) {
3989 pw.print(" camera=");
3990 printmAh(pw, bs.cameraPowerMah);
3991 }
3992 if (bs.flashlightPowerMah != 0) {
3993 pw.print(" flash=");
3994 printmAh(pw, bs.flashlightPowerMah);
3995 }
3996 pw.print(" )");
3997 }
3998 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003999 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004000 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004001 }
4002
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004003 sippers = helper.getMobilemsppList();
4004 if (sippers != null && sippers.size() > 0) {
4005 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004006 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004007 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004008 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004009 sb.setLength(0);
4010 sb.append(prefix); sb.append(" Uid ");
4011 UserHandle.formatUid(sb, bs.uidObj.getUid());
4012 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4013 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4014 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004015 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004016 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004017 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004018 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004019 sb.setLength(0);
4020 sb.append(prefix);
4021 sb.append(" TOTAL TIME: ");
4022 formatTimeMs(sb, totalTime);
4023 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4024 sb.append(")");
4025 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004026 pw.println();
4027 }
4028
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004029 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4030 @Override
4031 public int compare(TimerEntry lhs, TimerEntry rhs) {
4032 long lhsTime = lhs.mTime;
4033 long rhsTime = rhs.mTime;
4034 if (lhsTime < rhsTime) {
4035 return 1;
4036 }
4037 if (lhsTime > rhsTime) {
4038 return -1;
4039 }
4040 return 0;
4041 }
4042 };
4043
4044 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004045 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4046 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004047 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004048 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4049 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4050 : kernelWakelocks.entrySet()) {
4051 final BatteryStats.Timer timer = ent.getValue();
4052 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004053 if (totalTimeMillis > 0) {
4054 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4055 }
4056 }
4057 if (ktimers.size() > 0) {
4058 Collections.sort(ktimers, timerComparator);
4059 pw.print(prefix); pw.println(" All kernel wake locks:");
4060 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004061 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004062 String linePrefix = ": ";
4063 sb.setLength(0);
4064 sb.append(prefix);
4065 sb.append(" Kernel Wake lock ");
4066 sb.append(timer.mName);
4067 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4068 which, linePrefix);
4069 if (!linePrefix.equals(": ")) {
4070 sb.append(" realtime");
4071 // Only print out wake locks that were held
4072 pw.println(sb.toString());
4073 }
4074 }
4075 pw.println();
4076 }
4077 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004078
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004079 if (timers.size() > 0) {
4080 Collections.sort(timers, timerComparator);
4081 pw.print(prefix); pw.println(" All partial wake locks:");
4082 for (int i=0; i<timers.size(); i++) {
4083 TimerEntry timer = timers.get(i);
4084 sb.setLength(0);
4085 sb.append(" Wake lock ");
4086 UserHandle.formatUid(sb, timer.mId);
4087 sb.append(" ");
4088 sb.append(timer.mName);
4089 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4090 sb.append(" realtime");
4091 pw.println(sb.toString());
4092 }
4093 timers.clear();
4094 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004095 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004096
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004097 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004098 if (wakeupReasons.size() > 0) {
4099 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004100 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004101 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004102 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004103 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4104 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004105 }
4106 Collections.sort(reasons, timerComparator);
4107 for (int i=0; i<reasons.size(); i++) {
4108 TimerEntry timer = reasons.get(i);
4109 String linePrefix = ": ";
4110 sb.setLength(0);
4111 sb.append(prefix);
4112 sb.append(" Wakeup reason ");
4113 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004114 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4115 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004116 pw.println(sb.toString());
4117 }
4118 pw.println();
4119 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004120 }
Evan Millar22ac0432009-03-31 11:33:18 -07004121
James Carr2dd7e5e2016-07-20 18:48:39 -07004122 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
4123 pw.println("Memory Stats");
4124 for (int i = 0; i < mMemoryStats.size(); i++) {
4125 sb.setLength(0);
4126 sb.append("Bandwidth ");
4127 sb.append(mMemoryStats.keyAt(i));
4128 sb.append(" Time ");
4129 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4130 pw.println(sb.toString());
4131 }
4132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 for (int iu=0; iu<NU; iu++) {
4134 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004135 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004136 continue;
4137 }
4138
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004139 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004140
4141 pw.print(prefix);
4142 pw.print(" ");
4143 UserHandle.formatUid(pw, uid);
4144 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004146
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004147 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4148 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4149 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4150 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004151 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4152 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4153
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004154 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4155 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004156 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4157 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004158
4159 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4160 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4161
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004162 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4163 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4164 final int wifiScanCount = u.getWifiScanCount(which);
4165 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004166
Adam Lesinski5f056f62016-07-14 16:56:08 -07004167 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4168 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4169
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004170 if (mobileRxBytes > 0 || mobileTxBytes > 0
4171 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004172 pw.print(prefix); pw.print(" Mobile network: ");
4173 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004174 pw.print(formatBytesLocked(mobileTxBytes));
4175 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4176 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004178 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4179 sb.setLength(0);
4180 sb.append(prefix); sb.append(" Mobile radio active: ");
4181 formatTimeMs(sb, uidMobileActiveTime / 1000);
4182 sb.append("(");
4183 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4184 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4185 long packets = mobileRxPackets + mobileTxPackets;
4186 if (packets == 0) {
4187 packets = 1;
4188 }
4189 sb.append(" @ ");
4190 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4191 sb.append(" mspp");
4192 pw.println(sb.toString());
4193 }
4194
Adam Lesinski5f056f62016-07-14 16:56:08 -07004195 if (mobileWakeup > 0) {
4196 sb.setLength(0);
4197 sb.append(prefix);
4198 sb.append(" Mobile radio AP wakeups: ");
4199 sb.append(mobileWakeup);
4200 pw.println(sb.toString());
4201 }
4202
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004203 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4204 u.getModemControllerActivity(), which);
4205
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004206 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004207 pw.print(prefix); pw.print(" Wi-Fi network: ");
4208 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004209 pw.print(formatBytesLocked(wifiTxBytes));
4210 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4211 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004212 }
4213
Dianne Hackborn62793e42015-03-09 11:15:41 -07004214 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004215 || uidWifiRunningTime != 0) {
4216 sb.setLength(0);
4217 sb.append(prefix); sb.append(" Wifi Running: ");
4218 formatTimeMs(sb, uidWifiRunningTime / 1000);
4219 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4220 whichBatteryRealtime)); sb.append(")\n");
4221 sb.append(prefix); sb.append(" Full Wifi Lock: ");
4222 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4223 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4224 whichBatteryRealtime)); sb.append(")\n");
4225 sb.append(prefix); sb.append(" Wifi Scan: ");
4226 formatTimeMs(sb, wifiScanTime / 1000);
4227 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004228 whichBatteryRealtime)); sb.append(") ");
4229 sb.append(wifiScanCount);
4230 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004231 pw.println(sb.toString());
4232 }
4233
Adam Lesinski5f056f62016-07-14 16:56:08 -07004234 if (wifiWakeup > 0) {
4235 sb.setLength(0);
4236 sb.append(prefix);
4237 sb.append(" WiFi AP wakeups: ");
4238 sb.append(wifiWakeup);
4239 pw.println(sb.toString());
4240 }
4241
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004242 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4243 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004244
Adam Lesinski50e47602015-12-04 17:04:54 -08004245 if (btRxBytes > 0 || btTxBytes > 0) {
4246 pw.print(prefix); pw.print(" Bluetooth network: ");
4247 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4248 pw.print(formatBytesLocked(btTxBytes));
4249 pw.println(" sent");
4250 }
4251
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004252 uidActivity |= printTimer(pw, sb, u.getBluetoothScanTimer(), rawRealtime, which, prefix,
4253 "Bluetooth Scan");
4254
Dianne Hackborn617f8772009-03-31 15:04:46 -07004255 if (u.hasUserActivity()) {
4256 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004257 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004258 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004259 if (val != 0) {
4260 if (!hasData) {
4261 sb.setLength(0);
4262 sb.append(" User activity: ");
4263 hasData = true;
4264 } else {
4265 sb.append(", ");
4266 }
4267 sb.append(val);
4268 sb.append(" ");
4269 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4270 }
4271 }
4272 if (hasData) {
4273 pw.println(sb.toString());
4274 }
4275 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004276
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004277 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4278 = u.getWakelockStats();
4279 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004280 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004281 int countWakelock = 0;
4282 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4283 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4284 String linePrefix = ": ";
4285 sb.setLength(0);
4286 sb.append(prefix);
4287 sb.append(" Wake lock ");
4288 sb.append(wakelocks.keyAt(iw));
4289 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4290 "full", which, linePrefix);
4291 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
4292 "partial", which, linePrefix);
4293 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4294 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004295 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4296 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004297 sb.append(" realtime");
4298 pw.println(sb.toString());
4299 uidActivity = true;
4300 countWakelock++;
4301
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004302 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4303 rawRealtime, which);
4304 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4305 rawRealtime, which);
4306 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4307 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004308 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004309 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004310 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004311 if (countWakelock > 1) {
4312 if (totalFullWakelock != 0 || totalPartialWakelock != 0
4313 || totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004314 sb.setLength(0);
4315 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004316 sb.append(" TOTAL wake: ");
4317 boolean needComma = false;
4318 if (totalFullWakelock != 0) {
4319 needComma = true;
4320 formatTimeMs(sb, totalFullWakelock);
4321 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004322 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004323 if (totalPartialWakelock != 0) {
4324 if (needComma) {
4325 sb.append(", ");
4326 }
4327 needComma = true;
4328 formatTimeMs(sb, totalPartialWakelock);
4329 sb.append("partial");
4330 }
4331 if (totalWindowWakelock != 0) {
4332 if (needComma) {
4333 sb.append(", ");
4334 }
4335 needComma = true;
4336 formatTimeMs(sb, totalWindowWakelock);
4337 sb.append("window");
4338 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004339 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004340 if (needComma) {
4341 sb.append(",");
4342 }
4343 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004344 formatTimeMs(sb, totalDrawWakelock);
4345 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004346 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004347 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004348 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004349 }
4350 }
4351
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004352 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4353 for (int isy=syncs.size()-1; isy>=0; isy--) {
4354 final Timer timer = syncs.valueAt(isy);
4355 // Convert from microseconds to milliseconds with rounding
4356 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4357 final int count = timer.getCountLocked(which);
4358 sb.setLength(0);
4359 sb.append(prefix);
4360 sb.append(" Sync ");
4361 sb.append(syncs.keyAt(isy));
4362 sb.append(": ");
4363 if (totalTime != 0) {
4364 formatTimeMs(sb, totalTime);
4365 sb.append("realtime (");
4366 sb.append(count);
4367 sb.append(" times)");
4368 } else {
4369 sb.append("(not used)");
4370 }
4371 pw.println(sb.toString());
4372 uidActivity = true;
4373 }
4374
4375 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4376 for (int ij=jobs.size()-1; ij>=0; ij--) {
4377 final Timer timer = jobs.valueAt(ij);
4378 // Convert from microseconds to milliseconds with rounding
4379 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4380 final int count = timer.getCountLocked(which);
4381 sb.setLength(0);
4382 sb.append(prefix);
4383 sb.append(" Job ");
4384 sb.append(jobs.keyAt(ij));
4385 sb.append(": ");
4386 if (totalTime != 0) {
4387 formatTimeMs(sb, totalTime);
4388 sb.append("realtime (");
4389 sb.append(count);
4390 sb.append(" times)");
4391 } else {
4392 sb.append("(not used)");
4393 }
4394 pw.println(sb.toString());
4395 uidActivity = true;
4396 }
4397
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004398 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
4399 prefix, "Flashlight");
4400 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
4401 prefix, "Camera");
4402 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
4403 prefix, "Video");
4404 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
4405 prefix, "Audio");
4406
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004407 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4408 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004409 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004410 final Uid.Sensor se = sensors.valueAt(ise);
4411 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004412 sb.setLength(0);
4413 sb.append(prefix);
4414 sb.append(" Sensor ");
4415 int handle = se.getHandle();
4416 if (handle == Uid.Sensor.GPS) {
4417 sb.append("GPS");
4418 } else {
4419 sb.append(handle);
4420 }
4421 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004422
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004423 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004424 if (timer != null) {
4425 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004426 final long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn61659e52014-07-09 16:13:01 -07004427 rawRealtime, which) + 500) / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004428 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004429 //timer.logState();
4430 if (totalTime != 0) {
4431 formatTimeMs(sb, totalTime);
4432 sb.append("realtime (");
4433 sb.append(count);
4434 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 } else {
4436 sb.append("(not used)");
4437 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004438 } else {
4439 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004440 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004441
4442 pw.println(sb.toString());
4443 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 }
4445
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004446 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4447 "Vibrator");
4448 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4449 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004450
Dianne Hackborn61659e52014-07-09 16:13:01 -07004451 long totalStateTime = 0;
4452 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4453 long time = u.getProcessStateTime(ips, rawRealtime, which);
4454 if (time > 0) {
4455 totalStateTime += time;
4456 sb.setLength(0);
4457 sb.append(prefix);
4458 sb.append(" ");
4459 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4460 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08004461 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004462 pw.println(sb.toString());
4463 uidActivity = true;
4464 }
4465 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08004466 if (totalStateTime > 0) {
4467 sb.setLength(0);
4468 sb.append(prefix);
4469 sb.append(" Total running: ");
4470 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4471 pw.println(sb.toString());
4472 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004473
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004474 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4475 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004476 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
4477 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004478 sb.setLength(0);
4479 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004480 sb.append(" Total cpu time: u=");
4481 formatTimeMs(sb, userCpuTimeUs / 1000);
4482 sb.append("s=");
4483 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004484 sb.append("p=");
4485 printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0));
4486 sb.append("mAh");
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004487 pw.println(sb.toString());
4488 }
4489
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004490 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4491 = u.getProcessStats();
4492 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4493 final Uid.Proc ps = processStats.valueAt(ipr);
4494 long userTime;
4495 long systemTime;
4496 long foregroundTime;
4497 int starts;
4498 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004500 userTime = ps.getUserTime(which);
4501 systemTime = ps.getSystemTime(which);
4502 foregroundTime = ps.getForegroundTime(which);
4503 starts = ps.getStarts(which);
4504 final int numCrashes = ps.getNumCrashes(which);
4505 final int numAnrs = ps.getNumAnrs(which);
4506 numExcessive = which == STATS_SINCE_CHARGED
4507 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004508
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004509 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
4510 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
4511 sb.setLength(0);
4512 sb.append(prefix); sb.append(" Proc ");
4513 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
4514 sb.append(prefix); sb.append(" CPU: ");
4515 formatTimeMs(sb, userTime); sb.append("usr + ");
4516 formatTimeMs(sb, systemTime); sb.append("krn ; ");
4517 formatTimeMs(sb, foregroundTime); sb.append("fg");
4518 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
4519 sb.append("\n"); sb.append(prefix); sb.append(" ");
4520 boolean hasOne = false;
4521 if (starts != 0) {
4522 hasOne = true;
4523 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07004524 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004525 if (numCrashes != 0) {
4526 if (hasOne) {
4527 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004528 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004529 hasOne = true;
4530 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004531 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004532 if (numAnrs != 0) {
4533 if (hasOne) {
4534 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004535 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004536 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004537 }
4538 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004539 pw.println(sb.toString());
4540 for (int e=0; e<numExcessive; e++) {
4541 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
4542 if (ew != null) {
4543 pw.print(prefix); pw.print(" * Killed for ");
4544 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
4545 pw.print("wake lock");
4546 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
4547 pw.print("cpu");
4548 } else {
4549 pw.print("unknown");
4550 }
4551 pw.print(" use: ");
4552 TimeUtils.formatDuration(ew.usedTime, pw);
4553 pw.print(" over ");
4554 TimeUtils.formatDuration(ew.overTime, pw);
4555 if (ew.overTime != 0) {
4556 pw.print(" (");
4557 pw.print((ew.usedTime*100)/ew.overTime);
4558 pw.println("%)");
4559 }
4560 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004561 }
4562 uidActivity = true;
4563 }
4564 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004565
4566 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4567 = u.getPackageStats();
4568 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4569 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
4570 pw.println(":");
4571 boolean apkActivity = false;
4572 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4573 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4574 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
4575 pw.print(prefix); pw.print(" Wakeup alarm ");
4576 pw.print(alarms.keyAt(iwa)); pw.print(": ");
4577 pw.print(alarms.valueAt(iwa).getCountLocked(which));
4578 pw.println(" times");
4579 apkActivity = true;
4580 }
4581 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4582 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4583 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4584 final long startTime = ss.getStartTime(batteryUptime, which);
4585 final int starts = ss.getStarts(which);
4586 final int launches = ss.getLaunches(which);
4587 if (startTime != 0 || starts != 0 || launches != 0) {
4588 sb.setLength(0);
4589 sb.append(prefix); sb.append(" Service ");
4590 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
4591 sb.append(prefix); sb.append(" Created for: ");
4592 formatTimeMs(sb, startTime / 1000);
4593 sb.append("uptime\n");
4594 sb.append(prefix); sb.append(" Starts: ");
4595 sb.append(starts);
4596 sb.append(", launches: "); sb.append(launches);
4597 pw.println(sb.toString());
4598 apkActivity = true;
4599 }
4600 }
4601 if (!apkActivity) {
4602 pw.print(prefix); pw.println(" (nothing executed)");
4603 }
4604 uidActivity = true;
4605 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004606 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004607 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004608 }
4609 }
4610 }
4611
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004612 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004613 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004614 int diff = oldval ^ newval;
4615 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004616 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004617 for (int i=0; i<descriptions.length; i++) {
4618 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004619 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004620 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004621 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004622 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004623 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004624 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
4625 didWake = true;
4626 pw.print("=");
4627 if (longNames) {
4628 UserHandle.formatUid(pw, wakelockTag.uid);
4629 pw.print(":\"");
4630 pw.print(wakelockTag.string);
4631 pw.print("\"");
4632 } else {
4633 pw.print(wakelockTag.poolIdx);
4634 }
4635 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004636 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004637 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004638 pw.print("=");
4639 int val = (newval&bd.mask)>>bd.shift;
4640 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004641 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004642 } else {
4643 pw.print(val);
4644 }
4645 }
4646 }
4647 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004648 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07004649 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004650 if (longNames) {
4651 UserHandle.formatUid(pw, wakelockTag.uid);
4652 pw.print(":\"");
4653 pw.print(wakelockTag.string);
4654 pw.print("\"");
4655 } else {
4656 pw.print(wakelockTag.poolIdx);
4657 }
4658 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004659 }
4660
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004661 public void prepareForDumpLocked() {
4662 }
4663
4664 public static class HistoryPrinter {
4665 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004666 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004667 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004668 int oldStatus = -1;
4669 int oldHealth = -1;
4670 int oldPlug = -1;
4671 int oldTemp = -1;
4672 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004673 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004674 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004675
Dianne Hackborn3251b902014-06-20 14:40:53 -07004676 void reset() {
4677 oldState = oldState2 = 0;
4678 oldLevel = -1;
4679 oldStatus = -1;
4680 oldHealth = -1;
4681 oldPlug = -1;
4682 oldTemp = -1;
4683 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004684 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07004685 }
4686
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004687 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004688 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004689 if (!checkin) {
4690 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004691 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004692 pw.print(" (");
4693 pw.print(rec.numReadInts);
4694 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004695 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004696 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4697 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004698 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004699 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004700 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004701 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004702 }
4703 lastTime = rec.time;
4704 }
4705 if (rec.cmd == HistoryItem.CMD_START) {
4706 if (checkin) {
4707 pw.print(":");
4708 }
4709 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004710 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004711 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4712 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004713 if (checkin) {
4714 pw.print(":");
4715 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004716 if (rec.cmd == HistoryItem.CMD_RESET) {
4717 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004718 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004719 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004720 pw.print("TIME:");
4721 if (checkin) {
4722 pw.println(rec.currentTime);
4723 } else {
4724 pw.print(" ");
4725 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4726 rec.currentTime).toString());
4727 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004728 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4729 if (checkin) {
4730 pw.print(":");
4731 }
4732 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004733 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4734 if (checkin) {
4735 pw.print(":");
4736 }
4737 pw.println("*OVERFLOW*");
4738 } else {
4739 if (!checkin) {
4740 if (rec.batteryLevel < 10) pw.print("00");
4741 else if (rec.batteryLevel < 100) pw.print("0");
4742 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004743 if (verbose) {
4744 pw.print(" ");
4745 if (rec.states < 0) ;
4746 else if (rec.states < 0x10) pw.print("0000000");
4747 else if (rec.states < 0x100) pw.print("000000");
4748 else if (rec.states < 0x1000) pw.print("00000");
4749 else if (rec.states < 0x10000) pw.print("0000");
4750 else if (rec.states < 0x100000) pw.print("000");
4751 else if (rec.states < 0x1000000) pw.print("00");
4752 else if (rec.states < 0x10000000) pw.print("0");
4753 pw.print(Integer.toHexString(rec.states));
4754 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004755 } else {
4756 if (oldLevel != rec.batteryLevel) {
4757 oldLevel = rec.batteryLevel;
4758 pw.print(",Bl="); pw.print(rec.batteryLevel);
4759 }
4760 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004761 if (oldStatus != rec.batteryStatus) {
4762 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004763 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004764 switch (oldStatus) {
4765 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004766 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004767 break;
4768 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004769 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004770 break;
4771 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004772 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004773 break;
4774 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004775 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004776 break;
4777 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004778 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004779 break;
4780 default:
4781 pw.print(oldStatus);
4782 break;
4783 }
4784 }
4785 if (oldHealth != rec.batteryHealth) {
4786 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004787 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004788 switch (oldHealth) {
4789 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004790 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004791 break;
4792 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004793 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004794 break;
4795 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004796 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004797 break;
4798 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004799 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004800 break;
4801 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004802 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004803 break;
4804 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004805 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004806 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004807 case BatteryManager.BATTERY_HEALTH_COLD:
4808 pw.print(checkin ? "c" : "cold");
4809 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004810 default:
4811 pw.print(oldHealth);
4812 break;
4813 }
4814 }
4815 if (oldPlug != rec.batteryPlugType) {
4816 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004817 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004818 switch (oldPlug) {
4819 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004820 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004821 break;
4822 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004823 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004824 break;
4825 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004826 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004827 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004828 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004829 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004830 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004831 default:
4832 pw.print(oldPlug);
4833 break;
4834 }
4835 }
4836 if (oldTemp != rec.batteryTemperature) {
4837 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004838 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004839 pw.print(oldTemp);
4840 }
4841 if (oldVolt != rec.batteryVoltage) {
4842 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004843 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004844 pw.print(oldVolt);
4845 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004846 final int chargeMAh = rec.batteryChargeUAh / 1000;
4847 if (oldChargeMAh != chargeMAh) {
4848 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07004849 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004850 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07004851 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004852 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004853 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004854 printBitDescriptions(pw, oldState2, rec.states2, null,
4855 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004856 if (rec.wakeReasonTag != null) {
4857 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004858 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004859 pw.print(rec.wakeReasonTag.poolIdx);
4860 } else {
4861 pw.print(" wake_reason=");
4862 pw.print(rec.wakeReasonTag.uid);
4863 pw.print(":\"");
4864 pw.print(rec.wakeReasonTag.string);
4865 pw.print("\"");
4866 }
4867 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004868 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004869 pw.print(checkin ? "," : " ");
4870 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4871 pw.print("+");
4872 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4873 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004874 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004875 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4876 : HISTORY_EVENT_NAMES;
4877 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4878 | HistoryItem.EVENT_FLAG_FINISH);
4879 if (idx >= 0 && idx < eventNames.length) {
4880 pw.print(eventNames[idx]);
4881 } else {
4882 pw.print(checkin ? "Ev" : "event");
4883 pw.print(idx);
4884 }
4885 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004886 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004887 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004888 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004889 UserHandle.formatUid(pw, rec.eventTag.uid);
4890 pw.print(":\"");
4891 pw.print(rec.eventTag.string);
4892 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004893 }
4894 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004895 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004896 if (rec.stepDetails != null) {
4897 if (!checkin) {
4898 pw.print(" Details: cpu=");
4899 pw.print(rec.stepDetails.userTime);
4900 pw.print("u+");
4901 pw.print(rec.stepDetails.systemTime);
4902 pw.print("s");
4903 if (rec.stepDetails.appCpuUid1 >= 0) {
4904 pw.print(" (");
4905 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4906 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4907 if (rec.stepDetails.appCpuUid2 >= 0) {
4908 pw.print(", ");
4909 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4910 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4911 }
4912 if (rec.stepDetails.appCpuUid3 >= 0) {
4913 pw.print(", ");
4914 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4915 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4916 }
4917 pw.print(')');
4918 }
4919 pw.println();
4920 pw.print(" /proc/stat=");
4921 pw.print(rec.stepDetails.statUserTime);
4922 pw.print(" usr, ");
4923 pw.print(rec.stepDetails.statSystemTime);
4924 pw.print(" sys, ");
4925 pw.print(rec.stepDetails.statIOWaitTime);
4926 pw.print(" io, ");
4927 pw.print(rec.stepDetails.statIrqTime);
4928 pw.print(" irq, ");
4929 pw.print(rec.stepDetails.statSoftIrqTime);
4930 pw.print(" sirq, ");
4931 pw.print(rec.stepDetails.statIdlTime);
4932 pw.print(" idle");
4933 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4934 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4935 + rec.stepDetails.statSoftIrqTime;
4936 int total = totalRun + rec.stepDetails.statIdlTime;
4937 if (total > 0) {
4938 pw.print(" (");
4939 float perc = ((float)totalRun) / ((float)total) * 100;
4940 pw.print(String.format("%.1f%%", perc));
4941 pw.print(" of ");
4942 StringBuilder sb = new StringBuilder(64);
4943 formatTimeMsNoSpace(sb, total*10);
4944 pw.print(sb);
4945 pw.print(")");
4946 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07004947 pw.print(", PlatformIdleStat ");
4948 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004949 pw.println();
4950 } else {
4951 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4952 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4953 pw.print(rec.stepDetails.userTime);
4954 pw.print(":");
4955 pw.print(rec.stepDetails.systemTime);
4956 if (rec.stepDetails.appCpuUid1 >= 0) {
4957 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4958 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4959 if (rec.stepDetails.appCpuUid2 >= 0) {
4960 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4961 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4962 }
4963 if (rec.stepDetails.appCpuUid3 >= 0) {
4964 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4965 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4966 }
4967 }
4968 pw.println();
4969 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4970 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4971 pw.print(rec.stepDetails.statUserTime);
4972 pw.print(',');
4973 pw.print(rec.stepDetails.statSystemTime);
4974 pw.print(',');
4975 pw.print(rec.stepDetails.statIOWaitTime);
4976 pw.print(',');
4977 pw.print(rec.stepDetails.statIrqTime);
4978 pw.print(',');
4979 pw.print(rec.stepDetails.statSoftIrqTime);
4980 pw.print(',');
4981 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07004982 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07004983 if (rec.stepDetails.statPlatformIdleState != null) {
4984 pw.print(rec.stepDetails.statPlatformIdleState);
4985 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004986 pw.println();
4987 }
4988 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004989 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004990 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004991 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004992 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004993
4994 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4995 UserHandle.formatUid(pw, uid);
4996 pw.print("=");
4997 pw.print(utime);
4998 pw.print("u+");
4999 pw.print(stime);
5000 pw.print("s");
5001 }
5002
5003 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5004 pw.print('/');
5005 pw.print(uid);
5006 pw.print(":");
5007 pw.print(utime);
5008 pw.print(":");
5009 pw.print(stime);
5010 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005011 }
5012
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005013 private void printSizeValue(PrintWriter pw, long size) {
5014 float result = size;
5015 String suffix = "";
5016 if (result >= 10*1024) {
5017 suffix = "KB";
5018 result = result / 1024;
5019 }
5020 if (result >= 10*1024) {
5021 suffix = "MB";
5022 result = result / 1024;
5023 }
5024 if (result >= 10*1024) {
5025 suffix = "GB";
5026 result = result / 1024;
5027 }
5028 if (result >= 10*1024) {
5029 suffix = "TB";
5030 result = result / 1024;
5031 }
5032 if (result >= 10*1024) {
5033 suffix = "PB";
5034 result = result / 1024;
5035 }
5036 pw.print((int)result);
5037 pw.print(suffix);
5038 }
5039
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005040 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5041 String label3, long estimatedTime) {
5042 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005043 return false;
5044 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005045 pw.print(label1);
5046 pw.print(label2);
5047 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005048 StringBuilder sb = new StringBuilder(64);
5049 formatTimeMs(sb, estimatedTime);
5050 pw.print(sb);
5051 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005052 return true;
5053 }
5054
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005055 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5056 LevelStepTracker steps, boolean checkin) {
5057 if (steps == null) {
5058 return false;
5059 }
5060 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005061 if (count <= 0) {
5062 return false;
5063 }
5064 if (!checkin) {
5065 pw.println(header);
5066 }
Kweku Adams030980a2015-04-01 16:07:48 -07005067 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005068 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005069 long duration = steps.getDurationAt(i);
5070 int level = steps.getLevelAt(i);
5071 long initMode = steps.getInitModeAt(i);
5072 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005073 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005074 lineArgs[0] = Long.toString(duration);
5075 lineArgs[1] = Integer.toString(level);
5076 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5077 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5078 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5079 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5080 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5081 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005082 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005083 }
5084 } else {
5085 lineArgs[2] = "";
5086 }
5087 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5088 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5089 } else {
5090 lineArgs[3] = "";
5091 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005092 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005093 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005094 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005095 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005096 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005097 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5098 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005099 pw.print(prefix);
5100 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005101 TimeUtils.formatDuration(duration, pw);
5102 pw.print(" to "); pw.print(level);
5103 boolean haveModes = false;
5104 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5105 pw.print(" (");
5106 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5107 case Display.STATE_OFF: pw.print("screen-off"); break;
5108 case Display.STATE_ON: pw.print("screen-on"); break;
5109 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5110 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005111 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005112 }
5113 haveModes = true;
5114 }
5115 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5116 pw.print(haveModes ? ", " : " (");
5117 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5118 ? "power-save-on" : "power-save-off");
5119 haveModes = true;
5120 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005121 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5122 pw.print(haveModes ? ", " : " (");
5123 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5124 ? "device-idle-on" : "device-idle-off");
5125 haveModes = true;
5126 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005127 if (haveModes) {
5128 pw.print(")");
5129 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005130 pw.println();
5131 }
5132 }
5133 return true;
5134 }
5135
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005136 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005137 public static final int DUMP_DAILY_ONLY = 1<<2;
5138 public static final int DUMP_HISTORY_ONLY = 1<<3;
5139 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5140 public static final int DUMP_VERBOSE = 1<<5;
5141 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005142
Dianne Hackborn37de0982014-05-09 09:32:18 -07005143 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5144 final HistoryPrinter hprinter = new HistoryPrinter();
5145 final HistoryItem rec = new HistoryItem();
5146 long lastTime = -1;
5147 long baseTime = -1;
5148 boolean printed = false;
5149 HistoryEventTracker tracker = null;
5150 while (getNextHistoryLocked(rec)) {
5151 lastTime = rec.time;
5152 if (baseTime < 0) {
5153 baseTime = lastTime;
5154 }
5155 if (rec.time >= histStart) {
5156 if (histStart >= 0 && !printed) {
5157 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005158 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005159 || rec.cmd == HistoryItem.CMD_START
5160 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005161 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005162 hprinter.printNextItem(pw, rec, baseTime, checkin,
5163 (flags&DUMP_VERBOSE) != 0);
5164 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005165 } else if (rec.currentTime != 0) {
5166 printed = true;
5167 byte cmd = rec.cmd;
5168 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005169 hprinter.printNextItem(pw, rec, baseTime, checkin,
5170 (flags&DUMP_VERBOSE) != 0);
5171 rec.cmd = cmd;
5172 }
5173 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005174 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5175 hprinter.printNextItem(pw, rec, baseTime, checkin,
5176 (flags&DUMP_VERBOSE) != 0);
5177 rec.cmd = HistoryItem.CMD_UPDATE;
5178 }
5179 int oldEventCode = rec.eventCode;
5180 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005181 rec.eventTag = new HistoryTag();
5182 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5183 HashMap<String, SparseIntArray> active
5184 = tracker.getStateForEvent(i);
5185 if (active == null) {
5186 continue;
5187 }
5188 for (HashMap.Entry<String, SparseIntArray> ent
5189 : active.entrySet()) {
5190 SparseIntArray uids = ent.getValue();
5191 for (int j=0; j<uids.size(); j++) {
5192 rec.eventCode = i;
5193 rec.eventTag.string = ent.getKey();
5194 rec.eventTag.uid = uids.keyAt(j);
5195 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005196 hprinter.printNextItem(pw, rec, baseTime, checkin,
5197 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005198 rec.wakeReasonTag = null;
5199 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005200 }
5201 }
5202 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005203 rec.eventCode = oldEventCode;
5204 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005205 tracker = null;
5206 }
5207 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005208 hprinter.printNextItem(pw, rec, baseTime, checkin,
5209 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005210 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5211 // This is an attempt to aggregate the previous state and generate
5212 // fake events to reflect that state at the point where we start
5213 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005214 if (tracker == null) {
5215 tracker = new HistoryEventTracker();
5216 }
5217 tracker.updateState(rec.eventCode, rec.eventTag.string,
5218 rec.eventTag.uid, rec.eventTag.poolIdx);
5219 }
5220 }
5221 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005222 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005223 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5224 }
5225 }
5226
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005227 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5228 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5229 if (steps == null) {
5230 return;
5231 }
5232 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5233 if (timeRemaining >= 0) {
5234 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5235 tmpSb.setLength(0);
5236 formatTimeMs(tmpSb, timeRemaining);
5237 pw.print(tmpSb);
5238 pw.print(" (from "); pw.print(tmpOutInt[0]);
5239 pw.println(" steps)");
5240 }
5241 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5242 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5243 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5244 if (estimatedTime > 0) {
5245 pw.print(prefix); pw.print(label); pw.print(" ");
5246 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5247 pw.print(" time: ");
5248 tmpSb.setLength(0);
5249 formatTimeMs(tmpSb, estimatedTime);
5250 pw.print(tmpSb);
5251 pw.print(" (from "); pw.print(tmpOutInt[0]);
5252 pw.println(" steps)");
5253 }
5254 }
5255 }
5256
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005257 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5258 ArrayList<PackageChange> changes) {
5259 if (changes == null) {
5260 return;
5261 }
5262 pw.print(prefix); pw.println("Package changes:");
5263 for (int i=0; i<changes.size(); i++) {
5264 PackageChange pc = changes.get(i);
5265 if (pc.mUpdate) {
5266 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5267 pw.print(" vers="); pw.println(pc.mVersionCode);
5268 } else {
5269 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5270 }
5271 }
5272 }
5273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005274 /**
5275 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5276 *
5277 * @param pw a Printer to receive the dump output.
5278 */
5279 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005280 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005281 prepareForDumpLocked();
5282
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005283 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005284 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005285
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005286 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005287 final long historyTotalSize = getHistoryTotalSize();
5288 final long historyUsedSize = getHistoryUsedSize();
5289 if (startIteratingHistoryLocked()) {
5290 try {
5291 pw.print("Battery History (");
5292 pw.print((100*historyUsedSize)/historyTotalSize);
5293 pw.print("% used, ");
5294 printSizeValue(pw, historyUsedSize);
5295 pw.print(" used of ");
5296 printSizeValue(pw, historyTotalSize);
5297 pw.print(", ");
5298 pw.print(getHistoryStringPoolSize());
5299 pw.print(" strings using ");
5300 printSizeValue(pw, getHistoryStringPoolBytes());
5301 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005302 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005303 pw.println();
5304 } finally {
5305 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005306 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005307 }
5308
5309 if (startIteratingOldHistoryLocked()) {
5310 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005311 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005312 pw.println("Old battery History:");
5313 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005314 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005315 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005316 if (baseTime < 0) {
5317 baseTime = rec.time;
5318 }
5319 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005320 }
5321 pw.println();
5322 } finally {
5323 finishIteratingOldHistoryLocked();
5324 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005325 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005326 }
5327
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005328 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005329 return;
5330 }
5331
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005332 if (!filtering) {
5333 SparseArray<? extends Uid> uidStats = getUidStats();
5334 final int NU = uidStats.size();
5335 boolean didPid = false;
5336 long nowRealtime = SystemClock.elapsedRealtime();
5337 for (int i=0; i<NU; i++) {
5338 Uid uid = uidStats.valueAt(i);
5339 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
5340 if (pids != null) {
5341 for (int j=0; j<pids.size(); j++) {
5342 Uid.Pid pid = pids.valueAt(j);
5343 if (!didPid) {
5344 pw.println("Per-PID Stats:");
5345 didPid = true;
5346 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005347 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
5348 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005349 pw.print(" PID "); pw.print(pids.keyAt(j));
5350 pw.print(" wake time: ");
5351 TimeUtils.formatDuration(time, pw);
5352 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005353 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005354 }
5355 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005356 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005357 pw.println();
5358 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005359 }
5360
5361 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005362 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
5363 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005364 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5365 if (timeRemaining >= 0) {
5366 pw.print(" Estimated discharge time remaining: ");
5367 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5368 pw.println();
5369 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005370 final LevelStepTracker steps = getDischargeLevelStepTracker();
5371 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5372 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
5373 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5374 STEP_LEVEL_MODE_VALUES[i], null));
5375 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005376 pw.println();
5377 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005378 if (dumpDurationSteps(pw, " ", "Charge step durations:",
5379 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005380 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5381 if (timeRemaining >= 0) {
5382 pw.print(" Estimated charge time remaining: ");
5383 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5384 pw.println();
5385 }
5386 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005387 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005388 }
5389 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
5390 pw.println("Daily stats:");
5391 pw.print(" Current start time: ");
5392 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5393 getCurrentDailyStartTime()).toString());
5394 pw.print(" Next min deadline: ");
5395 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5396 getNextMinDailyDeadline()).toString());
5397 pw.print(" Next max deadline: ");
5398 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5399 getNextMaxDailyDeadline()).toString());
5400 StringBuilder sb = new StringBuilder(64);
5401 int[] outInt = new int[1];
5402 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
5403 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005404 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
5405 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005406 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005407 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
5408 dsteps, false)) {
5409 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5410 sb, outInt);
5411 }
5412 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
5413 csteps, false)) {
5414 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5415 sb, outInt);
5416 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005417 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005418 } else {
5419 pw.println(" Current daily steps:");
5420 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5421 sb, outInt);
5422 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5423 sb, outInt);
5424 }
5425 }
5426 DailyItem dit;
5427 int curIndex = 0;
5428 while ((dit=getDailyItemLocked(curIndex)) != null) {
5429 curIndex++;
5430 if ((flags&DUMP_DAILY_ONLY) != 0) {
5431 pw.println();
5432 }
5433 pw.print(" Daily from ");
5434 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
5435 pw.print(" to ");
5436 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
5437 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005438 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005439 if (dumpDurationSteps(pw, " ",
5440 " Discharge step durations:", dit.mDischargeSteps, false)) {
5441 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5442 sb, outInt);
5443 }
5444 if (dumpDurationSteps(pw, " ",
5445 " Charge step durations:", dit.mChargeSteps, false)) {
5446 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5447 sb, outInt);
5448 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005449 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005450 } else {
5451 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5452 sb, outInt);
5453 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5454 sb, outInt);
5455 }
5456 }
5457 pw.println();
5458 }
5459 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005460 pw.println("Statistics since last charge:");
5461 pw.println(" System starts: " + getStartCount()
5462 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005463 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5464 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005465 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005467 }
5468
5469 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005470 public void dumpCheckinLocked(Context context, PrintWriter pw,
5471 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005472 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005473
5474 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005475 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5476 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005477
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005478 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5479
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005480 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005481 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005482
5483 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005484 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005485 try {
5486 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5487 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5488 pw.print(HISTORY_STRING_POOL); pw.print(',');
5489 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005490 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005491 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005492 pw.print(",\"");
5493 String str = getHistoryTagPoolString(i);
5494 str = str.replace("\\", "\\\\");
5495 str = str.replace("\"", "\\\"");
5496 pw.print(str);
5497 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005498 pw.println();
5499 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005500 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005501 } finally {
5502 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08005503 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005504 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005505 }
5506
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005507 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005508 return;
5509 }
5510
Dianne Hackborne4a59512010-12-07 11:08:07 -08005511 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005512 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08005513 for (int i=0; i<apps.size(); i++) {
5514 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005515 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
5516 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08005517 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005518 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
5519 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005520 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005521 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005522 }
5523 SparseArray<? extends Uid> uidStats = getUidStats();
5524 final int NU = uidStats.size();
5525 String[] lineArgs = new String[2];
5526 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005527 int uid = UserHandle.getAppId(uidStats.keyAt(i));
5528 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
5529 if (pkgs != null && !pkgs.second.value) {
5530 pkgs.second.value = true;
5531 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08005532 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005533 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005534 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
5535 (Object[])lineArgs);
5536 }
5537 }
5538 }
5539 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005540 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005541 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005542 String[] lineArgs = new String[1];
5543 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5544 if (timeRemaining >= 0) {
5545 lineArgs[0] = Long.toString(timeRemaining);
5546 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
5547 (Object[])lineArgs);
5548 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005549 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005550 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5551 if (timeRemaining >= 0) {
5552 lineArgs[0] = Long.toString(timeRemaining);
5553 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
5554 (Object[])lineArgs);
5555 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07005556 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
5557 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005558 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005560}