blob: 1b9e2aa3896aff45587aeb5ffb2f128e85a03988 [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;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070033import android.util.MutableBoolean;
34import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.util.Printer;
36import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070037import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070038import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070039import android.view.Display;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080040import com.android.internal.os.BatterySipper;
41import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43/**
44 * A class providing access to battery usage statistics, including information on
45 * wakelocks, processes, packages, and services. All times are represented in microseconds
46 * except where indicated otherwise.
47 * @hide
48 */
49public abstract class BatteryStats implements Parcelable {
50
51 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070052
53 /** @hide */
54 public static final String SERVICE_NAME = "batterystats";
55
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 /**
57 * A constant indicating a partial wake lock timer.
58 */
59 public static final int WAKE_TYPE_PARTIAL = 0;
60
61 /**
62 * A constant indicating a full wake lock timer.
63 */
64 public static final int WAKE_TYPE_FULL = 1;
65
66 /**
67 * A constant indicating a window wake lock timer.
68 */
69 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 /**
72 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 */
74 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070075
76 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070077 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070078 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070079 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070080
81 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070082 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070083 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070084 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070085
86 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070087 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070088 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070089 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
Dianne Hackborn62793e42015-03-09 11:15:41 -070091 /**
92 * A constant indicating a wifi multicast timer
93 */
94 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070097 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070098 */
99 public static final int VIDEO_TURNED_ON = 8;
100
101 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800102 * A constant indicating a vibrator on timer
103 */
104 public static final int VIBRATOR_ON = 9;
105
106 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700107 * A constant indicating a foreground activity timer
108 */
109 public static final int FOREGROUND_ACTIVITY = 10;
110
111 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700112 * A constant indicating a wifi batched scan is active
113 */
114 public static final int WIFI_BATCHED_SCAN = 11;
115
116 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700117 * A constant indicating a process state timer
118 */
119 public static final int PROCESS_STATE = 12;
120
121 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700122 * A constant indicating a sync timer
123 */
124 public static final int SYNC = 13;
125
126 /**
127 * A constant indicating a job timer
128 */
129 public static final int JOB = 14;
130
131 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800132 * A constant indicating an audio turn on timer
133 */
134 public static final int AUDIO_TURNED_ON = 15;
135
136 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700137 * A constant indicating a flashlight turn on timer
138 */
139 public static final int FLASHLIGHT_TURNED_ON = 16;
140
141 /**
142 * A constant indicating a camera turn on timer
143 */
144 public static final int CAMERA_TURNED_ON = 17;
145
146 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700147 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700148 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700149 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700150
151 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800152 * A constant indicating a bluetooth scan timer.
153 */
154 public static final int BLUETOOTH_SCAN_ON = 19;
155
156 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 * Include all of the data in the stats, including previously saved data.
158 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700159 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160
161 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 * Include only the current run in the stats.
163 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700164 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165
166 /**
167 * Include only the run since the last time the device was unplugged in the stats.
168 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700169 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700170
171 // NOTE: Update this list if you add/change any stats above.
172 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700173 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700174 private static final String[] STAT_NAMES = { "l", "c", "u" };
175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700177 * Current version of checkin data format.
178 */
Adam Lesinskib55d7412016-06-09 17:46:19 -0700179 static final String CHECKIN_VERSION = "18";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700180
181 /**
182 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700184 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700185
Evan Millar22ac0432009-03-31 11:33:18 -0700186 private static final long BYTES_PER_KB = 1024;
187 private static final long BYTES_PER_MB = 1048576; // 1024^2
188 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700190 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800191 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700192 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700194 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700195 private static final String CPU_DATA = "cpu";
Evan Millare84de8d2009-04-02 22:16:12 -0700196 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800197 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700198 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700199 private static final String STATE_TIME_DATA = "st";
Evan Millare84de8d2009-04-02 22:16:12 -0700200 private static final String WAKELOCK_DATA = "wl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700201 private static final String SYNC_DATA = "sy";
202 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700203 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700204 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700205 private static final String NETWORK_DATA = "nt";
206 private static final String USER_ACTIVITY_DATA = "ua";
207 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800208 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700209 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700210 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700211 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800212 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
213 private static final String WIFI_CONTROLLER_DATA = "wfcd";
214 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
215 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700216 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700217 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800218 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800219 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
220 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800221 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700222 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700223 private static final String SCREEN_BRIGHTNESS_DATA = "br";
224 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700225 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700226 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
227 private static final String DATA_CONNECTION_TIME_DATA = "dct";
228 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800229 private static final String WIFI_STATE_TIME_DATA = "wst";
230 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700231 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
232 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
233 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
234 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800235 private static final String POWER_USE_SUMMARY_DATA = "pws";
236 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700237 private static final String DISCHARGE_STEP_DATA = "dsd";
238 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700239 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
240 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700241 private static final String FLASHLIGHT_DATA = "fla";
242 private static final String CAMERA_DATA = "cam";
243 private static final String VIDEO_DATA = "vid";
244 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245
Adam Lesinski010bf372016-04-11 12:18:18 -0700246 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
247
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700248 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 private final Formatter mFormatter = new Formatter(mFormatBuilder);
250
251 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700252 * State for keeping track of counting information.
253 */
254 public static abstract class Counter {
255
256 /**
257 * Returns the count associated with this Counter for the
258 * selected type of statistics.
259 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700260 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700261 */
Evan Millarc64edde2009-04-18 12:26:32 -0700262 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700263
264 /**
265 * Temporary for debugging.
266 */
267 public abstract void logState(Printer pw, String prefix);
268 }
269
270 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700271 * State for keeping track of long counting information.
272 */
273 public static abstract class LongCounter {
274
275 /**
276 * Returns the count associated with this Counter for the
277 * selected type of statistics.
278 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700279 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700280 */
281 public abstract long getCountLocked(int which);
282
283 /**
284 * Temporary for debugging.
285 */
286 public abstract void logState(Printer pw, String prefix);
287 }
288
289 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800290 * Container class that aggregates counters for transmit, receive, and idle state of a
291 * radio controller.
292 */
293 public static abstract class ControllerActivityCounter {
294 /**
295 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
296 * idle state.
297 */
298 public abstract LongCounter getIdleTimeCounter();
299
300 /**
301 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
302 * receive state.
303 */
304 public abstract LongCounter getRxTimeCounter();
305
306 /**
307 * An array of {@link LongCounter}, representing various transmit levels, where each level
308 * may draw a different amount of power. The levels themselves are controller-specific.
309 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
310 * various transmit level states.
311 */
312 public abstract LongCounter[] getTxTimeCounters();
313
314 /**
315 * @return a non-null {@link LongCounter} representing the power consumed by the controller
316 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
317 * yield a value of 0 if the device doesn't support power calculations.
318 */
319 public abstract LongCounter getPowerCounter();
320 }
321
322 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 * State for keeping track of timing information.
324 */
325 public static abstract class Timer {
326
327 /**
328 * Returns the count associated with this Timer for the
329 * selected type of statistics.
330 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700331 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 */
Evan Millarc64edde2009-04-18 12:26:32 -0700333 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334
335 /**
336 * Returns the total time in microseconds associated with this Timer for the
337 * selected type of statistics.
338 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800339 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700340 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 * @return a time in microseconds
342 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800343 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700346 * Returns the total time in microseconds associated with this Timer since the
347 * 'mark' was last set.
348 *
349 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
350 * @return a time in microseconds
351 */
352 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
353
354 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 * Temporary for debugging.
356 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700357 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 }
359
360 /**
361 * The statistics associated with a particular uid.
362 */
363 public static abstract class Uid {
364
365 /**
366 * Returns a mapping containing wakelock statistics.
367 *
368 * @return a Map from Strings to Uid.Wakelock objects.
369 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700370 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371
372 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700373 * Returns a mapping containing sync statistics.
374 *
375 * @return a Map from Strings to Timer objects.
376 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700377 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700378
379 /**
380 * Returns a mapping containing scheduled job statistics.
381 *
382 * @return a Map from Strings to Timer objects.
383 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700384 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700385
386 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 * The statistics associated with a particular wake lock.
388 */
389 public static abstract class Wakelock {
390 public abstract Timer getWakeTime(int type);
391 }
392
393 /**
394 * Returns a mapping containing sensor statistics.
395 *
396 * @return a Map from Integer sensor ids to Uid.Sensor objects.
397 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700398 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399
400 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700401 * Returns a mapping containing active process data.
402 */
403 public abstract SparseArray<? extends Pid> getPidStats();
404
405 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 * Returns a mapping containing process statistics.
407 *
408 * @return a Map from Strings to Uid.Proc objects.
409 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700410 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411
412 /**
413 * Returns a mapping containing package statistics.
414 *
415 * @return a Map from Strings to Uid.Pkg objects.
416 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700417 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700418
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800419 public abstract ControllerActivityCounter getWifiControllerActivity();
420 public abstract ControllerActivityCounter getBluetoothControllerActivity();
421 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800422
423 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 * {@hide}
425 */
426 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700427
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800428 public abstract void noteWifiRunningLocked(long elapsedRealtime);
429 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
430 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
431 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
432 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
433 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
434 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
435 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
436 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
437 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800438 public abstract void noteActivityResumedLocked(long elapsedRealtime);
439 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800440 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
441 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
442 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700443 public abstract int getWifiScanCount(int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800444 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700445 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800446 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700447 public abstract Timer getAudioTurnedOnTimer();
448 public abstract Timer getVideoTurnedOnTimer();
449 public abstract Timer getFlashlightTurnedOnTimer();
450 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700451 public abstract Timer getForegroundActivityTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800452 public abstract Timer getBluetoothScanTimer();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700453
Dianne Hackborna0200e32016-03-30 18:01:41 -0700454 // Note: the following times are disjoint. They can be added together to find the
455 // total time a uid has had any processes running at all.
456
457 /**
458 * Time this uid has any processes in the top state (or above such as persistent).
459 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800460 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700461 /**
462 * Time this uid has any process with a started out bound foreground service, but
463 * none in the "top" state.
464 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800465 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700466 /**
467 * Time this uid has any process that is top while the device is sleeping, but none
468 * in the "foreground service" or better state.
469 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800470 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700471 /**
472 * Time this uid has any process in an active foreground state, but none in the
473 * "top sleeping" or better state.
474 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800475 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700476 /**
477 * Time this uid has any process in an active background state, but none in the
478 * "foreground" or better state.
479 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800480 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700481 /**
482 * Time this uid has any processes that are sitting around cached, not in one of the
483 * other active states.
484 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800485 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700486 /**
487 * Total number of process states we track.
488 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800489 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700490
491 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800492 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700493 };
494
495 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800496 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700497
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800498 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499
Robert Greenwalta029ea12013-09-25 16:38:12 -0700500 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
501
Dianne Hackborn617f8772009-03-31 15:04:46 -0700502 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700503 * Note that these must match the constants in android.os.PowerManager.
504 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
505 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700506 */
507 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700508 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700509 };
510
Phil Weaverda80d672016-03-15 16:25:46 -0700511 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700512
Dianne Hackborn617f8772009-03-31 15:04:46 -0700513 public abstract void noteUserActivityLocked(int type);
514 public abstract boolean hasUserActivity();
515 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700516
517 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800518 public abstract long getNetworkActivityBytes(int type, int which);
519 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800520 public abstract long getMobileRadioActiveTime(int which);
521 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700522
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700523 /**
524 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
525 */
526 public abstract long getUserCpuTimeUs(int which);
527
528 /**
529 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
530 */
531 public abstract long getSystemCpuTimeUs(int which);
532
533 /**
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700534 * Get the total cpu power consumed (in milli-ampere-microseconds).
535 */
536 public abstract long getCpuPowerMaUs(int which);
537
538 /**
Adam Lesinski6832f392015-09-05 18:05:40 -0700539 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a
540 * given CPU cluster.
541 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700542 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700543 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700544 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
545 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700546 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700547 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700548
Adam Lesinski5f056f62016-07-14 16:56:08 -0700549 /**
550 * Returns the number of times this UID woke up the Application Processor to
551 * process a mobile radio packet.
552 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
553 */
554 public abstract long getMobileRadioApWakeupCount(int which);
555
556 /**
557 * Returns the number of times this UID woke up the Application Processor to
558 * process a WiFi packet.
559 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
560 */
561 public abstract long getWifiRadioApWakeupCount(int which);
562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800564 /*
565 * FIXME: it's not correct to use this magic value because it
566 * could clash with a sensor handle (which are defined by
567 * the sensor HAL, and therefore out of our control
568 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 // Magic sensor number for the GPS.
570 public static final int GPS = -10000;
571
572 public abstract int getHandle();
573
574 public abstract Timer getSensorTime();
575 }
576
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700577 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800578 public int mWakeNesting;
579 public long mWakeSumMs;
580 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700581 }
582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 /**
584 * The statistics associated with a particular process.
585 */
586 public static abstract class Proc {
587
Dianne Hackborn287952c2010-09-22 22:34:31 -0700588 public static class ExcessivePower {
589 public static final int TYPE_WAKE = 1;
590 public static final int TYPE_CPU = 2;
591
592 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700593 public long overTime;
594 public long usedTime;
595 }
596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800598 * Returns true if this process is still active in the battery stats.
599 */
600 public abstract boolean isActive();
601
602 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700603 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700605 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 */
607 public abstract long getUserTime(int which);
608
609 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700610 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700612 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 */
614 public abstract long getSystemTime(int which);
615
616 /**
617 * Returns the number of times the process has been started.
618 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700619 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 */
621 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700622
623 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800624 * Returns the number of times the process has crashed.
625 *
626 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
627 */
628 public abstract int getNumCrashes(int which);
629
630 /**
631 * Returns the number of times the process has ANRed.
632 *
633 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
634 */
635 public abstract int getNumAnrs(int which);
636
637 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700638 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700639 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700640 * @return foreground cpu time in microseconds
641 */
642 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700643
Dianne Hackborn287952c2010-09-22 22:34:31 -0700644 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700645
Dianne Hackborn287952c2010-09-22 22:34:31 -0700646 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 }
648
649 /**
650 * The statistics associated with a particular package.
651 */
652 public static abstract class Pkg {
653
654 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700655 * Returns information about all wakeup alarms that have been triggered for this
656 * package. The mapping keys are tag names for the alarms, the counter contains
657 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700659 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660
661 /**
662 * Returns a mapping containing service statistics.
663 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700664 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665
666 /**
667 * The statistics associated with a particular service.
668 */
Joe Onoratoabded112016-02-08 16:49:39 -0800669 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670
671 /**
672 * Returns the amount of time spent started.
673 *
674 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700675 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 * @return
677 */
678 public abstract long getStartTime(long batteryUptime, int which);
679
680 /**
681 * Returns the total number of times startService() has been called.
682 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700683 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 */
685 public abstract int getStarts(int which);
686
687 /**
688 * Returns the total number times the service has been launched.
689 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700690 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 */
692 public abstract int getLaunches(int which);
693 }
694 }
695 }
696
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800697 public static final class LevelStepTracker {
698 public long mLastStepTime = -1;
699 public int mNumStepDurations;
700 public final long[] mStepDurations;
701
702 public LevelStepTracker(int maxLevelSteps) {
703 mStepDurations = new long[maxLevelSteps];
704 }
705
706 public LevelStepTracker(int numSteps, long[] steps) {
707 mNumStepDurations = numSteps;
708 mStepDurations = new long[numSteps];
709 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
710 }
711
712 public long getDurationAt(int index) {
713 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
714 }
715
716 public int getLevelAt(int index) {
717 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
718 >> STEP_LEVEL_LEVEL_SHIFT);
719 }
720
721 public int getInitModeAt(int index) {
722 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
723 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
724 }
725
726 public int getModModeAt(int index) {
727 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
728 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
729 }
730
731 private void appendHex(long val, int topOffset, StringBuilder out) {
732 boolean hasData = false;
733 while (topOffset >= 0) {
734 int digit = (int)( (val>>topOffset) & 0xf );
735 topOffset -= 4;
736 if (!hasData && digit == 0) {
737 continue;
738 }
739 hasData = true;
740 if (digit >= 0 && digit <= 9) {
741 out.append((char)('0' + digit));
742 } else {
743 out.append((char)('a' + digit - 10));
744 }
745 }
746 }
747
748 public void encodeEntryAt(int index, StringBuilder out) {
749 long item = mStepDurations[index];
750 long duration = item & STEP_LEVEL_TIME_MASK;
751 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
752 >> STEP_LEVEL_LEVEL_SHIFT);
753 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
754 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
755 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
756 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
757 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
758 case Display.STATE_OFF: out.append('f'); break;
759 case Display.STATE_ON: out.append('o'); break;
760 case Display.STATE_DOZE: out.append('d'); break;
761 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
762 }
763 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
764 out.append('p');
765 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700766 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
767 out.append('i');
768 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800769 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
770 case Display.STATE_OFF: out.append('F'); break;
771 case Display.STATE_ON: out.append('O'); break;
772 case Display.STATE_DOZE: out.append('D'); break;
773 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
774 }
775 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
776 out.append('P');
777 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700778 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
779 out.append('I');
780 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800781 out.append('-');
782 appendHex(level, 4, out);
783 out.append('-');
784 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
785 }
786
787 public void decodeEntryAt(int index, String value) {
788 final int N = value.length();
789 int i = 0;
790 char c;
791 long out = 0;
792 while (i < N && (c=value.charAt(i)) != '-') {
793 i++;
794 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800795 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800796 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800797 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800798 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800799 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800800 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800801 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
802 << STEP_LEVEL_INITIAL_MODE_SHIFT);
803 break;
804 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
805 << STEP_LEVEL_INITIAL_MODE_SHIFT);
806 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700807 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
808 << STEP_LEVEL_INITIAL_MODE_SHIFT);
809 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800810 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
811 break;
812 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
813 break;
814 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
815 break;
816 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
817 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
818 break;
819 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
820 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800821 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700822 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
823 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
824 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800825 }
826 }
827 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800828 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800829 while (i < N && (c=value.charAt(i)) != '-') {
830 i++;
831 level <<= 4;
832 if (c >= '0' && c <= '9') {
833 level += c - '0';
834 } else if (c >= 'a' && c <= 'f') {
835 level += c - 'a' + 10;
836 } else if (c >= 'A' && c <= 'F') {
837 level += c - 'A' + 10;
838 }
839 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800840 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800841 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
842 long duration = 0;
843 while (i < N && (c=value.charAt(i)) != '-') {
844 i++;
845 duration <<= 4;
846 if (c >= '0' && c <= '9') {
847 duration += c - '0';
848 } else if (c >= 'a' && c <= 'f') {
849 duration += c - 'a' + 10;
850 } else if (c >= 'A' && c <= 'F') {
851 duration += c - 'A' + 10;
852 }
853 }
854 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
855 }
856
857 public void init() {
858 mLastStepTime = -1;
859 mNumStepDurations = 0;
860 }
861
862 public void clearTime() {
863 mLastStepTime = -1;
864 }
865
866 public long computeTimePerLevel() {
867 final long[] steps = mStepDurations;
868 final int numSteps = mNumStepDurations;
869
870 // For now we'll do a simple average across all steps.
871 if (numSteps <= 0) {
872 return -1;
873 }
874 long total = 0;
875 for (int i=0; i<numSteps; i++) {
876 total += steps[i] & STEP_LEVEL_TIME_MASK;
877 }
878 return total / numSteps;
879 /*
880 long[] buckets = new long[numSteps];
881 int numBuckets = 0;
882 int numToAverage = 4;
883 int i = 0;
884 while (i < numSteps) {
885 long totalTime = 0;
886 int num = 0;
887 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
888 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
889 num++;
890 }
891 buckets[numBuckets] = totalTime / num;
892 numBuckets++;
893 numToAverage *= 2;
894 i += num;
895 }
896 if (numBuckets < 1) {
897 return -1;
898 }
899 long averageTime = buckets[numBuckets-1];
900 for (i=numBuckets-2; i>=0; i--) {
901 averageTime = (averageTime + buckets[i]) / 2;
902 }
903 return averageTime;
904 */
905 }
906
907 public long computeTimeEstimate(long modesOfInterest, long modeValues,
908 int[] outNumOfInterest) {
909 final long[] steps = mStepDurations;
910 final int count = mNumStepDurations;
911 if (count <= 0) {
912 return -1;
913 }
914 long total = 0;
915 int numOfInterest = 0;
916 for (int i=0; i<count; i++) {
917 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
918 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
919 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
920 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
921 // If the modes of interest didn't change during this step period...
922 if ((modMode&modesOfInterest) == 0) {
923 // And the mode values during this period match those we are measuring...
924 if ((initMode&modesOfInterest) == modeValues) {
925 // Then this can be used to estimate the total time!
926 numOfInterest++;
927 total += steps[i] & STEP_LEVEL_TIME_MASK;
928 }
929 }
930 }
931 if (numOfInterest <= 0) {
932 return -1;
933 }
934
935 if (outNumOfInterest != null) {
936 outNumOfInterest[0] = numOfInterest;
937 }
938
939 // The estimated time is the average time we spend in each level, multipled
940 // by 100 -- the total number of battery levels
941 return (total / numOfInterest) * 100;
942 }
943
944 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
945 int stepCount = mNumStepDurations;
946 final long lastStepTime = mLastStepTime;
947 if (lastStepTime >= 0 && numStepLevels > 0) {
948 final long[] steps = mStepDurations;
949 long duration = elapsedRealtime - lastStepTime;
950 for (int i=0; i<numStepLevels; i++) {
951 System.arraycopy(steps, 0, steps, 1, steps.length-1);
952 long thisDuration = duration / (numStepLevels-i);
953 duration -= thisDuration;
954 if (thisDuration > STEP_LEVEL_TIME_MASK) {
955 thisDuration = STEP_LEVEL_TIME_MASK;
956 }
957 steps[0] = thisDuration | modeBits;
958 }
959 stepCount += numStepLevels;
960 if (stepCount > steps.length) {
961 stepCount = steps.length;
962 }
963 }
964 mNumStepDurations = stepCount;
965 mLastStepTime = elapsedRealtime;
966 }
967
968 public void readFromParcel(Parcel in) {
969 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -0700970 if (N > mStepDurations.length) {
971 throw new ParcelFormatException("more step durations than available: " + N);
972 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800973 mNumStepDurations = N;
974 for (int i=0; i<N; i++) {
975 mStepDurations[i] = in.readLong();
976 }
977 }
978
979 public void writeToParcel(Parcel out) {
980 final int N = mNumStepDurations;
981 out.writeInt(N);
982 for (int i=0; i<N; i++) {
983 out.writeLong(mStepDurations[i]);
984 }
985 }
986 }
987
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700988 public static final class PackageChange {
989 public String mPackageName;
990 public boolean mUpdate;
991 public int mVersionCode;
992 }
993
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800994 public static final class DailyItem {
995 public long mStartTime;
996 public long mEndTime;
997 public LevelStepTracker mDischargeSteps;
998 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700999 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001000 }
1001
1002 public abstract DailyItem getDailyItemLocked(int daysAgo);
1003
1004 public abstract long getCurrentDailyStartTime();
1005
1006 public abstract long getNextMinDailyDeadline();
1007
1008 public abstract long getNextMaxDailyDeadline();
1009
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001010 public final static class HistoryTag {
1011 public String string;
1012 public int uid;
1013
1014 public int poolIdx;
1015
1016 public void setTo(HistoryTag o) {
1017 string = o.string;
1018 uid = o.uid;
1019 poolIdx = o.poolIdx;
1020 }
1021
1022 public void setTo(String _string, int _uid) {
1023 string = _string;
1024 uid = _uid;
1025 poolIdx = -1;
1026 }
1027
1028 public void writeToParcel(Parcel dest, int flags) {
1029 dest.writeString(string);
1030 dest.writeInt(uid);
1031 }
1032
1033 public void readFromParcel(Parcel src) {
1034 string = src.readString();
1035 uid = src.readInt();
1036 poolIdx = -1;
1037 }
1038
1039 @Override
1040 public boolean equals(Object o) {
1041 if (this == o) return true;
1042 if (o == null || getClass() != o.getClass()) return false;
1043
1044 HistoryTag that = (HistoryTag) o;
1045
1046 if (uid != that.uid) return false;
1047 if (!string.equals(that.string)) return false;
1048
1049 return true;
1050 }
1051
1052 @Override
1053 public int hashCode() {
1054 int result = string.hashCode();
1055 result = 31 * result + uid;
1056 return result;
1057 }
1058 }
1059
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001060 /**
1061 * Optional detailed information that can go into a history step. This is typically
1062 * generated each time the battery level changes.
1063 */
1064 public final static class HistoryStepDetails {
1065 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1066 public int userTime;
1067 public int systemTime;
1068
1069 // Top three apps using CPU in the last step, with times in 1/100 second.
1070 public int appCpuUid1;
1071 public int appCpuUTime1;
1072 public int appCpuSTime1;
1073 public int appCpuUid2;
1074 public int appCpuUTime2;
1075 public int appCpuSTime2;
1076 public int appCpuUid3;
1077 public int appCpuUTime3;
1078 public int appCpuSTime3;
1079
1080 // Information from /proc/stat
1081 public int statUserTime;
1082 public int statSystemTime;
1083 public int statIOWaitTime;
1084 public int statIrqTime;
1085 public int statSoftIrqTime;
1086 public int statIdlTime;
1087
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001088 // Platform-level low power state stats
1089 public String statPlatformIdleState;
1090
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001091 public HistoryStepDetails() {
1092 clear();
1093 }
1094
1095 public void clear() {
1096 userTime = systemTime = 0;
1097 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1098 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1099 = appCpuUTime3 = appCpuSTime3 = 0;
1100 }
1101
1102 public void writeToParcel(Parcel out) {
1103 out.writeInt(userTime);
1104 out.writeInt(systemTime);
1105 out.writeInt(appCpuUid1);
1106 out.writeInt(appCpuUTime1);
1107 out.writeInt(appCpuSTime1);
1108 out.writeInt(appCpuUid2);
1109 out.writeInt(appCpuUTime2);
1110 out.writeInt(appCpuSTime2);
1111 out.writeInt(appCpuUid3);
1112 out.writeInt(appCpuUTime3);
1113 out.writeInt(appCpuSTime3);
1114 out.writeInt(statUserTime);
1115 out.writeInt(statSystemTime);
1116 out.writeInt(statIOWaitTime);
1117 out.writeInt(statIrqTime);
1118 out.writeInt(statSoftIrqTime);
1119 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001120 out.writeString(statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001121 }
1122
1123 public void readFromParcel(Parcel in) {
1124 userTime = in.readInt();
1125 systemTime = in.readInt();
1126 appCpuUid1 = in.readInt();
1127 appCpuUTime1 = in.readInt();
1128 appCpuSTime1 = in.readInt();
1129 appCpuUid2 = in.readInt();
1130 appCpuUTime2 = in.readInt();
1131 appCpuSTime2 = in.readInt();
1132 appCpuUid3 = in.readInt();
1133 appCpuUTime3 = in.readInt();
1134 appCpuSTime3 = in.readInt();
1135 statUserTime = in.readInt();
1136 statSystemTime = in.readInt();
1137 statIOWaitTime = in.readInt();
1138 statIrqTime = in.readInt();
1139 statSoftIrqTime = in.readInt();
1140 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001141 statPlatformIdleState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001142 }
1143 }
1144
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001145 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001146 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001147
1148 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001149 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001150
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001151 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001152 public static final byte CMD_NULL = -1;
1153 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001154 public static final byte CMD_CURRENT_TIME = 5;
1155 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001156 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001157 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001158
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001159 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001160
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001161 /**
1162 * Return whether the command code is a delta data update.
1163 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001164 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001165 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001166 }
1167
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001168 public byte batteryLevel;
1169 public byte batteryStatus;
1170 public byte batteryHealth;
1171 public byte batteryPlugType;
1172
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001173 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001174 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001175
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001176 // The charge of the battery in micro-Ampere-hours.
1177 public int batteryChargeUAh;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001178
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001179 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001180 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001181 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001182 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001183 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1184 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001185 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001186 public static final int STATE_PHONE_STATE_SHIFT = 6;
1187 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001188 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001189 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001190 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001191
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001192 // These states always appear directly in the first int token
1193 // of a delta change; they should be ones that change relatively
1194 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001195 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1196 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001197 public static final int STATE_GPS_ON_FLAG = 1<<29;
1198 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001199 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001200 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001201 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001202 // Do not use, this is used for coulomb delta count.
1203 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001204 // These are on the lower bits used for the command; if they change
1205 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001206 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001207 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001208 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001209 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1210 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1211 // empty slot
1212 // empty slot
1213 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001214
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001215 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001216 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1217
1218 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001219
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001220 public int states;
1221
Dianne Hackborn3251b902014-06-20 14:40:53 -07001222 // Constants from WIFI_SUPPL_STATE_*
1223 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1224 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1225 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1226 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1227 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1228 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1229
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001230 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001231 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1232 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1233 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001234 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001235 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1236 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1237 public static final int STATE2_CHARGING_FLAG = 1<<24;
1238 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1239 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1240 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001241 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001242
1243 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001244 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001245 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1246
1247 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001248
Dianne Hackborn40c87252014-03-19 16:55:40 -07001249 public int states2;
1250
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001251 // The wake lock that was acquired at this point.
1252 public HistoryTag wakelockTag;
1253
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001254 // Kernel wakeup reason at this point.
1255 public HistoryTag wakeReasonTag;
1256
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001257 // Non-null when there is more detailed information at this step.
1258 public HistoryStepDetails stepDetails;
1259
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001260 public static final int EVENT_FLAG_START = 0x8000;
1261 public static final int EVENT_FLAG_FINISH = 0x4000;
1262
1263 // No event in this item.
1264 public static final int EVENT_NONE = 0x0000;
1265 // Event is about a process that is running.
1266 public static final int EVENT_PROC = 0x0001;
1267 // Event is about an application package that is in the foreground.
1268 public static final int EVENT_FOREGROUND = 0x0002;
1269 // Event is about an application package that is at the top of the screen.
1270 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001271 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001272 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001273 // Events for all additional wake locks aquired/release within a wake block.
1274 // These are not generated by default.
1275 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001276 // Event is about an application executing a scheduled job.
1277 public static final int EVENT_JOB = 0x0006;
1278 // Events for users running.
1279 public static final int EVENT_USER_RUNNING = 0x0007;
1280 // Events for foreground user.
1281 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001282 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001283 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001284 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001285 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001286 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001287 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001288 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001289 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001290 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001291 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001292 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001293 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001294 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001295 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001296 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001297 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001298 // Event for a package being on the temporary whitelist.
1299 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001300 // Event for the screen waking up.
1301 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001302 // Event for the UID that woke up the application processor.
1303 // Used for wakeups coming from WiFi, modem, etc.
1304 public static final int EVENT_WAKEUP_AP = 0x0013;
Amith Yamasani67768492015-06-09 12:23:58 -07001305
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001306 // Number of event types.
Adam Lesinski5f056f62016-07-14 16:56:08 -07001307 public static final int EVENT_COUNT = 0x0014;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001308 // Mask to extract out only the type part of the event.
1309 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001310
1311 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1312 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1313 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1314 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1315 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1316 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001317 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1318 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001319 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1320 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001321 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1322 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1323 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1324 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1325 public static final int EVENT_USER_FOREGROUND_START =
1326 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1327 public static final int EVENT_USER_FOREGROUND_FINISH =
1328 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001329 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1330 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001331 public static final int EVENT_TEMP_WHITELIST_START =
1332 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1333 public static final int EVENT_TEMP_WHITELIST_FINISH =
1334 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001335
1336 // For CMD_EVENT.
1337 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001338 public HistoryTag eventTag;
1339
Dianne Hackborn9a755432014-05-15 17:05:22 -07001340 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001341 public long currentTime;
1342
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001343 // Meta-data when reading.
1344 public int numReadInts;
1345
1346 // Pre-allocated objects.
1347 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001348 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001349 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001350
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001351 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001352 }
1353
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001354 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001355 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001356 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001357 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001358 }
1359
1360 public int describeContents() {
1361 return 0;
1362 }
1363
1364 public void writeToParcel(Parcel dest, int flags) {
1365 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001366 int bat = (((int)cmd)&0xff)
1367 | ((((int)batteryLevel)<<8)&0xff00)
1368 | ((((int)batteryStatus)<<16)&0xf0000)
1369 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001370 | ((((int)batteryPlugType)<<24)&0xf000000)
1371 | (wakelockTag != null ? 0x10000000 : 0)
1372 | (wakeReasonTag != null ? 0x20000000 : 0)
1373 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001374 dest.writeInt(bat);
1375 bat = (((int)batteryTemperature)&0xffff)
1376 | ((((int)batteryVoltage)<<16)&0xffff0000);
1377 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001378 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001379 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001380 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001381 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001382 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001383 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001384 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001385 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001386 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001387 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001388 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001389 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001390 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001391 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001392 dest.writeLong(currentTime);
1393 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001394 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001395
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001396 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001397 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001398 int bat = src.readInt();
1399 cmd = (byte)(bat&0xff);
1400 batteryLevel = (byte)((bat>>8)&0xff);
1401 batteryStatus = (byte)((bat>>16)&0xf);
1402 batteryHealth = (byte)((bat>>20)&0xf);
1403 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001404 int bat2 = src.readInt();
1405 batteryTemperature = (short)(bat2&0xffff);
1406 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001407 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001408 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001409 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001410 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001411 wakelockTag = localWakelockTag;
1412 wakelockTag.readFromParcel(src);
1413 } else {
1414 wakelockTag = null;
1415 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001416 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001417 wakeReasonTag = localWakeReasonTag;
1418 wakeReasonTag.readFromParcel(src);
1419 } else {
1420 wakeReasonTag = null;
1421 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001422 if ((bat&0x40000000) != 0) {
1423 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001424 eventTag = localEventTag;
1425 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001426 } else {
1427 eventCode = EVENT_NONE;
1428 eventTag = null;
1429 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001430 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001431 currentTime = src.readLong();
1432 } else {
1433 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001434 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001435 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001436 }
1437
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001438 public void clear() {
1439 time = 0;
1440 cmd = CMD_NULL;
1441 batteryLevel = 0;
1442 batteryStatus = 0;
1443 batteryHealth = 0;
1444 batteryPlugType = 0;
1445 batteryTemperature = 0;
1446 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001447 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001448 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001449 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001450 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001451 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001452 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001453 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001454 }
1455
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001456 public void setTo(HistoryItem o) {
1457 time = o.time;
1458 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001459 setToCommon(o);
1460 }
1461
1462 public void setTo(long time, byte cmd, HistoryItem o) {
1463 this.time = time;
1464 this.cmd = cmd;
1465 setToCommon(o);
1466 }
1467
1468 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001469 batteryLevel = o.batteryLevel;
1470 batteryStatus = o.batteryStatus;
1471 batteryHealth = o.batteryHealth;
1472 batteryPlugType = o.batteryPlugType;
1473 batteryTemperature = o.batteryTemperature;
1474 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001475 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001476 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001477 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001478 if (o.wakelockTag != null) {
1479 wakelockTag = localWakelockTag;
1480 wakelockTag.setTo(o.wakelockTag);
1481 } else {
1482 wakelockTag = null;
1483 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001484 if (o.wakeReasonTag != null) {
1485 wakeReasonTag = localWakeReasonTag;
1486 wakeReasonTag.setTo(o.wakeReasonTag);
1487 } else {
1488 wakeReasonTag = null;
1489 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001490 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001491 if (o.eventTag != null) {
1492 eventTag = localEventTag;
1493 eventTag.setTo(o.eventTag);
1494 } else {
1495 eventTag = null;
1496 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001497 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001498 }
1499
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001500 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001501 return batteryLevel == o.batteryLevel
1502 && batteryStatus == o.batteryStatus
1503 && batteryHealth == o.batteryHealth
1504 && batteryPlugType == o.batteryPlugType
1505 && batteryTemperature == o.batteryTemperature
1506 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001507 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001508 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001509 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001510 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001511 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001512
1513 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001514 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001515 return false;
1516 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001517 if (wakelockTag != o.wakelockTag) {
1518 if (wakelockTag == null || o.wakelockTag == null) {
1519 return false;
1520 }
1521 if (!wakelockTag.equals(o.wakelockTag)) {
1522 return false;
1523 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001524 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001525 if (wakeReasonTag != o.wakeReasonTag) {
1526 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1527 return false;
1528 }
1529 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1530 return false;
1531 }
1532 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001533 if (eventTag != o.eventTag) {
1534 if (eventTag == null || o.eventTag == null) {
1535 return false;
1536 }
1537 if (!eventTag.equals(o.eventTag)) {
1538 return false;
1539 }
1540 }
1541 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001542 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001543 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001544
1545 public final static class HistoryEventTracker {
1546 private final HashMap<String, SparseIntArray>[] mActiveEvents
1547 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1548
1549 public boolean updateState(int code, String name, int uid, int poolIdx) {
1550 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1551 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1552 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1553 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001554 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001555 mActiveEvents[idx] = active;
1556 }
1557 SparseIntArray uids = active.get(name);
1558 if (uids == null) {
1559 uids = new SparseIntArray();
1560 active.put(name, uids);
1561 }
1562 if (uids.indexOfKey(uid) >= 0) {
1563 // Already set, nothing to do!
1564 return false;
1565 }
1566 uids.put(uid, poolIdx);
1567 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1568 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1569 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1570 if (active == null) {
1571 // not currently active, nothing to do.
1572 return false;
1573 }
1574 SparseIntArray uids = active.get(name);
1575 if (uids == null) {
1576 // not currently active, nothing to do.
1577 return false;
1578 }
1579 idx = uids.indexOfKey(uid);
1580 if (idx < 0) {
1581 // not currently active, nothing to do.
1582 return false;
1583 }
1584 uids.removeAt(idx);
1585 if (uids.size() <= 0) {
1586 active.remove(name);
1587 }
1588 }
1589 return true;
1590 }
1591
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001592 public void removeEvents(int code) {
1593 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1594 mActiveEvents[idx] = null;
1595 }
1596
Dianne Hackborn37de0982014-05-09 09:32:18 -07001597 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1598 return mActiveEvents[code];
1599 }
1600 }
1601
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001602 public static final class BitDescription {
1603 public final int mask;
1604 public final int shift;
1605 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001606 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001607 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001608 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001609
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001610 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001611 this.mask = mask;
1612 this.shift = -1;
1613 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001614 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001615 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001616 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001617 }
1618
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001619 public BitDescription(int mask, int shift, String name, String shortName,
1620 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001621 this.mask = mask;
1622 this.shift = shift;
1623 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001624 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001625 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001626 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001627 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001628 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001629
Dianne Hackbornfc064132014-06-02 12:42:12 -07001630 /**
1631 * Don't allow any more batching in to the current history event. This
1632 * is called when printing partial histories, so to ensure that the next
1633 * history event will go in to a new batch after what was printed in the
1634 * last partial history.
1635 */
1636 public abstract void commitCurrentHistoryBatchLocked();
1637
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001638 public abstract int getHistoryTotalSize();
1639
1640 public abstract int getHistoryUsedSize();
1641
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001642 public abstract boolean startIteratingHistoryLocked();
1643
Dianne Hackborn099bc622014-01-22 13:39:16 -08001644 public abstract int getHistoryStringPoolSize();
1645
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001646 public abstract int getHistoryStringPoolBytes();
1647
1648 public abstract String getHistoryTagPoolString(int index);
1649
1650 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001651
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001652 public abstract boolean getNextHistoryLocked(HistoryItem out);
1653
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001654 public abstract void finishIteratingHistoryLocked();
1655
1656 public abstract boolean startIteratingOldHistoryLocked();
1657
1658 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1659
1660 public abstract void finishIteratingOldHistoryLocked();
1661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001663 * Return the base time offset for the battery history.
1664 */
1665 public abstract long getHistoryBaseTime();
1666
1667 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 * Returns the number of times the device has been started.
1669 */
1670 public abstract int getStartCount();
1671
1672 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001673 * 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 -08001674 * running on battery.
1675 *
1676 * {@hide}
1677 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001678 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001680 /**
1681 * Returns the number of times the screen was turned on.
1682 *
1683 * {@hide}
1684 */
1685 public abstract int getScreenOnCount(int which);
1686
Jeff Browne95c3cd2014-05-02 16:59:26 -07001687 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1688
Dianne Hackborn617f8772009-03-31 15:04:46 -07001689 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1690 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1691 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1692 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1693 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1694
1695 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1696 "dark", "dim", "medium", "light", "bright"
1697 };
1698
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001699 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1700 "0", "1", "2", "3", "4"
1701 };
1702
Dianne Hackborn617f8772009-03-31 15:04:46 -07001703 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001704
Dianne Hackborn617f8772009-03-31 15:04:46 -07001705 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001706 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001707 * the given brightness
1708 *
1709 * {@hide}
1710 */
1711 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001712 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001714 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001715 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001716 * running on battery.
1717 *
1718 * {@hide}
1719 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001720 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001721
1722 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001723 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001724 *
1725 * {@hide}
1726 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001727 public abstract int getPowerSaveModeEnabledCount(int which);
1728
1729 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001730 * Constant for device idle mode: not active.
1731 */
1732 public static final int DEVICE_IDLE_MODE_OFF = 0;
1733
1734 /**
1735 * Constant for device idle mode: active in lightweight mode.
1736 */
1737 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1738
1739 /**
1740 * Constant for device idle mode: active in full mode.
1741 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001742 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001743
1744 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001745 * Returns the time in microseconds that device has been in idle mode while
1746 * running on battery.
1747 *
1748 * {@hide}
1749 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001750 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001751
1752 /**
1753 * Returns the number of times that the devie has gone in to idle mode.
1754 *
1755 * {@hide}
1756 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001757 public abstract int getDeviceIdleModeCount(int mode, int which);
1758
1759 /**
1760 * Return the longest duration we spent in a particular device idle mode (fully in the
1761 * mode, not in idle maintenance etc).
1762 */
1763 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001764
1765 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001766 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001767 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001768 * counts all of the time that we consider the device to be idle, whether or not
1769 * it is currently in the actual device idle mode.
1770 *
1771 * {@hide}
1772 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001773 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001774
1775 /**
1776 * Returns the number of times that the devie has started idling.
1777 *
1778 * {@hide}
1779 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001780 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001781
1782 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001783 * Returns the number of times that connectivity state changed.
1784 *
1785 * {@hide}
1786 */
1787 public abstract int getNumConnectivityChange(int which);
1788
1789 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001790 * 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 -08001791 * running on battery.
1792 *
1793 * {@hide}
1794 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001795 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001796
1797 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001798 * Returns the number of times a phone call was activated.
1799 *
1800 * {@hide}
1801 */
1802 public abstract int getPhoneOnCount(int which);
1803
1804 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001805 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001806 * the given signal strength.
1807 *
1808 * {@hide}
1809 */
1810 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001811 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001812
Dianne Hackborn617f8772009-03-31 15:04:46 -07001813 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001814 * Returns the time in microseconds that the phone has been trying to
1815 * acquire a signal.
1816 *
1817 * {@hide}
1818 */
1819 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001820 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001821
1822 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001823 * Returns the number of times the phone has entered the given signal strength.
1824 *
1825 * {@hide}
1826 */
1827 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1828
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001829 /**
1830 * Returns the time in microseconds that the mobile network has been active
1831 * (in a high power state).
1832 *
1833 * {@hide}
1834 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001835 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001836
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001837 /**
1838 * Returns the number of times that the mobile network has transitioned to the
1839 * active state.
1840 *
1841 * {@hide}
1842 */
1843 public abstract int getMobileRadioActiveCount(int which);
1844
1845 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001846 * Returns the time in microseconds that is the difference between the mobile radio
1847 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1848 * from the radio.
1849 *
1850 * {@hide}
1851 */
1852 public abstract long getMobileRadioActiveAdjustedTime(int which);
1853
1854 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001855 * Returns the time in microseconds that the mobile network has been active
1856 * (in a high power state) but not being able to blame on an app.
1857 *
1858 * {@hide}
1859 */
1860 public abstract long getMobileRadioActiveUnknownTime(int which);
1861
1862 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001863 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001864 *
1865 * {@hide}
1866 */
1867 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001868
Dianne Hackborn627bba72009-03-24 22:32:56 -07001869 public static final int DATA_CONNECTION_NONE = 0;
1870 public static final int DATA_CONNECTION_GPRS = 1;
1871 public static final int DATA_CONNECTION_EDGE = 2;
1872 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001873 public static final int DATA_CONNECTION_CDMA = 4;
1874 public static final int DATA_CONNECTION_EVDO_0 = 5;
1875 public static final int DATA_CONNECTION_EVDO_A = 6;
1876 public static final int DATA_CONNECTION_1xRTT = 7;
1877 public static final int DATA_CONNECTION_HSDPA = 8;
1878 public static final int DATA_CONNECTION_HSUPA = 9;
1879 public static final int DATA_CONNECTION_HSPA = 10;
1880 public static final int DATA_CONNECTION_IDEN = 11;
1881 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001882 public static final int DATA_CONNECTION_LTE = 13;
1883 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001884 public static final int DATA_CONNECTION_HSPAP = 15;
1885 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001886
Dianne Hackborn627bba72009-03-24 22:32:56 -07001887 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001888 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001889 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001890 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001891 };
1892
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001893 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001894
1895 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001896 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001897 * the given data connection.
1898 *
1899 * {@hide}
1900 */
1901 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001902 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001903
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001905 * Returns the number of times the phone has entered the given data
1906 * connection type.
1907 *
1908 * {@hide}
1909 */
1910 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001911
Dianne Hackborn3251b902014-06-20 14:40:53 -07001912 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1913 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1914 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1915 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1916 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1917 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1918 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1919 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1920 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1921 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1922 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1923 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1924 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1925
1926 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1927
1928 static final String[] WIFI_SUPPL_STATE_NAMES = {
1929 "invalid", "disconn", "disabled", "inactive", "scanning",
1930 "authenticating", "associating", "associated", "4-way-handshake",
1931 "group-handshake", "completed", "dormant", "uninit"
1932 };
1933
1934 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1935 "inv", "dsc", "dis", "inact", "scan",
1936 "auth", "ascing", "asced", "4-way",
1937 "group", "compl", "dorm", "uninit"
1938 };
1939
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001940 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1941 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001942 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001943 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1944 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001945 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001946 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1947 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1948 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001949 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001950 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001951 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001952 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001953 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1954 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001955 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1956 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1957 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1958 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1959 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1960 new String[] {"in", "out", "emergency", "off"},
1961 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001962 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1963 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1964 SignalStrength.SIGNAL_STRENGTH_NAMES,
1965 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001966 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1967 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1968 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001969 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001970
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001971 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1972 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001973 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001974 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001975 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001976 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001977 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001978 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
1979 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
1980 new String[] { "off", "light", "full", "???" },
1981 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001982 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
1983 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
1984 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001985 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1986 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1987 new String[] { "0", "1", "2", "3", "4" },
1988 new String[] { "0", "1", "2", "3", "4" }),
1989 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1990 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1991 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07001992 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001993 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001994 };
1995
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001996 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001997 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001998 "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist",
Adam Lesinski5f056f62016-07-14 16:56:08 -07001999 "screenwake", "wakeupap"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002000 };
2001
2002 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002003 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002004 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski5f056f62016-07-14 16:56:08 -07002005 "Esw", "Ewa"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002006 };
2007
Dianne Hackborn617f8772009-03-31 15:04:46 -07002008 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002009 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002010 * running on battery.
2011 *
2012 * {@hide}
2013 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002014 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002015
2016 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002017 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002018 * been in the running state while the device was running on battery.
2019 *
2020 * {@hide}
2021 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002022 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002023
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002024 public static final int WIFI_STATE_OFF = 0;
2025 public static final int WIFI_STATE_OFF_SCANNING = 1;
2026 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2027 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2028 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2029 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2030 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2031 public static final int WIFI_STATE_SOFT_AP = 7;
2032
2033 static final String[] WIFI_STATE_NAMES = {
2034 "off", "scanning", "no_net", "disconn",
2035 "sta", "p2p", "sta_p2p", "soft_ap"
2036 };
2037
2038 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2039
2040 /**
2041 * Returns the time in microseconds that WiFi has been running in the given state.
2042 *
2043 * {@hide}
2044 */
2045 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002046 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002047
2048 /**
2049 * Returns the number of times that WiFi has entered the given state.
2050 *
2051 * {@hide}
2052 */
2053 public abstract int getWifiStateCount(int wifiState, int which);
2054
The Android Open Source Project10592532009-03-18 17:39:46 -07002055 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002056 * Returns the time in microseconds that the wifi supplicant has been
2057 * in a given state.
2058 *
2059 * {@hide}
2060 */
2061 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2062
2063 /**
2064 * Returns the number of times that the wifi supplicant has transitioned
2065 * to a given state.
2066 *
2067 * {@hide}
2068 */
2069 public abstract int getWifiSupplStateCount(int state, int which);
2070
2071 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2072
2073 /**
2074 * Returns the time in microseconds that WIFI has been running with
2075 * the given signal strength.
2076 *
2077 * {@hide}
2078 */
2079 public abstract long getWifiSignalStrengthTime(int strengthBin,
2080 long elapsedRealtimeUs, int which);
2081
2082 /**
2083 * Returns the number of times WIFI has entered the given signal strength.
2084 *
2085 * {@hide}
2086 */
2087 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2088
2089 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002090 * Returns the time in microseconds that the flashlight has been on while the device was
2091 * running on battery.
2092 *
2093 * {@hide}
2094 */
2095 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2096
2097 /**
2098 * Returns the number of times that the flashlight has been turned on while the device was
2099 * running on battery.
2100 *
2101 * {@hide}
2102 */
2103 public abstract long getFlashlightOnCount(int which);
2104
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002105 /**
2106 * Returns the time in microseconds that the camera has been on while the device was
2107 * running on battery.
2108 *
2109 * {@hide}
2110 */
2111 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2112
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002113 /**
2114 * Returns the time in microseconds that bluetooth scans were running while the device was
2115 * on battery.
2116 *
2117 * {@hide}
2118 */
2119 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002120
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002121 public static final int NETWORK_MOBILE_RX_DATA = 0;
2122 public static final int NETWORK_MOBILE_TX_DATA = 1;
2123 public static final int NETWORK_WIFI_RX_DATA = 2;
2124 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002125 public static final int NETWORK_BT_RX_DATA = 4;
2126 public static final int NETWORK_BT_TX_DATA = 5;
2127 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_BT_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002128
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002129 public abstract long getNetworkActivityBytes(int type, int which);
2130 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002131
Adam Lesinskie08af192015-03-25 16:42:59 -07002132 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002133 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002134 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002135 * actual power data.
2136 */
2137 public abstract boolean hasWifiActivityReporting();
2138
2139 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002140 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2141 * in various radio controller states, such as transmit, receive, and idle.
2142 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002143 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002144 public abstract ControllerActivityCounter getWifiControllerActivity();
2145
2146 /**
2147 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2148 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2149 * actual power data.
2150 */
2151 public abstract boolean hasBluetoothActivityReporting();
2152
2153 /**
2154 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2155 * in various radio controller states, such as transmit, receive, and idle.
2156 * @return non-null {@link ControllerActivityCounter}
2157 */
2158 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2159
2160 /**
2161 * Returns true if the BatteryStats object has detailed modem power reports.
2162 * When true, calling {@link #getModemControllerActivity()} will yield the
2163 * actual power data.
2164 */
2165 public abstract boolean hasModemActivityReporting();
2166
2167 /**
2168 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2169 * in various radio controller states, such as transmit, receive, and idle.
2170 * @return non-null {@link ControllerActivityCounter}
2171 */
2172 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002173
The Android Open Source Project10592532009-03-18 17:39:46 -07002174 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002175 * Return the wall clock time when battery stats data collection started.
2176 */
2177 public abstract long getStartClockTime();
2178
2179 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002180 * Return platform version tag that we were running in when the battery stats started.
2181 */
2182 public abstract String getStartPlatformVersion();
2183
2184 /**
2185 * Return platform version tag that we were running in when the battery stats ended.
2186 */
2187 public abstract String getEndPlatformVersion();
2188
2189 /**
2190 * Return the internal version code of the parcelled format.
2191 */
2192 public abstract int getParcelVersion();
2193
2194 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 * Return whether we are currently running on battery.
2196 */
2197 public abstract boolean getIsOnBattery();
2198
2199 /**
2200 * Returns a SparseArray containing the statistics for each uid.
2201 */
2202 public abstract SparseArray<? extends Uid> getUidStats();
2203
2204 /**
2205 * Returns the current battery uptime in microseconds.
2206 *
2207 * @param curTime the amount of elapsed realtime in microseconds.
2208 */
2209 public abstract long getBatteryUptime(long curTime);
2210
2211 /**
2212 * Returns the current battery realtime in microseconds.
2213 *
2214 * @param curTime the amount of elapsed realtime in microseconds.
2215 */
2216 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07002217
2218 /**
Evan Millar633a1742009-04-02 16:36:33 -07002219 * Returns the battery percentage level at the last time the device was unplugged from power, or
2220 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002221 */
Evan Millar633a1742009-04-02 16:36:33 -07002222 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07002223
2224 /**
Evan Millar633a1742009-04-02 16:36:33 -07002225 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2226 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002227 */
Evan Millar633a1742009-04-02 16:36:33 -07002228 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002229
2230 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002231 * Get the amount the battery has discharged since the stats were
2232 * last reset after charging, as a lower-end approximation.
2233 */
2234 public abstract int getLowDischargeAmountSinceCharge();
2235
2236 /**
2237 * Get the amount the battery has discharged since the stats were
2238 * last reset after charging, as an upper-end approximation.
2239 */
2240 public abstract int getHighDischargeAmountSinceCharge();
2241
2242 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002243 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2244 */
2245 public abstract int getDischargeAmount(int which);
2246
2247 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002248 * Get the amount the battery has discharged while the screen was on,
2249 * since the last time power was unplugged.
2250 */
2251 public abstract int getDischargeAmountScreenOn();
2252
2253 /**
2254 * Get the amount the battery has discharged while the screen was on,
2255 * since the last time the device was charged.
2256 */
2257 public abstract int getDischargeAmountScreenOnSinceCharge();
2258
2259 /**
2260 * Get the amount the battery has discharged while the screen was off,
2261 * since the last time power was unplugged.
2262 */
2263 public abstract int getDischargeAmountScreenOff();
2264
2265 /**
2266 * Get the amount the battery has discharged while the screen was off,
2267 * since the last time the device was charged.
2268 */
2269 public abstract int getDischargeAmountScreenOffSinceCharge();
2270
2271 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002272 * Returns the total, last, or current battery uptime in microseconds.
2273 *
2274 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002275 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002276 */
2277 public abstract long computeBatteryUptime(long curTime, int which);
2278
2279 /**
2280 * Returns the total, last, or current battery realtime in microseconds.
2281 *
2282 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002283 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 */
2285 public abstract long computeBatteryRealtime(long curTime, int which);
2286
2287 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002288 * Returns the total, last, or current battery screen off uptime in microseconds.
2289 *
2290 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002291 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002292 */
2293 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2294
2295 /**
2296 * Returns the total, last, or current battery screen off realtime in microseconds.
2297 *
2298 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002299 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002300 */
2301 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2302
2303 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 * Returns the total, last, or current uptime in microseconds.
2305 *
2306 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002307 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002308 */
2309 public abstract long computeUptime(long curTime, int which);
2310
2311 /**
2312 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002313 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002315 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 */
2317 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002318
2319 /**
2320 * Compute an approximation for how much run time (in microseconds) is remaining on
2321 * the battery. Returns -1 if no time can be computed: either there is not
2322 * enough current data to make a decision, or the battery is currently
2323 * charging.
2324 *
2325 * @param curTime The current elepsed realtime in microseconds.
2326 */
2327 public abstract long computeBatteryTimeRemaining(long curTime);
2328
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002329 // The part of a step duration that is the actual time.
2330 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2331
2332 // Bits in a step duration that are the new battery level we are at.
2333 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002334 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002335
2336 // Bits in a step duration that are the initial mode we were in at that step.
2337 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002338 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002339
2340 // Bits in a step duration that indicate which modes changed during that step.
2341 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002342 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002343
2344 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2345 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2346
2347 // Step duration mode: power save is on.
2348 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2349
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002350 // Step duration mode: device is currently in idle mode.
2351 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2352
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002353 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2354 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002355 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2356 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002357 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2358 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2359 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2360 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
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 };
2365 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2366 (Display.STATE_OFF-1),
2367 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002368 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002369 (Display.STATE_ON-1),
2370 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2371 (Display.STATE_DOZE-1),
2372 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2373 (Display.STATE_DOZE_SUSPEND-1),
2374 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002375 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002376 };
2377 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2378 "screen off",
2379 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002380 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002381 "screen on",
2382 "screen on power save",
2383 "screen doze",
2384 "screen doze power save",
2385 "screen doze-suspend",
2386 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002387 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002388 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002389
2390 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002391 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2392 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2393 * a coulomb counter.
2394 */
2395 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2396
2397 /**
2398 * Return the counter keeping track of the amount of battery discharge measured in
2399 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2400 * a coulomb counter.
2401 */
2402 public abstract LongCounter getDischargeCoulombCounter();
2403
2404 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002405 * Returns the estimated real battery capacity, which may be less than the capacity
2406 * declared by the PowerProfile.
2407 * @return The estimated battery capacity in mAh.
2408 */
2409 public abstract int getEstimatedBatteryCapacity();
2410
2411 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002412 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002413 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002414 public abstract LevelStepTracker getDischargeLevelStepTracker();
2415
2416 /**
2417 * Return the array of daily discharge step durations.
2418 */
2419 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002420
2421 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002422 * Compute an approximation for how much time (in microseconds) remains until the battery
2423 * is fully charged. Returns -1 if no time can be computed: either there is not
2424 * enough current data to make a decision, or the battery is currently
2425 * discharging.
2426 *
2427 * @param curTime The current elepsed realtime in microseconds.
2428 */
2429 public abstract long computeChargeTimeRemaining(long curTime);
2430
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002431 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002432 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002433 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002434 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002435
2436 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002437 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002438 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002439 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002440
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002441 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2442
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002443 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002444
Evan Millarc64edde2009-04-18 12:26:32 -07002445 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002446
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002447 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2448
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002449 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 long days = seconds / (60 * 60 * 24);
2451 if (days != 0) {
2452 out.append(days);
2453 out.append("d ");
2454 }
2455 long used = days * 60 * 60 * 24;
2456
2457 long hours = (seconds - used) / (60 * 60);
2458 if (hours != 0 || used != 0) {
2459 out.append(hours);
2460 out.append("h ");
2461 }
2462 used += hours * 60 * 60;
2463
2464 long mins = (seconds-used) / 60;
2465 if (mins != 0 || used != 0) {
2466 out.append(mins);
2467 out.append("m ");
2468 }
2469 used += mins * 60;
2470
2471 if (seconds != 0 || used != 0) {
2472 out.append(seconds-used);
2473 out.append("s ");
2474 }
2475 }
2476
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002477 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002479 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 sb.append(time - (sec * 1000));
2481 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 }
2483
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002484 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002485 long sec = time / 1000;
2486 formatTimeRaw(sb, sec);
2487 sb.append(time - (sec * 1000));
2488 sb.append("ms");
2489 }
2490
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002491 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002493 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 }
2495 float perc = ((float)num) / ((float)den) * 100;
2496 mFormatBuilder.setLength(0);
2497 mFormatter.format("%.1f%%", perc);
2498 return mFormatBuilder.toString();
2499 }
2500
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002501 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002502 mFormatBuilder.setLength(0);
2503
2504 if (bytes < BYTES_PER_KB) {
2505 return bytes + "B";
2506 } else if (bytes < BYTES_PER_MB) {
2507 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2508 return mFormatBuilder.toString();
2509 } else if (bytes < BYTES_PER_GB){
2510 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2511 return mFormatBuilder.toString();
2512 } else {
2513 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2514 return mFormatBuilder.toString();
2515 }
2516 }
2517
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002518 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002519 if (timer != null) {
2520 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002521 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002522 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2523 return totalTimeMillis;
2524 }
2525 return 0;
2526 }
2527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 /**
2529 *
2530 * @param sb a StringBuilder object.
2531 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002532 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002534 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 * @param linePrefix a String to be prepended to each line of output.
2536 * @return the line prefix
2537 */
2538 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002539 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002542 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002543
Evan Millarc64edde2009-04-18 12:26:32 -07002544 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 if (totalTimeMillis != 0) {
2546 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002547 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002548 if (name != null) {
2549 sb.append(name);
2550 sb.append(' ');
2551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 sb.append('(');
2553 sb.append(count);
2554 sb.append(" times)");
2555 return ", ";
2556 }
2557 }
2558 return linePrefix;
2559 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002560
2561 /**
2562 *
2563 * @param pw a PrintWriter object to print to.
2564 * @param sb a StringBuilder object.
2565 * @param timer a Timer object contining the wakelock times.
2566 * @param rawRealtime the current on-battery time in microseconds.
2567 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2568 * @param prefix a String to be prepended to each line of output.
2569 * @param type the name of the timer.
2570 */
2571 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
2572 long rawRealtime, int which, String prefix, String type) {
2573 if (timer != null) {
2574 // Convert from microseconds to milliseconds with rounding
2575 final long totalTime = (timer.getTotalTimeLocked(
2576 rawRealtime, which) + 500) / 1000;
2577 final int count = timer.getCountLocked(which);
2578 if (totalTime != 0) {
2579 sb.setLength(0);
2580 sb.append(prefix);
2581 sb.append(" ");
2582 sb.append(type);
2583 sb.append(": ");
2584 formatTimeMs(sb, totalTime);
2585 sb.append("realtime (");
2586 sb.append(count);
2587 sb.append(" times)");
2588 pw.println(sb.toString());
2589 return true;
2590 }
2591 }
2592 return false;
2593 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594
2595 /**
2596 * Checkin version of wakelock printer. Prints simple comma-separated list.
2597 *
2598 * @param sb a StringBuilder object.
2599 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002600 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002601 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002602 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002603 * @param linePrefix a String to be prepended to each line of output.
2604 * @return the line prefix
2605 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002606 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2607 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002608 long totalTimeMicros = 0;
2609 int count = 0;
2610 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002611 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002612 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002613 }
2614 sb.append(linePrefix);
2615 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2616 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002617 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 sb.append(count);
2619 return ",";
2620 }
2621
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002622 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2623 String type) {
2624 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2625 pw.print(',');
2626 pw.print(uid);
2627 pw.print(',');
2628 pw.print(category);
2629 pw.print(',');
2630 pw.print(type);
2631 }
2632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633 /**
2634 * Dump a comma-separated line of values for terse checkin mode.
2635 *
2636 * @param pw the PageWriter to dump log to
2637 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2638 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2639 * @param args type-dependent data arguments
2640 */
2641 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2642 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002643 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002644 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002645 pw.print(',');
2646 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002648 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002650
2651 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002652 * Dump a given timer stat for terse checkin mode.
2653 *
2654 * @param pw the PageWriter to dump log to
2655 * @param uid the UID to log
2656 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2657 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2658 * @param timer a {@link Timer} to dump stats for
2659 * @param rawRealtime the current elapsed realtime of the system in microseconds
2660 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2661 */
2662 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2663 Timer timer, long rawRealtime, int which) {
2664 if (timer != null) {
2665 // Convert from microseconds to milliseconds with rounding
2666 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2667 / 1000;
2668 final int count = timer.getCountLocked(which);
2669 if (totalTime != 0) {
2670 dumpLine(pw, uid, category, type, totalTime, count);
2671 }
2672 }
2673 }
2674
2675 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002676 * Checks if the ControllerActivityCounter has any data worth dumping.
2677 */
2678 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2679 if (counter == null) {
2680 return false;
2681 }
2682
2683 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2684 || counter.getRxTimeCounter().getCountLocked(which) != 0
2685 || counter.getPowerCounter().getCountLocked(which) != 0) {
2686 return true;
2687 }
2688
2689 for (LongCounter c : counter.getTxTimeCounters()) {
2690 if (c.getCountLocked(which) != 0) {
2691 return true;
2692 }
2693 }
2694 return false;
2695 }
2696
2697 /**
2698 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2699 * The order of the arguments in the final check in line is:
2700 *
2701 * idle, rx, power, tx...
2702 *
2703 * where tx... is one or more transmit level times.
2704 */
2705 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2706 String type,
2707 ControllerActivityCounter counter,
2708 int which) {
2709 if (!controllerActivityHasData(counter, which)) {
2710 return;
2711 }
2712
2713 dumpLineHeader(pw, uid, category, type);
2714 pw.print(",");
2715 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2716 pw.print(",");
2717 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2718 pw.print(",");
2719 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2720 for (LongCounter c : counter.getTxTimeCounters()) {
2721 pw.print(",");
2722 pw.print(c.getCountLocked(which));
2723 }
2724 pw.println();
2725 }
2726
2727 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2728 String prefix, String controllerName,
2729 ControllerActivityCounter counter,
2730 int which) {
2731 if (controllerActivityHasData(counter, which)) {
2732 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2733 }
2734 }
2735
2736 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2737 String controllerName,
2738 ControllerActivityCounter counter, int which) {
2739 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2740 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2741 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2742 long totalTxTimeMs = 0;
2743 for (LongCounter txState : counter.getTxTimeCounters()) {
2744 totalTxTimeMs += txState.getCountLocked(which);
2745 }
2746
2747 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2748
2749 sb.setLength(0);
2750 sb.append(prefix);
2751 sb.append(" ");
2752 sb.append(controllerName);
2753 sb.append(" Idle time: ");
2754 formatTimeMs(sb, idleTimeMs);
2755 sb.append("(");
2756 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2757 sb.append(")");
2758 pw.println(sb.toString());
2759
2760 sb.setLength(0);
2761 sb.append(prefix);
2762 sb.append(" ");
2763 sb.append(controllerName);
2764 sb.append(" Rx time: ");
2765 formatTimeMs(sb, rxTimeMs);
2766 sb.append("(");
2767 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
2768 sb.append(")");
2769 pw.println(sb.toString());
2770
2771 sb.setLength(0);
2772 sb.append(prefix);
2773 sb.append(" ");
2774 sb.append(controllerName);
2775 sb.append(" Tx time: ");
2776 formatTimeMs(sb, totalTxTimeMs);
2777 sb.append("(");
2778 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
2779 sb.append(")");
2780 pw.println(sb.toString());
2781
2782 final int numTxLvls = counter.getTxTimeCounters().length;
2783 if (numTxLvls > 1) {
2784 for (int lvl = 0; lvl < numTxLvls; lvl++) {
2785 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
2786 sb.setLength(0);
2787 sb.append(prefix);
2788 sb.append(" [");
2789 sb.append(lvl);
2790 sb.append("] ");
2791 formatTimeMs(sb, txLvlTimeMs);
2792 sb.append("(");
2793 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
2794 sb.append(")");
2795 pw.println(sb.toString());
2796 }
2797 }
2798
2799 sb.setLength(0);
2800 sb.append(prefix);
2801 sb.append(" ");
2802 sb.append(controllerName);
2803 sb.append(" Power drain: ").append(
2804 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
2805 sb.append("mAh");
2806 pw.println(sb.toString());
2807 }
2808
2809 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07002810 * Temporary for settings.
2811 */
2812 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2813 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2814 }
2815
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 /**
2817 * Checkin server version of dump to produce more compact, computer-readable log.
2818 *
2819 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002821 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2822 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2824 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2825 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2827 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002828 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2829 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2830 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002831 final long totalRealtime = computeRealtime(rawRealtime, which);
2832 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002833 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002834 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002835 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002836 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
2837 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002838 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002839 rawRealtime, which);
2840 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
2841 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002842 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002843 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002844 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002845 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002846 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
2847 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
2848 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002849
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002850 final StringBuilder sb = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002851
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002852 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07002853 final int NU = uidStats.size();
2854
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002855 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002856
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 // Dump "battery" stat
2858 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002859 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002860 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002861 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002862 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002863 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
2864 getEstimatedBatteryCapacity());
Adam Lesinski67c134f2016-06-10 15:15:08 -07002865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002867 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002868 long fullWakeLockTimeTotal = 0;
2869 long partialWakeLockTimeTotal = 0;
2870
2871 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002872 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002873
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002874 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
2875 = u.getWakelockStats();
2876 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2877 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07002878
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002879 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2880 if (fullWakeTimer != null) {
2881 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2882 which);
2883 }
2884
2885 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2886 if (partialWakeTimer != null) {
2887 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
2888 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002889 }
2890 }
2891 }
Adam Lesinskie283d332015-04-16 12:29:25 -07002892
2893 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002894 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2895 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2896 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2897 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2898 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2899 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2900 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2901 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002902 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
2903 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002904 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2905 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002906 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
2907 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002908
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002909 // Dump Modem controller stats
2910 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
2911 getModemControllerActivity(), which);
2912
Adam Lesinskie283d332015-04-16 12:29:25 -07002913 // Dump Wifi controller stats
2914 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2915 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002916 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08002917 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002918
2919 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
2920 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002921
2922 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002923 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
2924 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002925
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 // Dump misc stats
2927 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07002928 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002929 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07002930 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002931 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002932 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002933 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
2934 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07002935 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002936 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
2937 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
2938 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
2939 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002940 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002941
2942 // Dump screen brightness stats
2943 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2944 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002945 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002946 }
2947 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002948
Dianne Hackborn627bba72009-03-24 22:32:56 -07002949 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002950 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2951 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002952 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002953 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002954 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002955 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002956 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002957 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002958 args[i] = getPhoneSignalStrengthCount(i, which);
2959 }
2960 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002961
Dianne Hackborn627bba72009-03-24 22:32:56 -07002962 // Dump network type stats
2963 args = new Object[NUM_DATA_CONNECTION_TYPES];
2964 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002965 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002966 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002967 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2968 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2969 args[i] = getPhoneDataConnectionCount(i, which);
2970 }
2971 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002972
2973 // Dump wifi state stats
2974 args = new Object[NUM_WIFI_STATES];
2975 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002976 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002977 }
2978 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2979 for (int i=0; i<NUM_WIFI_STATES; i++) {
2980 args[i] = getWifiStateCount(i, which);
2981 }
2982 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2983
Dianne Hackborn3251b902014-06-20 14:40:53 -07002984 // Dump wifi suppl state stats
2985 args = new Object[NUM_WIFI_SUPPL_STATES];
2986 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2987 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2988 }
2989 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2990 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2991 args[i] = getWifiSupplStateCount(i, which);
2992 }
2993 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
2994
2995 // Dump wifi signal strength stats
2996 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
2997 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2998 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
2999 }
3000 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3001 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3002 args[i] = getWifiSignalStrengthCount(i, which);
3003 }
3004 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3005
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003006 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003007 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003008 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003009 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003011 if (which == STATS_SINCE_UNPLUGGED) {
3012 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3013 getDischargeStartLevel()-getDischargeCurrentLevel(),
3014 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003015 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
3016 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003017 } else {
3018 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3019 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003020 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003021 getDischargeAmountScreenOffSinceCharge(),
3022 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003023 }
3024
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003025 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003026 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003027 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003028 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003029 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003030 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003031 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003032 sb.toString());
3033 }
Evan Millarc64edde2009-04-18 12:26:32 -07003034 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003035 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003036 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003037 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3038 // Not doing the regular wake lock formatting to remain compatible
3039 // with the old checkin format.
3040 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3041 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003042 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003043 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003044 }
3045 }
Evan Millarc64edde2009-04-18 12:26:32 -07003046 }
3047
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003048 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003049 helper.create(this);
3050 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003051 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003052 if (sippers != null && sippers.size() > 0) {
3053 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3054 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003055 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003056 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3057 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3058 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003059 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003060 int uid = 0;
3061 String label;
3062 switch (bs.drainType) {
3063 case IDLE:
3064 label="idle";
3065 break;
3066 case CELL:
3067 label="cell";
3068 break;
3069 case PHONE:
3070 label="phone";
3071 break;
3072 case WIFI:
3073 label="wifi";
3074 break;
3075 case BLUETOOTH:
3076 label="blue";
3077 break;
3078 case SCREEN:
3079 label="scrn";
3080 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003081 case FLASHLIGHT:
3082 label="flashlight";
3083 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003084 case APP:
3085 uid = bs.uidObj.getUid();
3086 label = "uid";
3087 break;
3088 case USER:
3089 uid = UserHandle.getUid(bs.userId, 0);
3090 label = "user";
3091 break;
3092 case UNACCOUNTED:
3093 label = "unacc";
3094 break;
3095 case OVERCOUNTED:
3096 label = "over";
3097 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003098 case CAMERA:
3099 label = "camera";
3100 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003101 default:
3102 label = "???";
3103 }
3104 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07003105 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003106 }
3107 }
3108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 for (int iu = 0; iu < NU; iu++) {
3110 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003111 if (reqUid >= 0 && uid != reqUid) {
3112 continue;
3113 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003114 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003116 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003117 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3118 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3119 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3120 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3121 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3122 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3123 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3124 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003125 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003126 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3127 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003128 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003129 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3130 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003131 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3132 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003133 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Adam Lesinski5f056f62016-07-14 16:56:08 -07003134 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003135 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3136 wifiBytesRx, wifiBytesTx,
3137 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003138 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003139 mobileActiveTime, mobileActiveCount,
Adam Lesinski5f056f62016-07-14 16:56:08 -07003140 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003141 }
3142
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003143 // Dump modem controller data, per UID.
3144 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3145 u.getModemControllerActivity(), which);
3146
3147 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003148 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3149 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3150 final int wifiScanCount = u.getWifiScanCount(which);
3151 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003152 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003153 || uidWifiRunningTime != 0) {
3154 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3155 uidWifiRunningTime, wifiScanCount,
Kweku Adams5b2747e2016-04-25 10:44:05 -07003156 /* legacy fields follow, keep at 0 */ 0, 0, 0);
The Android Open Source Project10592532009-03-18 17:39:46 -07003157 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003159 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3160 u.getWifiControllerActivity(), which);
3161
Adam Lesinskiba9d8932016-04-12 12:06:03 -07003162 dumpTimer(pw, uid, category, BLUETOOTH_MISC_DATA, u.getBluetoothScanTimer(),
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003163 rawRealtime, which);
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003164
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003165 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3166 u.getBluetoothControllerActivity(), which);
3167
Dianne Hackborn617f8772009-03-31 15:04:46 -07003168 if (u.hasUserActivity()) {
3169 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3170 boolean hasData = false;
3171 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3172 int val = u.getUserActivityCount(i, which);
3173 args[i] = val;
3174 if (val != 0) hasData = true;
3175 }
3176 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003177 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003178 }
3179 }
3180
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003181 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3182 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3183 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3184 String linePrefix = "";
3185 sb.setLength(0);
3186 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3187 rawRealtime, "f", which, linePrefix);
3188 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
3189 rawRealtime, "p", which, linePrefix);
3190 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3191 rawRealtime, "w", which, linePrefix);
3192
3193 // Only log if we had at lease one wakelock...
3194 if (sb.length() > 0) {
3195 String name = wakelocks.keyAt(iw);
3196 if (name.indexOf(',') >= 0) {
3197 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003199 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 }
3201 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003202
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003203 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3204 for (int isy=syncs.size()-1; isy>=0; isy--) {
3205 final Timer timer = syncs.valueAt(isy);
3206 // Convert from microseconds to milliseconds with rounding
3207 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3208 final int count = timer.getCountLocked(which);
3209 if (totalTime != 0) {
3210 dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003211 }
3212 }
3213
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003214 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3215 for (int ij=jobs.size()-1; ij>=0; ij--) {
3216 final Timer timer = jobs.valueAt(ij);
3217 // Convert from microseconds to milliseconds with rounding
3218 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3219 final int count = timer.getCountLocked(which);
3220 if (totalTime != 0) {
3221 dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003222 }
3223 }
3224
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003225 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3226 rawRealtime, which);
3227 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3228 rawRealtime, which);
3229 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3230 rawRealtime, which);
3231 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3232 rawRealtime, which);
3233
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003234 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3235 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003236 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003237 final Uid.Sensor se = sensors.valueAt(ise);
3238 final int sensorNumber = sensors.keyAt(ise);
3239 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003240 if (timer != null) {
3241 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003242 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3243 / 1000;
3244 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003245 if (totalTime != 0) {
3246 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
3247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003248 }
3249 }
3250
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003251 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3252 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003253
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003254 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3255 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003256
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003257 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003258 long totalStateTime = 0;
3259 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003260 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3261 totalStateTime += time;
3262 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003263 }
3264 if (totalStateTime > 0) {
3265 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3266 }
3267
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003268 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3269 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
3270 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
3271 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
3272 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
3273 powerCpuMaUs / 1000);
3274 }
3275
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003276 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3277 = u.getProcessStats();
3278 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3279 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003280
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003281 final long userMillis = ps.getUserTime(which);
3282 final long systemMillis = ps.getSystemTime(which);
3283 final long foregroundMillis = ps.getForegroundTime(which);
3284 final int starts = ps.getStarts(which);
3285 final int numCrashes = ps.getNumCrashes(which);
3286 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003287
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003288 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3289 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
3290 dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis,
3291 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 }
3293 }
3294
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003295 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3296 = u.getPackageStats();
3297 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3298 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3299 int wakeups = 0;
3300 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3301 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003302 int count = alarms.valueAt(iwa).getCountLocked(which);
3303 wakeups += count;
3304 String name = alarms.keyAt(iwa).replace(',', '_');
3305 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003306 }
3307 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3308 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3309 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3310 final long startTime = ss.getStartTime(batteryUptime, which);
3311 final int starts = ss.getStarts(which);
3312 final int launches = ss.getLaunches(which);
3313 if (startTime != 0 || starts != 0 || launches != 0) {
3314 dumpLine(pw, uid, category, APK_DATA,
3315 wakeups, // wakeup alarms
3316 packageStats.keyAt(ipkg), // Apk
3317 serviceStats.keyAt(isvc), // service
3318 startTime / 1000, // time spent started, in ms
3319 starts,
3320 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003321 }
3322 }
3323 }
3324 }
3325 }
3326
Dianne Hackborn81038902012-11-26 17:04:09 -08003327 static final class TimerEntry {
3328 final String mName;
3329 final int mId;
3330 final BatteryStats.Timer mTimer;
3331 final long mTime;
3332 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3333 mName = name;
3334 mId = id;
3335 mTimer = timer;
3336 mTime = time;
3337 }
3338 }
3339
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003340 private void printmAh(PrintWriter printer, double power) {
3341 printer.print(BatteryStatsHelper.makemAh(power));
3342 }
3343
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003344 private void printmAh(StringBuilder sb, double power) {
3345 sb.append(BatteryStatsHelper.makemAh(power));
3346 }
3347
Dianne Hackbornd953c532014-08-16 18:17:38 -07003348 /**
3349 * Temporary for settings.
3350 */
3351 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3352 int reqUid) {
3353 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3354 }
3355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003357 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003358 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3360 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3361 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003362
3363 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3364 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3365 final long totalRealtime = computeRealtime(rawRealtime, which);
3366 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003367 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3368 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3369 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003370 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3371 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003372
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003373 final StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07003374
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003375 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003376 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003377
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003378 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3379 if (estimatedBatteryCapacity > 0) {
3380 sb.setLength(0);
3381 sb.append(prefix);
3382 sb.append(" Estimated battery capacity: ");
3383 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3384 sb.append(" mAh");
3385 pw.println(sb.toString());
3386 }
3387
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003388 sb.setLength(0);
3389 sb.append(prefix);
3390 sb.append(" Time on battery: ");
3391 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3392 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3393 sb.append(") realtime, ");
3394 formatTimeMs(sb, whichBatteryUptime / 1000);
3395 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3396 sb.append(") uptime");
3397 pw.println(sb.toString());
3398 sb.setLength(0);
3399 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003400 sb.append(" Time on battery screen off: ");
3401 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3402 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3403 sb.append(") realtime, ");
3404 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3405 sb.append("(");
3406 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3407 sb.append(") uptime");
3408 pw.println(sb.toString());
3409 sb.setLength(0);
3410 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003411 sb.append(" Total run time: ");
3412 formatTimeMs(sb, totalRealtime / 1000);
3413 sb.append("realtime, ");
3414 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003415 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003416 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003417 if (batteryTimeRemaining >= 0) {
3418 sb.setLength(0);
3419 sb.append(prefix);
3420 sb.append(" Battery time remaining: ");
3421 formatTimeMs(sb, batteryTimeRemaining / 1000);
3422 pw.println(sb.toString());
3423 }
3424 if (chargeTimeRemaining >= 0) {
3425 sb.setLength(0);
3426 sb.append(prefix);
3427 sb.append(" Charge time remaining: ");
3428 formatTimeMs(sb, chargeTimeRemaining / 1000);
3429 pw.println(sb.toString());
3430 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003431
3432 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3433 final long dischargeCount = dischargeCounter.getCountLocked(which);
3434 if (dischargeCount >= 0) {
3435 sb.setLength(0);
3436 sb.append(prefix);
3437 sb.append(" Discharge: ");
3438 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3439 sb.append(" mAh");
3440 pw.println(sb.toString());
3441 }
3442
3443 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3444 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3445 if (dischargeScreenOffCount >= 0) {
3446 sb.setLength(0);
3447 sb.append(prefix);
3448 sb.append(" Screen off discharge: ");
3449 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3450 sb.append(" mAh");
3451 pw.println(sb.toString());
3452 }
3453
3454 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3455 if (dischargeScreenOnCount >= 0) {
3456 sb.setLength(0);
3457 sb.append(prefix);
3458 sb.append(" Screen on discharge: ");
3459 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3460 sb.append(" mAh");
3461 pw.println(sb.toString());
3462 }
3463
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003464 pw.print(" Start clock time: ");
3465 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3466
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003467 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003468 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003469 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003470 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3471 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003472 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003473 rawRealtime, which);
3474 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3475 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003476 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003477 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003478 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3479 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3480 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003481 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003482 sb.append(prefix);
3483 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3484 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003485 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003486 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3487 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003488 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003489 pw.println(sb.toString());
3490 sb.setLength(0);
3491 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003492 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003493 boolean didOne = false;
3494 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003495 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003496 if (time == 0) {
3497 continue;
3498 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003499 sb.append("\n ");
3500 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003501 didOne = true;
3502 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3503 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003504 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003505 sb.append("(");
3506 sb.append(formatRatioLocked(time, screenOnTime));
3507 sb.append(")");
3508 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003509 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003510 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003511 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003512 sb.setLength(0);
3513 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003514 sb.append(" Power save mode enabled: ");
3515 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003516 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003517 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003518 sb.append(")");
3519 pw.println(sb.toString());
3520 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003521 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003522 sb.setLength(0);
3523 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003524 sb.append(" Device light idling: ");
3525 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003526 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003527 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3528 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003529 sb.append("x");
3530 pw.println(sb.toString());
3531 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003532 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003533 sb.setLength(0);
3534 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003535 sb.append(" Idle mode light time: ");
3536 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003537 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003538 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3539 sb.append(") ");
3540 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003541 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003542 sb.append(" -- longest ");
3543 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3544 pw.println(sb.toString());
3545 }
3546 if (deviceIdlingTime != 0) {
3547 sb.setLength(0);
3548 sb.append(prefix);
3549 sb.append(" Device full idling: ");
3550 formatTimeMs(sb, deviceIdlingTime / 1000);
3551 sb.append("(");
3552 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003553 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003554 sb.append("x");
3555 pw.println(sb.toString());
3556 }
3557 if (deviceIdleModeFullTime != 0) {
3558 sb.setLength(0);
3559 sb.append(prefix);
3560 sb.append(" Idle mode full time: ");
3561 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3562 sb.append("(");
3563 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3564 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003565 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003566 sb.append("x");
3567 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003568 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003569 pw.println(sb.toString());
3570 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003571 if (phoneOnTime != 0) {
3572 sb.setLength(0);
3573 sb.append(prefix);
3574 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3575 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003576 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003577 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003578 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003579 if (connChanges != 0) {
3580 pw.print(prefix);
3581 pw.print(" Connectivity changes: "); pw.println(connChanges);
3582 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003583
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003584 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003585 long fullWakeLockTimeTotalMicros = 0;
3586 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003587
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003588 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003589
Evan Millar22ac0432009-03-31 11:33:18 -07003590 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003591 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003592
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003593 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3594 = u.getWakelockStats();
3595 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3596 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003597
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003598 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3599 if (fullWakeTimer != null) {
3600 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3601 rawRealtime, which);
3602 }
3603
3604 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3605 if (partialWakeTimer != null) {
3606 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3607 rawRealtime, which);
3608 if (totalTimeMicros > 0) {
3609 if (reqUid < 0) {
3610 // Only show the ordered list of all wake
3611 // locks if the caller is not asking for data
3612 // about a specific uid.
3613 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3614 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003615 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003616 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003617 }
3618 }
3619 }
3620 }
3621
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003622 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3623 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3624 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3625 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3626 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3627 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3628 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3629 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08003630 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3631 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003632
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003633 if (fullWakeLockTimeTotalMicros != 0) {
3634 sb.setLength(0);
3635 sb.append(prefix);
3636 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3637 (fullWakeLockTimeTotalMicros + 500) / 1000);
3638 pw.println(sb.toString());
3639 }
3640
3641 if (partialWakeLockTimeTotalMicros != 0) {
3642 sb.setLength(0);
3643 sb.append(prefix);
3644 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3645 (partialWakeLockTimeTotalMicros + 500) / 1000);
3646 pw.println(sb.toString());
3647 }
3648
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003649 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003650 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3651 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3652 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3653 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003654 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003655 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003656 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003657 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003658 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003659 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003660 if (time == 0) {
3661 continue;
3662 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003663 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003664 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003665 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003666 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003667 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003668 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003669 sb.append("(");
3670 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003671 sb.append(") ");
3672 sb.append(getPhoneSignalStrengthCount(i, which));
3673 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003674 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003675 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003676 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003677
3678 sb.setLength(0);
3679 sb.append(prefix);
3680 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003681 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003682 pw.println(sb.toString());
3683
Dianne Hackborn627bba72009-03-24 22:32:56 -07003684 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003685 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003686 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003687 didOne = false;
3688 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003689 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003690 if (time == 0) {
3691 continue;
3692 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003693 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003694 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003695 didOne = true;
3696 sb.append(DATA_CONNECTION_NAMES[i]);
3697 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003698 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003699 sb.append("(");
3700 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003701 sb.append(") ");
3702 sb.append(getPhoneDataConnectionCount(i, which));
3703 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003704 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003705 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003706 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003707
3708 sb.setLength(0);
3709 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003710 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003711 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003712 formatTimeMs(sb, mobileActiveTime / 1000);
3713 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3714 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3715 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003716 pw.println(sb.toString());
3717
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003718 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3719 if (mobileActiveUnknownTime != 0) {
3720 sb.setLength(0);
3721 sb.append(prefix);
3722 sb.append(" Mobile radio active unknown time: ");
3723 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3724 sb.append("(");
3725 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3726 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3727 sb.append("x");
3728 pw.println(sb.toString());
3729 }
3730
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003731 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3732 if (mobileActiveAdjustedTime != 0) {
3733 sb.setLength(0);
3734 sb.append(prefix);
3735 sb.append(" Mobile radio active adjusted time: ");
3736 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3737 sb.append("(");
3738 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3739 sb.append(")");
3740 pw.println(sb.toString());
3741 }
3742
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003743 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
3744
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003745 pw.print(prefix);
3746 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3747 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3748 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3749 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003750 sb.setLength(0);
3751 sb.append(prefix);
3752 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3753 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3754 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3755 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003756 sb.append(")");
3757 pw.println(sb.toString());
3758
3759 sb.setLength(0);
3760 sb.append(prefix);
3761 sb.append(" Wifi states:");
3762 didOne = false;
3763 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003764 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003765 if (time == 0) {
3766 continue;
3767 }
3768 sb.append("\n ");
3769 didOne = true;
3770 sb.append(WIFI_STATE_NAMES[i]);
3771 sb.append(" ");
3772 formatTimeMs(sb, time/1000);
3773 sb.append("(");
3774 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3775 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003776 sb.append(getWifiStateCount(i, which));
3777 sb.append("x");
3778 }
3779 if (!didOne) sb.append(" (no activity)");
3780 pw.println(sb.toString());
3781
3782 sb.setLength(0);
3783 sb.append(prefix);
3784 sb.append(" Wifi supplicant states:");
3785 didOne = false;
3786 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3787 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3788 if (time == 0) {
3789 continue;
3790 }
3791 sb.append("\n ");
3792 didOne = true;
3793 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3794 sb.append(" ");
3795 formatTimeMs(sb, time/1000);
3796 sb.append("(");
3797 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3798 sb.append(") ");
3799 sb.append(getWifiSupplStateCount(i, which));
3800 sb.append("x");
3801 }
3802 if (!didOne) sb.append(" (no activity)");
3803 pw.println(sb.toString());
3804
3805 sb.setLength(0);
3806 sb.append(prefix);
3807 sb.append(" Wifi signal levels:");
3808 didOne = false;
3809 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3810 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3811 if (time == 0) {
3812 continue;
3813 }
3814 sb.append("\n ");
3815 sb.append(prefix);
3816 didOne = true;
3817 sb.append("level(");
3818 sb.append(i);
3819 sb.append(") ");
3820 formatTimeMs(sb, time/1000);
3821 sb.append("(");
3822 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3823 sb.append(") ");
3824 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003825 sb.append("x");
3826 }
3827 if (!didOne) sb.append(" (no activity)");
3828 pw.println(sb.toString());
3829
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003830 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07003831
Adam Lesinski50e47602015-12-04 17:04:54 -08003832 pw.print(prefix);
3833 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
3834 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
3835
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003836 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
3837 sb.setLength(0);
3838 sb.append(prefix);
3839 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
3840 pw.println(sb.toString());
3841
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003842 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
3843 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003844
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003845 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003846
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003847 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003848 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003849 pw.print(prefix); pw.println(" Device is currently unplugged");
3850 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3851 pw.println(getDischargeStartLevel());
3852 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3853 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003854 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003855 pw.print(prefix); pw.println(" Device is currently plugged into power");
3856 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3857 pw.println(getDischargeStartLevel());
3858 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3859 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003860 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003861 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3862 pw.println(getDischargeAmountScreenOn());
3863 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3864 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003865 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003866 } else {
3867 pw.print(prefix); pw.println(" Device battery use since last full charge");
3868 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3869 pw.println(getLowDischargeAmountSinceCharge());
3870 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3871 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003872 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3873 pw.println(getDischargeAmountScreenOnSinceCharge());
3874 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3875 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003876 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003877 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003878
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003879 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003880 helper.create(this);
3881 helper.refreshStats(which, UserHandle.USER_ALL);
3882 List<BatterySipper> sippers = helper.getUsageList();
3883 if (sippers != null && sippers.size() > 0) {
3884 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3885 pw.print(prefix); pw.print(" Capacity: ");
3886 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003887 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003888 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3889 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3890 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3891 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003892 pw.println();
3893 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003894 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003895 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003896 switch (bs.drainType) {
3897 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003898 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003899 break;
3900 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003901 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003902 break;
3903 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003904 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003905 break;
3906 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003907 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003908 break;
3909 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003910 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003911 break;
3912 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003913 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003914 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003915 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003916 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003917 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003918 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003919 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003920 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003921 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003922 break;
3923 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003924 pw.print(" User "); pw.print(bs.userId);
3925 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003926 break;
3927 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003928 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003929 break;
3930 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003931 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003932 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003933 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003934 pw.print(" Camera: ");
3935 break;
3936 default:
3937 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003938 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003939 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003940 printmAh(pw, bs.totalPowerMah);
3941
Adam Lesinski57123002015-06-12 16:12:07 -07003942 if (bs.usagePowerMah != bs.totalPowerMah) {
3943 // If the usage (generic power) isn't the whole amount, we list out
3944 // what components are involved in the calculation.
3945
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003946 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07003947 if (bs.usagePowerMah != 0) {
3948 pw.print(" usage=");
3949 printmAh(pw, bs.usagePowerMah);
3950 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003951 if (bs.cpuPowerMah != 0) {
3952 pw.print(" cpu=");
3953 printmAh(pw, bs.cpuPowerMah);
3954 }
3955 if (bs.wakeLockPowerMah != 0) {
3956 pw.print(" wake=");
3957 printmAh(pw, bs.wakeLockPowerMah);
3958 }
3959 if (bs.mobileRadioPowerMah != 0) {
3960 pw.print(" radio=");
3961 printmAh(pw, bs.mobileRadioPowerMah);
3962 }
3963 if (bs.wifiPowerMah != 0) {
3964 pw.print(" wifi=");
3965 printmAh(pw, bs.wifiPowerMah);
3966 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003967 if (bs.bluetoothPowerMah != 0) {
3968 pw.print(" bt=");
3969 printmAh(pw, bs.bluetoothPowerMah);
3970 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003971 if (bs.gpsPowerMah != 0) {
3972 pw.print(" gps=");
3973 printmAh(pw, bs.gpsPowerMah);
3974 }
3975 if (bs.sensorPowerMah != 0) {
3976 pw.print(" sensor=");
3977 printmAh(pw, bs.sensorPowerMah);
3978 }
3979 if (bs.cameraPowerMah != 0) {
3980 pw.print(" camera=");
3981 printmAh(pw, bs.cameraPowerMah);
3982 }
3983 if (bs.flashlightPowerMah != 0) {
3984 pw.print(" flash=");
3985 printmAh(pw, bs.flashlightPowerMah);
3986 }
3987 pw.print(" )");
3988 }
3989 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003990 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08003991 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003992 }
3993
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003994 sippers = helper.getMobilemsppList();
3995 if (sippers != null && sippers.size() > 0) {
3996 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003997 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003998 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003999 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004000 sb.setLength(0);
4001 sb.append(prefix); sb.append(" Uid ");
4002 UserHandle.formatUid(sb, bs.uidObj.getUid());
4003 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4004 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4005 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004006 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004007 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004008 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004009 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004010 sb.setLength(0);
4011 sb.append(prefix);
4012 sb.append(" TOTAL TIME: ");
4013 formatTimeMs(sb, totalTime);
4014 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4015 sb.append(")");
4016 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004017 pw.println();
4018 }
4019
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004020 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4021 @Override
4022 public int compare(TimerEntry lhs, TimerEntry rhs) {
4023 long lhsTime = lhs.mTime;
4024 long rhsTime = rhs.mTime;
4025 if (lhsTime < rhsTime) {
4026 return 1;
4027 }
4028 if (lhsTime > rhsTime) {
4029 return -1;
4030 }
4031 return 0;
4032 }
4033 };
4034
4035 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004036 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4037 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004038 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004039 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4040 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4041 : kernelWakelocks.entrySet()) {
4042 final BatteryStats.Timer timer = ent.getValue();
4043 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004044 if (totalTimeMillis > 0) {
4045 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4046 }
4047 }
4048 if (ktimers.size() > 0) {
4049 Collections.sort(ktimers, timerComparator);
4050 pw.print(prefix); pw.println(" All kernel wake locks:");
4051 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004052 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004053 String linePrefix = ": ";
4054 sb.setLength(0);
4055 sb.append(prefix);
4056 sb.append(" Kernel Wake lock ");
4057 sb.append(timer.mName);
4058 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4059 which, linePrefix);
4060 if (!linePrefix.equals(": ")) {
4061 sb.append(" realtime");
4062 // Only print out wake locks that were held
4063 pw.println(sb.toString());
4064 }
4065 }
4066 pw.println();
4067 }
4068 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004069
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004070 if (timers.size() > 0) {
4071 Collections.sort(timers, timerComparator);
4072 pw.print(prefix); pw.println(" All partial wake locks:");
4073 for (int i=0; i<timers.size(); i++) {
4074 TimerEntry timer = timers.get(i);
4075 sb.setLength(0);
4076 sb.append(" Wake lock ");
4077 UserHandle.formatUid(sb, timer.mId);
4078 sb.append(" ");
4079 sb.append(timer.mName);
4080 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4081 sb.append(" realtime");
4082 pw.println(sb.toString());
4083 }
4084 timers.clear();
4085 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004086 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004087
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004088 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004089 if (wakeupReasons.size() > 0) {
4090 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004091 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004092 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004093 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004094 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4095 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004096 }
4097 Collections.sort(reasons, timerComparator);
4098 for (int i=0; i<reasons.size(); i++) {
4099 TimerEntry timer = reasons.get(i);
4100 String linePrefix = ": ";
4101 sb.setLength(0);
4102 sb.append(prefix);
4103 sb.append(" Wakeup reason ");
4104 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004105 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4106 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004107 pw.println(sb.toString());
4108 }
4109 pw.println();
4110 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004111 }
Evan Millar22ac0432009-03-31 11:33:18 -07004112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 for (int iu=0; iu<NU; iu++) {
4114 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004115 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004116 continue;
4117 }
4118
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004119 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004120
4121 pw.print(prefix);
4122 pw.print(" ");
4123 UserHandle.formatUid(pw, uid);
4124 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004125 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004126
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004127 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4128 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4129 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4130 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004131 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4132 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4133
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004134 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4135 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004136 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4137 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004138
4139 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4140 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4141
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004142 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4143 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4144 final int wifiScanCount = u.getWifiScanCount(which);
4145 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004146
Adam Lesinski5f056f62016-07-14 16:56:08 -07004147 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4148 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4149
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004150 if (mobileRxBytes > 0 || mobileTxBytes > 0
4151 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004152 pw.print(prefix); pw.print(" Mobile network: ");
4153 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004154 pw.print(formatBytesLocked(mobileTxBytes));
4155 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4156 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004157 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004158 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4159 sb.setLength(0);
4160 sb.append(prefix); sb.append(" Mobile radio active: ");
4161 formatTimeMs(sb, uidMobileActiveTime / 1000);
4162 sb.append("(");
4163 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4164 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4165 long packets = mobileRxPackets + mobileTxPackets;
4166 if (packets == 0) {
4167 packets = 1;
4168 }
4169 sb.append(" @ ");
4170 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4171 sb.append(" mspp");
4172 pw.println(sb.toString());
4173 }
4174
Adam Lesinski5f056f62016-07-14 16:56:08 -07004175 if (mobileWakeup > 0) {
4176 sb.setLength(0);
4177 sb.append(prefix);
4178 sb.append(" Mobile radio AP wakeups: ");
4179 sb.append(mobileWakeup);
4180 pw.println(sb.toString());
4181 }
4182
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004183 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4184 u.getModemControllerActivity(), which);
4185
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004186 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004187 pw.print(prefix); pw.print(" Wi-Fi network: ");
4188 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004189 pw.print(formatBytesLocked(wifiTxBytes));
4190 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4191 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004192 }
4193
Dianne Hackborn62793e42015-03-09 11:15:41 -07004194 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004195 || uidWifiRunningTime != 0) {
4196 sb.setLength(0);
4197 sb.append(prefix); sb.append(" Wifi Running: ");
4198 formatTimeMs(sb, uidWifiRunningTime / 1000);
4199 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4200 whichBatteryRealtime)); sb.append(")\n");
4201 sb.append(prefix); sb.append(" Full Wifi Lock: ");
4202 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4203 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4204 whichBatteryRealtime)); sb.append(")\n");
4205 sb.append(prefix); sb.append(" Wifi Scan: ");
4206 formatTimeMs(sb, wifiScanTime / 1000);
4207 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004208 whichBatteryRealtime)); sb.append(") ");
4209 sb.append(wifiScanCount);
4210 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004211 pw.println(sb.toString());
4212 }
4213
Adam Lesinski5f056f62016-07-14 16:56:08 -07004214 if (wifiWakeup > 0) {
4215 sb.setLength(0);
4216 sb.append(prefix);
4217 sb.append(" WiFi AP wakeups: ");
4218 sb.append(wifiWakeup);
4219 pw.println(sb.toString());
4220 }
4221
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004222 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4223 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004224
Adam Lesinski50e47602015-12-04 17:04:54 -08004225 if (btRxBytes > 0 || btTxBytes > 0) {
4226 pw.print(prefix); pw.print(" Bluetooth network: ");
4227 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4228 pw.print(formatBytesLocked(btTxBytes));
4229 pw.println(" sent");
4230 }
4231
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004232 uidActivity |= printTimer(pw, sb, u.getBluetoothScanTimer(), rawRealtime, which, prefix,
4233 "Bluetooth Scan");
4234
Dianne Hackborn617f8772009-03-31 15:04:46 -07004235 if (u.hasUserActivity()) {
4236 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004237 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004238 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004239 if (val != 0) {
4240 if (!hasData) {
4241 sb.setLength(0);
4242 sb.append(" User activity: ");
4243 hasData = true;
4244 } else {
4245 sb.append(", ");
4246 }
4247 sb.append(val);
4248 sb.append(" ");
4249 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4250 }
4251 }
4252 if (hasData) {
4253 pw.println(sb.toString());
4254 }
4255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004256
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004257 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4258 = u.getWakelockStats();
4259 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004260 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004261 int countWakelock = 0;
4262 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4263 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4264 String linePrefix = ": ";
4265 sb.setLength(0);
4266 sb.append(prefix);
4267 sb.append(" Wake lock ");
4268 sb.append(wakelocks.keyAt(iw));
4269 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4270 "full", which, linePrefix);
4271 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
4272 "partial", which, linePrefix);
4273 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4274 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004275 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4276 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004277 sb.append(" realtime");
4278 pw.println(sb.toString());
4279 uidActivity = true;
4280 countWakelock++;
4281
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004282 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4283 rawRealtime, which);
4284 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4285 rawRealtime, which);
4286 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4287 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004288 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004289 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004290 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004291 if (countWakelock > 1) {
4292 if (totalFullWakelock != 0 || totalPartialWakelock != 0
4293 || totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004294 sb.setLength(0);
4295 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004296 sb.append(" TOTAL wake: ");
4297 boolean needComma = false;
4298 if (totalFullWakelock != 0) {
4299 needComma = true;
4300 formatTimeMs(sb, totalFullWakelock);
4301 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004302 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004303 if (totalPartialWakelock != 0) {
4304 if (needComma) {
4305 sb.append(", ");
4306 }
4307 needComma = true;
4308 formatTimeMs(sb, totalPartialWakelock);
4309 sb.append("partial");
4310 }
4311 if (totalWindowWakelock != 0) {
4312 if (needComma) {
4313 sb.append(", ");
4314 }
4315 needComma = true;
4316 formatTimeMs(sb, totalWindowWakelock);
4317 sb.append("window");
4318 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004319 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004320 if (needComma) {
4321 sb.append(",");
4322 }
4323 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004324 formatTimeMs(sb, totalDrawWakelock);
4325 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004326 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004327 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004328 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004329 }
4330 }
4331
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004332 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4333 for (int isy=syncs.size()-1; isy>=0; isy--) {
4334 final Timer timer = syncs.valueAt(isy);
4335 // Convert from microseconds to milliseconds with rounding
4336 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4337 final int count = timer.getCountLocked(which);
4338 sb.setLength(0);
4339 sb.append(prefix);
4340 sb.append(" Sync ");
4341 sb.append(syncs.keyAt(isy));
4342 sb.append(": ");
4343 if (totalTime != 0) {
4344 formatTimeMs(sb, totalTime);
4345 sb.append("realtime (");
4346 sb.append(count);
4347 sb.append(" times)");
4348 } else {
4349 sb.append("(not used)");
4350 }
4351 pw.println(sb.toString());
4352 uidActivity = true;
4353 }
4354
4355 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4356 for (int ij=jobs.size()-1; ij>=0; ij--) {
4357 final Timer timer = jobs.valueAt(ij);
4358 // Convert from microseconds to milliseconds with rounding
4359 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4360 final int count = timer.getCountLocked(which);
4361 sb.setLength(0);
4362 sb.append(prefix);
4363 sb.append(" Job ");
4364 sb.append(jobs.keyAt(ij));
4365 sb.append(": ");
4366 if (totalTime != 0) {
4367 formatTimeMs(sb, totalTime);
4368 sb.append("realtime (");
4369 sb.append(count);
4370 sb.append(" times)");
4371 } else {
4372 sb.append("(not used)");
4373 }
4374 pw.println(sb.toString());
4375 uidActivity = true;
4376 }
4377
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004378 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
4379 prefix, "Flashlight");
4380 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
4381 prefix, "Camera");
4382 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
4383 prefix, "Video");
4384 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
4385 prefix, "Audio");
4386
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004387 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4388 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004389 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004390 final Uid.Sensor se = sensors.valueAt(ise);
4391 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004392 sb.setLength(0);
4393 sb.append(prefix);
4394 sb.append(" Sensor ");
4395 int handle = se.getHandle();
4396 if (handle == Uid.Sensor.GPS) {
4397 sb.append("GPS");
4398 } else {
4399 sb.append(handle);
4400 }
4401 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004402
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004403 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004404 if (timer != null) {
4405 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004406 final long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn61659e52014-07-09 16:13:01 -07004407 rawRealtime, which) + 500) / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004408 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004409 //timer.logState();
4410 if (totalTime != 0) {
4411 formatTimeMs(sb, totalTime);
4412 sb.append("realtime (");
4413 sb.append(count);
4414 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415 } else {
4416 sb.append("(not used)");
4417 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004418 } else {
4419 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004421
4422 pw.println(sb.toString());
4423 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004424 }
4425
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004426 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4427 "Vibrator");
4428 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4429 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004430
Dianne Hackborn61659e52014-07-09 16:13:01 -07004431 long totalStateTime = 0;
4432 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4433 long time = u.getProcessStateTime(ips, rawRealtime, which);
4434 if (time > 0) {
4435 totalStateTime += time;
4436 sb.setLength(0);
4437 sb.append(prefix);
4438 sb.append(" ");
4439 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4440 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08004441 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004442 pw.println(sb.toString());
4443 uidActivity = true;
4444 }
4445 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08004446 if (totalStateTime > 0) {
4447 sb.setLength(0);
4448 sb.append(prefix);
4449 sb.append(" Total running: ");
4450 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4451 pw.println(sb.toString());
4452 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004453
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004454 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4455 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004456 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
4457 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004458 sb.setLength(0);
4459 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004460 sb.append(" Total cpu time: u=");
4461 formatTimeMs(sb, userCpuTimeUs / 1000);
4462 sb.append("s=");
4463 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004464 sb.append("p=");
4465 printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0));
4466 sb.append("mAh");
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004467 pw.println(sb.toString());
4468 }
4469
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004470 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4471 = u.getProcessStats();
4472 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4473 final Uid.Proc ps = processStats.valueAt(ipr);
4474 long userTime;
4475 long systemTime;
4476 long foregroundTime;
4477 int starts;
4478 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004480 userTime = ps.getUserTime(which);
4481 systemTime = ps.getSystemTime(which);
4482 foregroundTime = ps.getForegroundTime(which);
4483 starts = ps.getStarts(which);
4484 final int numCrashes = ps.getNumCrashes(which);
4485 final int numAnrs = ps.getNumAnrs(which);
4486 numExcessive = which == STATS_SINCE_CHARGED
4487 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004489 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
4490 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
4491 sb.setLength(0);
4492 sb.append(prefix); sb.append(" Proc ");
4493 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
4494 sb.append(prefix); sb.append(" CPU: ");
4495 formatTimeMs(sb, userTime); sb.append("usr + ");
4496 formatTimeMs(sb, systemTime); sb.append("krn ; ");
4497 formatTimeMs(sb, foregroundTime); sb.append("fg");
4498 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
4499 sb.append("\n"); sb.append(prefix); sb.append(" ");
4500 boolean hasOne = false;
4501 if (starts != 0) {
4502 hasOne = true;
4503 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07004504 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004505 if (numCrashes != 0) {
4506 if (hasOne) {
4507 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004508 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004509 hasOne = true;
4510 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004511 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004512 if (numAnrs != 0) {
4513 if (hasOne) {
4514 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004515 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004516 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004517 }
4518 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004519 pw.println(sb.toString());
4520 for (int e=0; e<numExcessive; e++) {
4521 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
4522 if (ew != null) {
4523 pw.print(prefix); pw.print(" * Killed for ");
4524 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
4525 pw.print("wake lock");
4526 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
4527 pw.print("cpu");
4528 } else {
4529 pw.print("unknown");
4530 }
4531 pw.print(" use: ");
4532 TimeUtils.formatDuration(ew.usedTime, pw);
4533 pw.print(" over ");
4534 TimeUtils.formatDuration(ew.overTime, pw);
4535 if (ew.overTime != 0) {
4536 pw.print(" (");
4537 pw.print((ew.usedTime*100)/ew.overTime);
4538 pw.println("%)");
4539 }
4540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004541 }
4542 uidActivity = true;
4543 }
4544 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004545
4546 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4547 = u.getPackageStats();
4548 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4549 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
4550 pw.println(":");
4551 boolean apkActivity = false;
4552 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4553 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4554 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
4555 pw.print(prefix); pw.print(" Wakeup alarm ");
4556 pw.print(alarms.keyAt(iwa)); pw.print(": ");
4557 pw.print(alarms.valueAt(iwa).getCountLocked(which));
4558 pw.println(" times");
4559 apkActivity = true;
4560 }
4561 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4562 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4563 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4564 final long startTime = ss.getStartTime(batteryUptime, which);
4565 final int starts = ss.getStarts(which);
4566 final int launches = ss.getLaunches(which);
4567 if (startTime != 0 || starts != 0 || launches != 0) {
4568 sb.setLength(0);
4569 sb.append(prefix); sb.append(" Service ");
4570 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
4571 sb.append(prefix); sb.append(" Created for: ");
4572 formatTimeMs(sb, startTime / 1000);
4573 sb.append("uptime\n");
4574 sb.append(prefix); sb.append(" Starts: ");
4575 sb.append(starts);
4576 sb.append(", launches: "); sb.append(launches);
4577 pw.println(sb.toString());
4578 apkActivity = true;
4579 }
4580 }
4581 if (!apkActivity) {
4582 pw.print(prefix); pw.println(" (nothing executed)");
4583 }
4584 uidActivity = true;
4585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004586 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004587 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 }
4589 }
4590 }
4591
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004592 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004593 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004594 int diff = oldval ^ newval;
4595 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004596 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004597 for (int i=0; i<descriptions.length; i++) {
4598 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004599 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004600 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004601 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004602 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004603 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004604 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
4605 didWake = true;
4606 pw.print("=");
4607 if (longNames) {
4608 UserHandle.formatUid(pw, wakelockTag.uid);
4609 pw.print(":\"");
4610 pw.print(wakelockTag.string);
4611 pw.print("\"");
4612 } else {
4613 pw.print(wakelockTag.poolIdx);
4614 }
4615 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004616 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004617 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004618 pw.print("=");
4619 int val = (newval&bd.mask)>>bd.shift;
4620 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004621 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004622 } else {
4623 pw.print(val);
4624 }
4625 }
4626 }
4627 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004628 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07004629 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004630 if (longNames) {
4631 UserHandle.formatUid(pw, wakelockTag.uid);
4632 pw.print(":\"");
4633 pw.print(wakelockTag.string);
4634 pw.print("\"");
4635 } else {
4636 pw.print(wakelockTag.poolIdx);
4637 }
4638 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004639 }
4640
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004641 public void prepareForDumpLocked() {
4642 }
4643
4644 public static class HistoryPrinter {
4645 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004646 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004647 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004648 int oldStatus = -1;
4649 int oldHealth = -1;
4650 int oldPlug = -1;
4651 int oldTemp = -1;
4652 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004653 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004654 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004655
Dianne Hackborn3251b902014-06-20 14:40:53 -07004656 void reset() {
4657 oldState = oldState2 = 0;
4658 oldLevel = -1;
4659 oldStatus = -1;
4660 oldHealth = -1;
4661 oldPlug = -1;
4662 oldTemp = -1;
4663 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004664 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07004665 }
4666
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004667 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004668 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004669 if (!checkin) {
4670 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004671 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004672 pw.print(" (");
4673 pw.print(rec.numReadInts);
4674 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004675 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004676 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4677 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004678 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004679 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004680 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004681 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004682 }
4683 lastTime = rec.time;
4684 }
4685 if (rec.cmd == HistoryItem.CMD_START) {
4686 if (checkin) {
4687 pw.print(":");
4688 }
4689 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004690 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004691 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4692 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004693 if (checkin) {
4694 pw.print(":");
4695 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004696 if (rec.cmd == HistoryItem.CMD_RESET) {
4697 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004698 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004699 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004700 pw.print("TIME:");
4701 if (checkin) {
4702 pw.println(rec.currentTime);
4703 } else {
4704 pw.print(" ");
4705 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4706 rec.currentTime).toString());
4707 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004708 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4709 if (checkin) {
4710 pw.print(":");
4711 }
4712 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004713 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4714 if (checkin) {
4715 pw.print(":");
4716 }
4717 pw.println("*OVERFLOW*");
4718 } else {
4719 if (!checkin) {
4720 if (rec.batteryLevel < 10) pw.print("00");
4721 else if (rec.batteryLevel < 100) pw.print("0");
4722 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004723 if (verbose) {
4724 pw.print(" ");
4725 if (rec.states < 0) ;
4726 else if (rec.states < 0x10) pw.print("0000000");
4727 else if (rec.states < 0x100) pw.print("000000");
4728 else if (rec.states < 0x1000) pw.print("00000");
4729 else if (rec.states < 0x10000) pw.print("0000");
4730 else if (rec.states < 0x100000) pw.print("000");
4731 else if (rec.states < 0x1000000) pw.print("00");
4732 else if (rec.states < 0x10000000) pw.print("0");
4733 pw.print(Integer.toHexString(rec.states));
4734 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004735 } else {
4736 if (oldLevel != rec.batteryLevel) {
4737 oldLevel = rec.batteryLevel;
4738 pw.print(",Bl="); pw.print(rec.batteryLevel);
4739 }
4740 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004741 if (oldStatus != rec.batteryStatus) {
4742 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004743 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004744 switch (oldStatus) {
4745 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004746 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004747 break;
4748 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004749 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004750 break;
4751 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004752 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004753 break;
4754 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004755 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004756 break;
4757 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004758 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004759 break;
4760 default:
4761 pw.print(oldStatus);
4762 break;
4763 }
4764 }
4765 if (oldHealth != rec.batteryHealth) {
4766 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004767 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004768 switch (oldHealth) {
4769 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004770 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004771 break;
4772 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004773 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004774 break;
4775 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004776 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004777 break;
4778 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004779 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004780 break;
4781 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004782 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004783 break;
4784 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004785 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004786 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004787 case BatteryManager.BATTERY_HEALTH_COLD:
4788 pw.print(checkin ? "c" : "cold");
4789 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004790 default:
4791 pw.print(oldHealth);
4792 break;
4793 }
4794 }
4795 if (oldPlug != rec.batteryPlugType) {
4796 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004797 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004798 switch (oldPlug) {
4799 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004800 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004801 break;
4802 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004803 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004804 break;
4805 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004806 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004807 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004808 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004809 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004810 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004811 default:
4812 pw.print(oldPlug);
4813 break;
4814 }
4815 }
4816 if (oldTemp != rec.batteryTemperature) {
4817 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004818 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004819 pw.print(oldTemp);
4820 }
4821 if (oldVolt != rec.batteryVoltage) {
4822 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004823 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004824 pw.print(oldVolt);
4825 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004826 final int chargeMAh = rec.batteryChargeUAh / 1000;
4827 if (oldChargeMAh != chargeMAh) {
4828 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07004829 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004830 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07004831 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004832 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004833 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004834 printBitDescriptions(pw, oldState2, rec.states2, null,
4835 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004836 if (rec.wakeReasonTag != null) {
4837 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004838 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004839 pw.print(rec.wakeReasonTag.poolIdx);
4840 } else {
4841 pw.print(" wake_reason=");
4842 pw.print(rec.wakeReasonTag.uid);
4843 pw.print(":\"");
4844 pw.print(rec.wakeReasonTag.string);
4845 pw.print("\"");
4846 }
4847 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004848 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004849 pw.print(checkin ? "," : " ");
4850 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4851 pw.print("+");
4852 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4853 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004854 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004855 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4856 : HISTORY_EVENT_NAMES;
4857 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4858 | HistoryItem.EVENT_FLAG_FINISH);
4859 if (idx >= 0 && idx < eventNames.length) {
4860 pw.print(eventNames[idx]);
4861 } else {
4862 pw.print(checkin ? "Ev" : "event");
4863 pw.print(idx);
4864 }
4865 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004866 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004867 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004868 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004869 UserHandle.formatUid(pw, rec.eventTag.uid);
4870 pw.print(":\"");
4871 pw.print(rec.eventTag.string);
4872 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004873 }
4874 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004875 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004876 if (rec.stepDetails != null) {
4877 if (!checkin) {
4878 pw.print(" Details: cpu=");
4879 pw.print(rec.stepDetails.userTime);
4880 pw.print("u+");
4881 pw.print(rec.stepDetails.systemTime);
4882 pw.print("s");
4883 if (rec.stepDetails.appCpuUid1 >= 0) {
4884 pw.print(" (");
4885 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4886 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4887 if (rec.stepDetails.appCpuUid2 >= 0) {
4888 pw.print(", ");
4889 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4890 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4891 }
4892 if (rec.stepDetails.appCpuUid3 >= 0) {
4893 pw.print(", ");
4894 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4895 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4896 }
4897 pw.print(')');
4898 }
4899 pw.println();
4900 pw.print(" /proc/stat=");
4901 pw.print(rec.stepDetails.statUserTime);
4902 pw.print(" usr, ");
4903 pw.print(rec.stepDetails.statSystemTime);
4904 pw.print(" sys, ");
4905 pw.print(rec.stepDetails.statIOWaitTime);
4906 pw.print(" io, ");
4907 pw.print(rec.stepDetails.statIrqTime);
4908 pw.print(" irq, ");
4909 pw.print(rec.stepDetails.statSoftIrqTime);
4910 pw.print(" sirq, ");
4911 pw.print(rec.stepDetails.statIdlTime);
4912 pw.print(" idle");
4913 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4914 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4915 + rec.stepDetails.statSoftIrqTime;
4916 int total = totalRun + rec.stepDetails.statIdlTime;
4917 if (total > 0) {
4918 pw.print(" (");
4919 float perc = ((float)totalRun) / ((float)total) * 100;
4920 pw.print(String.format("%.1f%%", perc));
4921 pw.print(" of ");
4922 StringBuilder sb = new StringBuilder(64);
4923 formatTimeMsNoSpace(sb, total*10);
4924 pw.print(sb);
4925 pw.print(")");
4926 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07004927 pw.print(", PlatformIdleStat ");
4928 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004929 pw.println();
4930 } else {
4931 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4932 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4933 pw.print(rec.stepDetails.userTime);
4934 pw.print(":");
4935 pw.print(rec.stepDetails.systemTime);
4936 if (rec.stepDetails.appCpuUid1 >= 0) {
4937 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4938 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4939 if (rec.stepDetails.appCpuUid2 >= 0) {
4940 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4941 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4942 }
4943 if (rec.stepDetails.appCpuUid3 >= 0) {
4944 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4945 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4946 }
4947 }
4948 pw.println();
4949 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4950 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4951 pw.print(rec.stepDetails.statUserTime);
4952 pw.print(',');
4953 pw.print(rec.stepDetails.statSystemTime);
4954 pw.print(',');
4955 pw.print(rec.stepDetails.statIOWaitTime);
4956 pw.print(',');
4957 pw.print(rec.stepDetails.statIrqTime);
4958 pw.print(',');
4959 pw.print(rec.stepDetails.statSoftIrqTime);
4960 pw.print(',');
4961 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07004962 pw.print(',');
4963 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004964 pw.println();
4965 }
4966 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004967 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004968 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004969 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004970 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004971
4972 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4973 UserHandle.formatUid(pw, uid);
4974 pw.print("=");
4975 pw.print(utime);
4976 pw.print("u+");
4977 pw.print(stime);
4978 pw.print("s");
4979 }
4980
4981 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
4982 pw.print('/');
4983 pw.print(uid);
4984 pw.print(":");
4985 pw.print(utime);
4986 pw.print(":");
4987 pw.print(stime);
4988 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004989 }
4990
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004991 private void printSizeValue(PrintWriter pw, long size) {
4992 float result = size;
4993 String suffix = "";
4994 if (result >= 10*1024) {
4995 suffix = "KB";
4996 result = result / 1024;
4997 }
4998 if (result >= 10*1024) {
4999 suffix = "MB";
5000 result = result / 1024;
5001 }
5002 if (result >= 10*1024) {
5003 suffix = "GB";
5004 result = result / 1024;
5005 }
5006 if (result >= 10*1024) {
5007 suffix = "TB";
5008 result = result / 1024;
5009 }
5010 if (result >= 10*1024) {
5011 suffix = "PB";
5012 result = result / 1024;
5013 }
5014 pw.print((int)result);
5015 pw.print(suffix);
5016 }
5017
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005018 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5019 String label3, long estimatedTime) {
5020 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005021 return false;
5022 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005023 pw.print(label1);
5024 pw.print(label2);
5025 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005026 StringBuilder sb = new StringBuilder(64);
5027 formatTimeMs(sb, estimatedTime);
5028 pw.print(sb);
5029 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005030 return true;
5031 }
5032
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005033 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5034 LevelStepTracker steps, boolean checkin) {
5035 if (steps == null) {
5036 return false;
5037 }
5038 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005039 if (count <= 0) {
5040 return false;
5041 }
5042 if (!checkin) {
5043 pw.println(header);
5044 }
Kweku Adams030980a2015-04-01 16:07:48 -07005045 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005046 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005047 long duration = steps.getDurationAt(i);
5048 int level = steps.getLevelAt(i);
5049 long initMode = steps.getInitModeAt(i);
5050 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005051 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005052 lineArgs[0] = Long.toString(duration);
5053 lineArgs[1] = Integer.toString(level);
5054 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5055 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5056 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5057 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5058 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5059 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005060 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005061 }
5062 } else {
5063 lineArgs[2] = "";
5064 }
5065 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5066 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5067 } else {
5068 lineArgs[3] = "";
5069 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005070 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005071 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005072 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005073 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005074 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005075 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5076 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005077 pw.print(prefix);
5078 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005079 TimeUtils.formatDuration(duration, pw);
5080 pw.print(" to "); pw.print(level);
5081 boolean haveModes = false;
5082 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5083 pw.print(" (");
5084 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5085 case Display.STATE_OFF: pw.print("screen-off"); break;
5086 case Display.STATE_ON: pw.print("screen-on"); break;
5087 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5088 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005089 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005090 }
5091 haveModes = true;
5092 }
5093 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5094 pw.print(haveModes ? ", " : " (");
5095 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5096 ? "power-save-on" : "power-save-off");
5097 haveModes = true;
5098 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005099 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5100 pw.print(haveModes ? ", " : " (");
5101 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5102 ? "device-idle-on" : "device-idle-off");
5103 haveModes = true;
5104 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005105 if (haveModes) {
5106 pw.print(")");
5107 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005108 pw.println();
5109 }
5110 }
5111 return true;
5112 }
5113
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005114 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005115 public static final int DUMP_DAILY_ONLY = 1<<2;
5116 public static final int DUMP_HISTORY_ONLY = 1<<3;
5117 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5118 public static final int DUMP_VERBOSE = 1<<5;
5119 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005120
Dianne Hackborn37de0982014-05-09 09:32:18 -07005121 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5122 final HistoryPrinter hprinter = new HistoryPrinter();
5123 final HistoryItem rec = new HistoryItem();
5124 long lastTime = -1;
5125 long baseTime = -1;
5126 boolean printed = false;
5127 HistoryEventTracker tracker = null;
5128 while (getNextHistoryLocked(rec)) {
5129 lastTime = rec.time;
5130 if (baseTime < 0) {
5131 baseTime = lastTime;
5132 }
5133 if (rec.time >= histStart) {
5134 if (histStart >= 0 && !printed) {
5135 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005136 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005137 || rec.cmd == HistoryItem.CMD_START
5138 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005139 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005140 hprinter.printNextItem(pw, rec, baseTime, checkin,
5141 (flags&DUMP_VERBOSE) != 0);
5142 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005143 } else if (rec.currentTime != 0) {
5144 printed = true;
5145 byte cmd = rec.cmd;
5146 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005147 hprinter.printNextItem(pw, rec, baseTime, checkin,
5148 (flags&DUMP_VERBOSE) != 0);
5149 rec.cmd = cmd;
5150 }
5151 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005152 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5153 hprinter.printNextItem(pw, rec, baseTime, checkin,
5154 (flags&DUMP_VERBOSE) != 0);
5155 rec.cmd = HistoryItem.CMD_UPDATE;
5156 }
5157 int oldEventCode = rec.eventCode;
5158 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005159 rec.eventTag = new HistoryTag();
5160 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5161 HashMap<String, SparseIntArray> active
5162 = tracker.getStateForEvent(i);
5163 if (active == null) {
5164 continue;
5165 }
5166 for (HashMap.Entry<String, SparseIntArray> ent
5167 : active.entrySet()) {
5168 SparseIntArray uids = ent.getValue();
5169 for (int j=0; j<uids.size(); j++) {
5170 rec.eventCode = i;
5171 rec.eventTag.string = ent.getKey();
5172 rec.eventTag.uid = uids.keyAt(j);
5173 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005174 hprinter.printNextItem(pw, rec, baseTime, checkin,
5175 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005176 rec.wakeReasonTag = null;
5177 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005178 }
5179 }
5180 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005181 rec.eventCode = oldEventCode;
5182 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005183 tracker = null;
5184 }
5185 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005186 hprinter.printNextItem(pw, rec, baseTime, checkin,
5187 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005188 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5189 // This is an attempt to aggregate the previous state and generate
5190 // fake events to reflect that state at the point where we start
5191 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005192 if (tracker == null) {
5193 tracker = new HistoryEventTracker();
5194 }
5195 tracker.updateState(rec.eventCode, rec.eventTag.string,
5196 rec.eventTag.uid, rec.eventTag.poolIdx);
5197 }
5198 }
5199 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005200 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005201 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5202 }
5203 }
5204
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005205 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5206 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5207 if (steps == null) {
5208 return;
5209 }
5210 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5211 if (timeRemaining >= 0) {
5212 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5213 tmpSb.setLength(0);
5214 formatTimeMs(tmpSb, timeRemaining);
5215 pw.print(tmpSb);
5216 pw.print(" (from "); pw.print(tmpOutInt[0]);
5217 pw.println(" steps)");
5218 }
5219 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5220 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5221 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5222 if (estimatedTime > 0) {
5223 pw.print(prefix); pw.print(label); pw.print(" ");
5224 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5225 pw.print(" time: ");
5226 tmpSb.setLength(0);
5227 formatTimeMs(tmpSb, estimatedTime);
5228 pw.print(tmpSb);
5229 pw.print(" (from "); pw.print(tmpOutInt[0]);
5230 pw.println(" steps)");
5231 }
5232 }
5233 }
5234
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005235 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5236 ArrayList<PackageChange> changes) {
5237 if (changes == null) {
5238 return;
5239 }
5240 pw.print(prefix); pw.println("Package changes:");
5241 for (int i=0; i<changes.size(); i++) {
5242 PackageChange pc = changes.get(i);
5243 if (pc.mUpdate) {
5244 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5245 pw.print(" vers="); pw.println(pc.mVersionCode);
5246 } else {
5247 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5248 }
5249 }
5250 }
5251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005252 /**
5253 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5254 *
5255 * @param pw a Printer to receive the dump output.
5256 */
5257 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005258 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005259 prepareForDumpLocked();
5260
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005261 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005262 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005263
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005264 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005265 final long historyTotalSize = getHistoryTotalSize();
5266 final long historyUsedSize = getHistoryUsedSize();
5267 if (startIteratingHistoryLocked()) {
5268 try {
5269 pw.print("Battery History (");
5270 pw.print((100*historyUsedSize)/historyTotalSize);
5271 pw.print("% used, ");
5272 printSizeValue(pw, historyUsedSize);
5273 pw.print(" used of ");
5274 printSizeValue(pw, historyTotalSize);
5275 pw.print(", ");
5276 pw.print(getHistoryStringPoolSize());
5277 pw.print(" strings using ");
5278 printSizeValue(pw, getHistoryStringPoolBytes());
5279 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005280 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005281 pw.println();
5282 } finally {
5283 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005284 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005285 }
5286
5287 if (startIteratingOldHistoryLocked()) {
5288 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005289 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005290 pw.println("Old battery History:");
5291 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005292 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005293 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005294 if (baseTime < 0) {
5295 baseTime = rec.time;
5296 }
5297 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005298 }
5299 pw.println();
5300 } finally {
5301 finishIteratingOldHistoryLocked();
5302 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005303 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005304 }
5305
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005306 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005307 return;
5308 }
5309
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005310 if (!filtering) {
5311 SparseArray<? extends Uid> uidStats = getUidStats();
5312 final int NU = uidStats.size();
5313 boolean didPid = false;
5314 long nowRealtime = SystemClock.elapsedRealtime();
5315 for (int i=0; i<NU; i++) {
5316 Uid uid = uidStats.valueAt(i);
5317 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
5318 if (pids != null) {
5319 for (int j=0; j<pids.size(); j++) {
5320 Uid.Pid pid = pids.valueAt(j);
5321 if (!didPid) {
5322 pw.println("Per-PID Stats:");
5323 didPid = true;
5324 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005325 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
5326 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005327 pw.print(" PID "); pw.print(pids.keyAt(j));
5328 pw.print(" wake time: ");
5329 TimeUtils.formatDuration(time, pw);
5330 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005331 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005332 }
5333 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005334 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005335 pw.println();
5336 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005337 }
5338
5339 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005340 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
5341 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005342 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5343 if (timeRemaining >= 0) {
5344 pw.print(" Estimated discharge time remaining: ");
5345 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5346 pw.println();
5347 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005348 final LevelStepTracker steps = getDischargeLevelStepTracker();
5349 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5350 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
5351 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5352 STEP_LEVEL_MODE_VALUES[i], null));
5353 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005354 pw.println();
5355 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005356 if (dumpDurationSteps(pw, " ", "Charge step durations:",
5357 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005358 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5359 if (timeRemaining >= 0) {
5360 pw.print(" Estimated charge time remaining: ");
5361 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5362 pw.println();
5363 }
5364 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005365 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005366 }
5367 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
5368 pw.println("Daily stats:");
5369 pw.print(" Current start time: ");
5370 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5371 getCurrentDailyStartTime()).toString());
5372 pw.print(" Next min deadline: ");
5373 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5374 getNextMinDailyDeadline()).toString());
5375 pw.print(" Next max deadline: ");
5376 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5377 getNextMaxDailyDeadline()).toString());
5378 StringBuilder sb = new StringBuilder(64);
5379 int[] outInt = new int[1];
5380 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
5381 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005382 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
5383 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005384 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005385 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
5386 dsteps, false)) {
5387 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5388 sb, outInt);
5389 }
5390 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
5391 csteps, false)) {
5392 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5393 sb, outInt);
5394 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005395 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005396 } else {
5397 pw.println(" Current daily steps:");
5398 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5399 sb, outInt);
5400 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5401 sb, outInt);
5402 }
5403 }
5404 DailyItem dit;
5405 int curIndex = 0;
5406 while ((dit=getDailyItemLocked(curIndex)) != null) {
5407 curIndex++;
5408 if ((flags&DUMP_DAILY_ONLY) != 0) {
5409 pw.println();
5410 }
5411 pw.print(" Daily from ");
5412 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
5413 pw.print(" to ");
5414 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
5415 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005416 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005417 if (dumpDurationSteps(pw, " ",
5418 " Discharge step durations:", dit.mDischargeSteps, false)) {
5419 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5420 sb, outInt);
5421 }
5422 if (dumpDurationSteps(pw, " ",
5423 " Charge step durations:", dit.mChargeSteps, false)) {
5424 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5425 sb, outInt);
5426 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005427 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005428 } else {
5429 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5430 sb, outInt);
5431 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5432 sb, outInt);
5433 }
5434 }
5435 pw.println();
5436 }
5437 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005438 pw.println("Statistics since last charge:");
5439 pw.println(" System starts: " + getStartCount()
5440 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005441 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5442 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005443 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005444 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005445 }
5446
5447 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005448 public void dumpCheckinLocked(Context context, PrintWriter pw,
5449 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005450 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005451
5452 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005453 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5454 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005455
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005456 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5457
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005458 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005459 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005460
5461 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005462 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005463 try {
5464 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5465 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5466 pw.print(HISTORY_STRING_POOL); pw.print(',');
5467 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005468 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005469 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005470 pw.print(",\"");
5471 String str = getHistoryTagPoolString(i);
5472 str = str.replace("\\", "\\\\");
5473 str = str.replace("\"", "\\\"");
5474 pw.print(str);
5475 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005476 pw.println();
5477 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005478 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005479 } finally {
5480 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08005481 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005482 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005483 }
5484
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005485 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005486 return;
5487 }
5488
Dianne Hackborne4a59512010-12-07 11:08:07 -08005489 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005490 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08005491 for (int i=0; i<apps.size(); i++) {
5492 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005493 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
5494 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08005495 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005496 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
5497 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005498 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005499 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005500 }
5501 SparseArray<? extends Uid> uidStats = getUidStats();
5502 final int NU = uidStats.size();
5503 String[] lineArgs = new String[2];
5504 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005505 int uid = UserHandle.getAppId(uidStats.keyAt(i));
5506 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
5507 if (pkgs != null && !pkgs.second.value) {
5508 pkgs.second.value = true;
5509 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08005510 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005511 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005512 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
5513 (Object[])lineArgs);
5514 }
5515 }
5516 }
5517 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005518 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005519 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005520 String[] lineArgs = new String[1];
5521 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5522 if (timeRemaining >= 0) {
5523 lineArgs[0] = Long.toString(timeRemaining);
5524 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
5525 (Object[])lineArgs);
5526 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005527 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005528 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5529 if (timeRemaining >= 0) {
5530 lineArgs[0] = Long.toString(timeRemaining);
5531 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
5532 (Object[])lineArgs);
5533 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07005534 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
5535 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005536 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005538}