blob: ad8cbd83370b0cae61cce1eb55932cde43efba7d [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 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800179 static final String CHECKIN_VERSION = "17";
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800550 /*
551 * FIXME: it's not correct to use this magic value because it
552 * could clash with a sensor handle (which are defined by
553 * the sensor HAL, and therefore out of our control
554 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 // Magic sensor number for the GPS.
556 public static final int GPS = -10000;
557
558 public abstract int getHandle();
559
560 public abstract Timer getSensorTime();
561 }
562
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700563 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800564 public int mWakeNesting;
565 public long mWakeSumMs;
566 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700567 }
568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 /**
570 * The statistics associated with a particular process.
571 */
572 public static abstract class Proc {
573
Dianne Hackborn287952c2010-09-22 22:34:31 -0700574 public static class ExcessivePower {
575 public static final int TYPE_WAKE = 1;
576 public static final int TYPE_CPU = 2;
577
578 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700579 public long overTime;
580 public long usedTime;
581 }
582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800584 * Returns true if this process is still active in the battery stats.
585 */
586 public abstract boolean isActive();
587
588 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700589 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700591 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 */
593 public abstract long getUserTime(int which);
594
595 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700596 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700598 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 */
600 public abstract long getSystemTime(int which);
601
602 /**
603 * Returns the number of times the process has been started.
604 *
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 int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700608
609 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800610 * Returns the number of times the process has crashed.
611 *
612 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
613 */
614 public abstract int getNumCrashes(int which);
615
616 /**
617 * Returns the number of times the process has ANRed.
618 *
619 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
620 */
621 public abstract int getNumAnrs(int which);
622
623 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700624 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700625 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700626 * @return foreground cpu time in microseconds
627 */
628 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700629
Dianne Hackborn287952c2010-09-22 22:34:31 -0700630 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700631
Dianne Hackborn287952c2010-09-22 22:34:31 -0700632 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 }
634
635 /**
636 * The statistics associated with a particular package.
637 */
638 public static abstract class Pkg {
639
640 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700641 * Returns information about all wakeup alarms that have been triggered for this
642 * package. The mapping keys are tag names for the alarms, the counter contains
643 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700645 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646
647 /**
648 * Returns a mapping containing service statistics.
649 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700650 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651
652 /**
653 * The statistics associated with a particular service.
654 */
Joe Onoratoabded112016-02-08 16:49:39 -0800655 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656
657 /**
658 * Returns the amount of time spent started.
659 *
660 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700661 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 * @return
663 */
664 public abstract long getStartTime(long batteryUptime, int which);
665
666 /**
667 * Returns the total number of times startService() has been called.
668 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700669 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 */
671 public abstract int getStarts(int which);
672
673 /**
674 * Returns the total number times the service has been launched.
675 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700676 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 */
678 public abstract int getLaunches(int which);
679 }
680 }
681 }
682
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800683 public static final class LevelStepTracker {
684 public long mLastStepTime = -1;
685 public int mNumStepDurations;
686 public final long[] mStepDurations;
687
688 public LevelStepTracker(int maxLevelSteps) {
689 mStepDurations = new long[maxLevelSteps];
690 }
691
692 public LevelStepTracker(int numSteps, long[] steps) {
693 mNumStepDurations = numSteps;
694 mStepDurations = new long[numSteps];
695 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
696 }
697
698 public long getDurationAt(int index) {
699 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
700 }
701
702 public int getLevelAt(int index) {
703 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
704 >> STEP_LEVEL_LEVEL_SHIFT);
705 }
706
707 public int getInitModeAt(int index) {
708 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
709 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
710 }
711
712 public int getModModeAt(int index) {
713 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
714 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
715 }
716
717 private void appendHex(long val, int topOffset, StringBuilder out) {
718 boolean hasData = false;
719 while (topOffset >= 0) {
720 int digit = (int)( (val>>topOffset) & 0xf );
721 topOffset -= 4;
722 if (!hasData && digit == 0) {
723 continue;
724 }
725 hasData = true;
726 if (digit >= 0 && digit <= 9) {
727 out.append((char)('0' + digit));
728 } else {
729 out.append((char)('a' + digit - 10));
730 }
731 }
732 }
733
734 public void encodeEntryAt(int index, StringBuilder out) {
735 long item = mStepDurations[index];
736 long duration = item & STEP_LEVEL_TIME_MASK;
737 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
738 >> STEP_LEVEL_LEVEL_SHIFT);
739 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
740 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
741 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
742 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
743 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
744 case Display.STATE_OFF: out.append('f'); break;
745 case Display.STATE_ON: out.append('o'); break;
746 case Display.STATE_DOZE: out.append('d'); break;
747 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
748 }
749 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
750 out.append('p');
751 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700752 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
753 out.append('i');
754 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800755 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
756 case Display.STATE_OFF: out.append('F'); break;
757 case Display.STATE_ON: out.append('O'); break;
758 case Display.STATE_DOZE: out.append('D'); break;
759 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
760 }
761 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
762 out.append('P');
763 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700764 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
765 out.append('I');
766 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800767 out.append('-');
768 appendHex(level, 4, out);
769 out.append('-');
770 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
771 }
772
773 public void decodeEntryAt(int index, String value) {
774 final int N = value.length();
775 int i = 0;
776 char c;
777 long out = 0;
778 while (i < N && (c=value.charAt(i)) != '-') {
779 i++;
780 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800781 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800782 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800783 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800784 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800785 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800786 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800787 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
788 << STEP_LEVEL_INITIAL_MODE_SHIFT);
789 break;
790 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
791 << STEP_LEVEL_INITIAL_MODE_SHIFT);
792 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700793 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
794 << STEP_LEVEL_INITIAL_MODE_SHIFT);
795 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800796 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
797 break;
798 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
799 break;
800 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
801 break;
802 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
803 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
804 break;
805 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
806 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800807 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700808 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
809 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
810 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800811 }
812 }
813 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800814 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800815 while (i < N && (c=value.charAt(i)) != '-') {
816 i++;
817 level <<= 4;
818 if (c >= '0' && c <= '9') {
819 level += c - '0';
820 } else if (c >= 'a' && c <= 'f') {
821 level += c - 'a' + 10;
822 } else if (c >= 'A' && c <= 'F') {
823 level += c - 'A' + 10;
824 }
825 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800826 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800827 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
828 long duration = 0;
829 while (i < N && (c=value.charAt(i)) != '-') {
830 i++;
831 duration <<= 4;
832 if (c >= '0' && c <= '9') {
833 duration += c - '0';
834 } else if (c >= 'a' && c <= 'f') {
835 duration += c - 'a' + 10;
836 } else if (c >= 'A' && c <= 'F') {
837 duration += c - 'A' + 10;
838 }
839 }
840 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
841 }
842
843 public void init() {
844 mLastStepTime = -1;
845 mNumStepDurations = 0;
846 }
847
848 public void clearTime() {
849 mLastStepTime = -1;
850 }
851
852 public long computeTimePerLevel() {
853 final long[] steps = mStepDurations;
854 final int numSteps = mNumStepDurations;
855
856 // For now we'll do a simple average across all steps.
857 if (numSteps <= 0) {
858 return -1;
859 }
860 long total = 0;
861 for (int i=0; i<numSteps; i++) {
862 total += steps[i] & STEP_LEVEL_TIME_MASK;
863 }
864 return total / numSteps;
865 /*
866 long[] buckets = new long[numSteps];
867 int numBuckets = 0;
868 int numToAverage = 4;
869 int i = 0;
870 while (i < numSteps) {
871 long totalTime = 0;
872 int num = 0;
873 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
874 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
875 num++;
876 }
877 buckets[numBuckets] = totalTime / num;
878 numBuckets++;
879 numToAverage *= 2;
880 i += num;
881 }
882 if (numBuckets < 1) {
883 return -1;
884 }
885 long averageTime = buckets[numBuckets-1];
886 for (i=numBuckets-2; i>=0; i--) {
887 averageTime = (averageTime + buckets[i]) / 2;
888 }
889 return averageTime;
890 */
891 }
892
893 public long computeTimeEstimate(long modesOfInterest, long modeValues,
894 int[] outNumOfInterest) {
895 final long[] steps = mStepDurations;
896 final int count = mNumStepDurations;
897 if (count <= 0) {
898 return -1;
899 }
900 long total = 0;
901 int numOfInterest = 0;
902 for (int i=0; i<count; i++) {
903 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
904 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
905 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
906 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
907 // If the modes of interest didn't change during this step period...
908 if ((modMode&modesOfInterest) == 0) {
909 // And the mode values during this period match those we are measuring...
910 if ((initMode&modesOfInterest) == modeValues) {
911 // Then this can be used to estimate the total time!
912 numOfInterest++;
913 total += steps[i] & STEP_LEVEL_TIME_MASK;
914 }
915 }
916 }
917 if (numOfInterest <= 0) {
918 return -1;
919 }
920
921 if (outNumOfInterest != null) {
922 outNumOfInterest[0] = numOfInterest;
923 }
924
925 // The estimated time is the average time we spend in each level, multipled
926 // by 100 -- the total number of battery levels
927 return (total / numOfInterest) * 100;
928 }
929
930 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
931 int stepCount = mNumStepDurations;
932 final long lastStepTime = mLastStepTime;
933 if (lastStepTime >= 0 && numStepLevels > 0) {
934 final long[] steps = mStepDurations;
935 long duration = elapsedRealtime - lastStepTime;
936 for (int i=0; i<numStepLevels; i++) {
937 System.arraycopy(steps, 0, steps, 1, steps.length-1);
938 long thisDuration = duration / (numStepLevels-i);
939 duration -= thisDuration;
940 if (thisDuration > STEP_LEVEL_TIME_MASK) {
941 thisDuration = STEP_LEVEL_TIME_MASK;
942 }
943 steps[0] = thisDuration | modeBits;
944 }
945 stepCount += numStepLevels;
946 if (stepCount > steps.length) {
947 stepCount = steps.length;
948 }
949 }
950 mNumStepDurations = stepCount;
951 mLastStepTime = elapsedRealtime;
952 }
953
954 public void readFromParcel(Parcel in) {
955 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -0700956 if (N > mStepDurations.length) {
957 throw new ParcelFormatException("more step durations than available: " + N);
958 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800959 mNumStepDurations = N;
960 for (int i=0; i<N; i++) {
961 mStepDurations[i] = in.readLong();
962 }
963 }
964
965 public void writeToParcel(Parcel out) {
966 final int N = mNumStepDurations;
967 out.writeInt(N);
968 for (int i=0; i<N; i++) {
969 out.writeLong(mStepDurations[i]);
970 }
971 }
972 }
973
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700974 public static final class PackageChange {
975 public String mPackageName;
976 public boolean mUpdate;
977 public int mVersionCode;
978 }
979
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800980 public static final class DailyItem {
981 public long mStartTime;
982 public long mEndTime;
983 public LevelStepTracker mDischargeSteps;
984 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700985 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800986 }
987
988 public abstract DailyItem getDailyItemLocked(int daysAgo);
989
990 public abstract long getCurrentDailyStartTime();
991
992 public abstract long getNextMinDailyDeadline();
993
994 public abstract long getNextMaxDailyDeadline();
995
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800996 public final static class HistoryTag {
997 public String string;
998 public int uid;
999
1000 public int poolIdx;
1001
1002 public void setTo(HistoryTag o) {
1003 string = o.string;
1004 uid = o.uid;
1005 poolIdx = o.poolIdx;
1006 }
1007
1008 public void setTo(String _string, int _uid) {
1009 string = _string;
1010 uid = _uid;
1011 poolIdx = -1;
1012 }
1013
1014 public void writeToParcel(Parcel dest, int flags) {
1015 dest.writeString(string);
1016 dest.writeInt(uid);
1017 }
1018
1019 public void readFromParcel(Parcel src) {
1020 string = src.readString();
1021 uid = src.readInt();
1022 poolIdx = -1;
1023 }
1024
1025 @Override
1026 public boolean equals(Object o) {
1027 if (this == o) return true;
1028 if (o == null || getClass() != o.getClass()) return false;
1029
1030 HistoryTag that = (HistoryTag) o;
1031
1032 if (uid != that.uid) return false;
1033 if (!string.equals(that.string)) return false;
1034
1035 return true;
1036 }
1037
1038 @Override
1039 public int hashCode() {
1040 int result = string.hashCode();
1041 result = 31 * result + uid;
1042 return result;
1043 }
1044 }
1045
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001046 /**
1047 * Optional detailed information that can go into a history step. This is typically
1048 * generated each time the battery level changes.
1049 */
1050 public final static class HistoryStepDetails {
1051 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1052 public int userTime;
1053 public int systemTime;
1054
1055 // Top three apps using CPU in the last step, with times in 1/100 second.
1056 public int appCpuUid1;
1057 public int appCpuUTime1;
1058 public int appCpuSTime1;
1059 public int appCpuUid2;
1060 public int appCpuUTime2;
1061 public int appCpuSTime2;
1062 public int appCpuUid3;
1063 public int appCpuUTime3;
1064 public int appCpuSTime3;
1065
1066 // Information from /proc/stat
1067 public int statUserTime;
1068 public int statSystemTime;
1069 public int statIOWaitTime;
1070 public int statIrqTime;
1071 public int statSoftIrqTime;
1072 public int statIdlTime;
1073
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001074 // Platform-level low power state stats
1075 public String statPlatformIdleState;
1076
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001077 public HistoryStepDetails() {
1078 clear();
1079 }
1080
1081 public void clear() {
1082 userTime = systemTime = 0;
1083 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1084 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1085 = appCpuUTime3 = appCpuSTime3 = 0;
1086 }
1087
1088 public void writeToParcel(Parcel out) {
1089 out.writeInt(userTime);
1090 out.writeInt(systemTime);
1091 out.writeInt(appCpuUid1);
1092 out.writeInt(appCpuUTime1);
1093 out.writeInt(appCpuSTime1);
1094 out.writeInt(appCpuUid2);
1095 out.writeInt(appCpuUTime2);
1096 out.writeInt(appCpuSTime2);
1097 out.writeInt(appCpuUid3);
1098 out.writeInt(appCpuUTime3);
1099 out.writeInt(appCpuSTime3);
1100 out.writeInt(statUserTime);
1101 out.writeInt(statSystemTime);
1102 out.writeInt(statIOWaitTime);
1103 out.writeInt(statIrqTime);
1104 out.writeInt(statSoftIrqTime);
1105 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001106 out.writeString(statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001107 }
1108
1109 public void readFromParcel(Parcel in) {
1110 userTime = in.readInt();
1111 systemTime = in.readInt();
1112 appCpuUid1 = in.readInt();
1113 appCpuUTime1 = in.readInt();
1114 appCpuSTime1 = in.readInt();
1115 appCpuUid2 = in.readInt();
1116 appCpuUTime2 = in.readInt();
1117 appCpuSTime2 = in.readInt();
1118 appCpuUid3 = in.readInt();
1119 appCpuUTime3 = in.readInt();
1120 appCpuSTime3 = in.readInt();
1121 statUserTime = in.readInt();
1122 statSystemTime = in.readInt();
1123 statIOWaitTime = in.readInt();
1124 statIrqTime = in.readInt();
1125 statSoftIrqTime = in.readInt();
1126 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001127 statPlatformIdleState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001128 }
1129 }
1130
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001131 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001132 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001133
1134 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001135 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001136
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001137 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001138 public static final byte CMD_NULL = -1;
1139 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001140 public static final byte CMD_CURRENT_TIME = 5;
1141 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001142 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001143 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001144
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001145 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001146
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001147 /**
1148 * Return whether the command code is a delta data update.
1149 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001150 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001151 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001152 }
1153
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001154 public byte batteryLevel;
1155 public byte batteryStatus;
1156 public byte batteryHealth;
1157 public byte batteryPlugType;
1158
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001159 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001160 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001161
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001162 // The charge of the battery in micro-Ampere-hours.
1163 public int batteryChargeUAh;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001164
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001165 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001166 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001167 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001168 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001169 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1170 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001171 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001172 public static final int STATE_PHONE_STATE_SHIFT = 6;
1173 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001174 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001175 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001176 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001177
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001178 // These states always appear directly in the first int token
1179 // of a delta change; they should be ones that change relatively
1180 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001181 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1182 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001183 public static final int STATE_GPS_ON_FLAG = 1<<29;
1184 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001185 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001186 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001187 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001188 // Do not use, this is used for coulomb delta count.
1189 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001190 // These are on the lower bits used for the command; if they change
1191 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001192 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001193 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001194 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001195 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1196 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1197 // empty slot
1198 // empty slot
1199 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001200
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001201 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001202 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1203
1204 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001205
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001206 public int states;
1207
Dianne Hackborn3251b902014-06-20 14:40:53 -07001208 // Constants from WIFI_SUPPL_STATE_*
1209 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1210 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1211 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1212 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1213 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1214 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1215
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001216 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001217 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1218 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1219 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001220 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001221 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1222 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1223 public static final int STATE2_CHARGING_FLAG = 1<<24;
1224 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1225 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1226 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001227 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001228
1229 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001230 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001231 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1232
1233 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001234
Dianne Hackborn40c87252014-03-19 16:55:40 -07001235 public int states2;
1236
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001237 // The wake lock that was acquired at this point.
1238 public HistoryTag wakelockTag;
1239
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001240 // Kernel wakeup reason at this point.
1241 public HistoryTag wakeReasonTag;
1242
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001243 // Non-null when there is more detailed information at this step.
1244 public HistoryStepDetails stepDetails;
1245
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001246 public static final int EVENT_FLAG_START = 0x8000;
1247 public static final int EVENT_FLAG_FINISH = 0x4000;
1248
1249 // No event in this item.
1250 public static final int EVENT_NONE = 0x0000;
1251 // Event is about a process that is running.
1252 public static final int EVENT_PROC = 0x0001;
1253 // Event is about an application package that is in the foreground.
1254 public static final int EVENT_FOREGROUND = 0x0002;
1255 // Event is about an application package that is at the top of the screen.
1256 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001257 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001258 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001259 // Events for all additional wake locks aquired/release within a wake block.
1260 // These are not generated by default.
1261 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001262 // Event is about an application executing a scheduled job.
1263 public static final int EVENT_JOB = 0x0006;
1264 // Events for users running.
1265 public static final int EVENT_USER_RUNNING = 0x0007;
1266 // Events for foreground user.
1267 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001268 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001269 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001270 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001271 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001272 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001273 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001274 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001275 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001276 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001277 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001278 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001279 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001280 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001281 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001282 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001283 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001284 // Event for a package being on the temporary whitelist.
1285 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001286 // Event for the screen waking up.
1287 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Amith Yamasani67768492015-06-09 12:23:58 -07001288
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001289 // Number of event types.
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001290 public static final int EVENT_COUNT = 0x0013;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001291 // Mask to extract out only the type part of the event.
1292 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001293
1294 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1295 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1296 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1297 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1298 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1299 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001300 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1301 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001302 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1303 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001304 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1305 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1306 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1307 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1308 public static final int EVENT_USER_FOREGROUND_START =
1309 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1310 public static final int EVENT_USER_FOREGROUND_FINISH =
1311 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001312 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1313 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001314 public static final int EVENT_TEMP_WHITELIST_START =
1315 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1316 public static final int EVENT_TEMP_WHITELIST_FINISH =
1317 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001318
1319 // For CMD_EVENT.
1320 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001321 public HistoryTag eventTag;
1322
Dianne Hackborn9a755432014-05-15 17:05:22 -07001323 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001324 public long currentTime;
1325
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001326 // Meta-data when reading.
1327 public int numReadInts;
1328
1329 // Pre-allocated objects.
1330 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001331 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001332 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001333
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001334 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001335 }
1336
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001337 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001338 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001339 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001340 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001341 }
1342
1343 public int describeContents() {
1344 return 0;
1345 }
1346
1347 public void writeToParcel(Parcel dest, int flags) {
1348 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001349 int bat = (((int)cmd)&0xff)
1350 | ((((int)batteryLevel)<<8)&0xff00)
1351 | ((((int)batteryStatus)<<16)&0xf0000)
1352 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001353 | ((((int)batteryPlugType)<<24)&0xf000000)
1354 | (wakelockTag != null ? 0x10000000 : 0)
1355 | (wakeReasonTag != null ? 0x20000000 : 0)
1356 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001357 dest.writeInt(bat);
1358 bat = (((int)batteryTemperature)&0xffff)
1359 | ((((int)batteryVoltage)<<16)&0xffff0000);
1360 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001361 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001362 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001363 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001364 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001365 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001366 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001367 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001368 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001369 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001370 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001371 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001372 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001373 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001374 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001375 dest.writeLong(currentTime);
1376 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001377 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001378
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001379 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001380 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001381 int bat = src.readInt();
1382 cmd = (byte)(bat&0xff);
1383 batteryLevel = (byte)((bat>>8)&0xff);
1384 batteryStatus = (byte)((bat>>16)&0xf);
1385 batteryHealth = (byte)((bat>>20)&0xf);
1386 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001387 int bat2 = src.readInt();
1388 batteryTemperature = (short)(bat2&0xffff);
1389 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001390 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001391 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001392 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001393 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001394 wakelockTag = localWakelockTag;
1395 wakelockTag.readFromParcel(src);
1396 } else {
1397 wakelockTag = null;
1398 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001399 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001400 wakeReasonTag = localWakeReasonTag;
1401 wakeReasonTag.readFromParcel(src);
1402 } else {
1403 wakeReasonTag = null;
1404 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001405 if ((bat&0x40000000) != 0) {
1406 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001407 eventTag = localEventTag;
1408 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001409 } else {
1410 eventCode = EVENT_NONE;
1411 eventTag = null;
1412 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001413 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001414 currentTime = src.readLong();
1415 } else {
1416 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001417 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001418 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001419 }
1420
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001421 public void clear() {
1422 time = 0;
1423 cmd = CMD_NULL;
1424 batteryLevel = 0;
1425 batteryStatus = 0;
1426 batteryHealth = 0;
1427 batteryPlugType = 0;
1428 batteryTemperature = 0;
1429 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001430 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001431 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001432 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001433 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001434 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001435 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001436 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001437 }
1438
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001439 public void setTo(HistoryItem o) {
1440 time = o.time;
1441 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001442 setToCommon(o);
1443 }
1444
1445 public void setTo(long time, byte cmd, HistoryItem o) {
1446 this.time = time;
1447 this.cmd = cmd;
1448 setToCommon(o);
1449 }
1450
1451 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001452 batteryLevel = o.batteryLevel;
1453 batteryStatus = o.batteryStatus;
1454 batteryHealth = o.batteryHealth;
1455 batteryPlugType = o.batteryPlugType;
1456 batteryTemperature = o.batteryTemperature;
1457 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001458 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001459 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001460 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001461 if (o.wakelockTag != null) {
1462 wakelockTag = localWakelockTag;
1463 wakelockTag.setTo(o.wakelockTag);
1464 } else {
1465 wakelockTag = null;
1466 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001467 if (o.wakeReasonTag != null) {
1468 wakeReasonTag = localWakeReasonTag;
1469 wakeReasonTag.setTo(o.wakeReasonTag);
1470 } else {
1471 wakeReasonTag = null;
1472 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001473 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001474 if (o.eventTag != null) {
1475 eventTag = localEventTag;
1476 eventTag.setTo(o.eventTag);
1477 } else {
1478 eventTag = null;
1479 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001480 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001481 }
1482
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001483 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001484 return batteryLevel == o.batteryLevel
1485 && batteryStatus == o.batteryStatus
1486 && batteryHealth == o.batteryHealth
1487 && batteryPlugType == o.batteryPlugType
1488 && batteryTemperature == o.batteryTemperature
1489 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001490 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001491 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001492 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001493 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001494 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001495
1496 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001497 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001498 return false;
1499 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001500 if (wakelockTag != o.wakelockTag) {
1501 if (wakelockTag == null || o.wakelockTag == null) {
1502 return false;
1503 }
1504 if (!wakelockTag.equals(o.wakelockTag)) {
1505 return false;
1506 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001507 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001508 if (wakeReasonTag != o.wakeReasonTag) {
1509 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1510 return false;
1511 }
1512 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1513 return false;
1514 }
1515 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001516 if (eventTag != o.eventTag) {
1517 if (eventTag == null || o.eventTag == null) {
1518 return false;
1519 }
1520 if (!eventTag.equals(o.eventTag)) {
1521 return false;
1522 }
1523 }
1524 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001525 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001526 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001527
1528 public final static class HistoryEventTracker {
1529 private final HashMap<String, SparseIntArray>[] mActiveEvents
1530 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1531
1532 public boolean updateState(int code, String name, int uid, int poolIdx) {
1533 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1534 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1535 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1536 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001537 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001538 mActiveEvents[idx] = active;
1539 }
1540 SparseIntArray uids = active.get(name);
1541 if (uids == null) {
1542 uids = new SparseIntArray();
1543 active.put(name, uids);
1544 }
1545 if (uids.indexOfKey(uid) >= 0) {
1546 // Already set, nothing to do!
1547 return false;
1548 }
1549 uids.put(uid, poolIdx);
1550 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1551 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1552 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1553 if (active == null) {
1554 // not currently active, nothing to do.
1555 return false;
1556 }
1557 SparseIntArray uids = active.get(name);
1558 if (uids == null) {
1559 // not currently active, nothing to do.
1560 return false;
1561 }
1562 idx = uids.indexOfKey(uid);
1563 if (idx < 0) {
1564 // not currently active, nothing to do.
1565 return false;
1566 }
1567 uids.removeAt(idx);
1568 if (uids.size() <= 0) {
1569 active.remove(name);
1570 }
1571 }
1572 return true;
1573 }
1574
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001575 public void removeEvents(int code) {
1576 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1577 mActiveEvents[idx] = null;
1578 }
1579
Dianne Hackborn37de0982014-05-09 09:32:18 -07001580 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1581 return mActiveEvents[code];
1582 }
1583 }
1584
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001585 public static final class BitDescription {
1586 public final int mask;
1587 public final int shift;
1588 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001589 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001590 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001591 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001592
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001593 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001594 this.mask = mask;
1595 this.shift = -1;
1596 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001597 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001598 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001599 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001600 }
1601
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001602 public BitDescription(int mask, int shift, String name, String shortName,
1603 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001604 this.mask = mask;
1605 this.shift = shift;
1606 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001607 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001608 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001609 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001610 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001611 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001612
Dianne Hackbornfc064132014-06-02 12:42:12 -07001613 /**
1614 * Don't allow any more batching in to the current history event. This
1615 * is called when printing partial histories, so to ensure that the next
1616 * history event will go in to a new batch after what was printed in the
1617 * last partial history.
1618 */
1619 public abstract void commitCurrentHistoryBatchLocked();
1620
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001621 public abstract int getHistoryTotalSize();
1622
1623 public abstract int getHistoryUsedSize();
1624
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001625 public abstract boolean startIteratingHistoryLocked();
1626
Dianne Hackborn099bc622014-01-22 13:39:16 -08001627 public abstract int getHistoryStringPoolSize();
1628
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001629 public abstract int getHistoryStringPoolBytes();
1630
1631 public abstract String getHistoryTagPoolString(int index);
1632
1633 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001634
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001635 public abstract boolean getNextHistoryLocked(HistoryItem out);
1636
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001637 public abstract void finishIteratingHistoryLocked();
1638
1639 public abstract boolean startIteratingOldHistoryLocked();
1640
1641 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1642
1643 public abstract void finishIteratingOldHistoryLocked();
1644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001646 * Return the base time offset for the battery history.
1647 */
1648 public abstract long getHistoryBaseTime();
1649
1650 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 * Returns the number of times the device has been started.
1652 */
1653 public abstract int getStartCount();
1654
1655 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001656 * 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 -08001657 * running on battery.
1658 *
1659 * {@hide}
1660 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001661 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001663 /**
1664 * Returns the number of times the screen was turned on.
1665 *
1666 * {@hide}
1667 */
1668 public abstract int getScreenOnCount(int which);
1669
Jeff Browne95c3cd2014-05-02 16:59:26 -07001670 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1671
Dianne Hackborn617f8772009-03-31 15:04:46 -07001672 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1673 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1674 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1675 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1676 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1677
1678 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1679 "dark", "dim", "medium", "light", "bright"
1680 };
1681
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001682 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1683 "0", "1", "2", "3", "4"
1684 };
1685
Dianne Hackborn617f8772009-03-31 15:04:46 -07001686 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001687
Dianne Hackborn617f8772009-03-31 15:04:46 -07001688 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001689 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001690 * the given brightness
1691 *
1692 * {@hide}
1693 */
1694 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001695 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001698 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001699 * running on battery.
1700 *
1701 * {@hide}
1702 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001703 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001704
1705 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001706 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001707 *
1708 * {@hide}
1709 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001710 public abstract int getPowerSaveModeEnabledCount(int which);
1711
1712 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001713 * Constant for device idle mode: not active.
1714 */
1715 public static final int DEVICE_IDLE_MODE_OFF = 0;
1716
1717 /**
1718 * Constant for device idle mode: active in lightweight mode.
1719 */
1720 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1721
1722 /**
1723 * Constant for device idle mode: active in full mode.
1724 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001725 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001726
1727 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001728 * Returns the time in microseconds that device has been in idle mode while
1729 * running on battery.
1730 *
1731 * {@hide}
1732 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001733 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001734
1735 /**
1736 * Returns the number of times that the devie has gone in to idle mode.
1737 *
1738 * {@hide}
1739 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001740 public abstract int getDeviceIdleModeCount(int mode, int which);
1741
1742 /**
1743 * Return the longest duration we spent in a particular device idle mode (fully in the
1744 * mode, not in idle maintenance etc).
1745 */
1746 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001747
1748 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001749 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001750 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001751 * counts all of the time that we consider the device to be idle, whether or not
1752 * it is currently in the actual device idle mode.
1753 *
1754 * {@hide}
1755 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001756 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001757
1758 /**
1759 * Returns the number of times that the devie has started idling.
1760 *
1761 * {@hide}
1762 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001763 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001764
1765 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001766 * Returns the number of times that connectivity state changed.
1767 *
1768 * {@hide}
1769 */
1770 public abstract int getNumConnectivityChange(int which);
1771
1772 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001773 * 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 -08001774 * running on battery.
1775 *
1776 * {@hide}
1777 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001778 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001779
1780 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001781 * Returns the number of times a phone call was activated.
1782 *
1783 * {@hide}
1784 */
1785 public abstract int getPhoneOnCount(int which);
1786
1787 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001788 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001789 * the given signal strength.
1790 *
1791 * {@hide}
1792 */
1793 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001794 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001795
Dianne Hackborn617f8772009-03-31 15:04:46 -07001796 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001797 * Returns the time in microseconds that the phone has been trying to
1798 * acquire a signal.
1799 *
1800 * {@hide}
1801 */
1802 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001803 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001804
1805 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001806 * Returns the number of times the phone has entered the given signal strength.
1807 *
1808 * {@hide}
1809 */
1810 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1811
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001812 /**
1813 * Returns the time in microseconds that the mobile network has been active
1814 * (in a high power state).
1815 *
1816 * {@hide}
1817 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001818 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001819
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001820 /**
1821 * Returns the number of times that the mobile network has transitioned to the
1822 * active state.
1823 *
1824 * {@hide}
1825 */
1826 public abstract int getMobileRadioActiveCount(int which);
1827
1828 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001829 * Returns the time in microseconds that is the difference between the mobile radio
1830 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1831 * from the radio.
1832 *
1833 * {@hide}
1834 */
1835 public abstract long getMobileRadioActiveAdjustedTime(int which);
1836
1837 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001838 * Returns the time in microseconds that the mobile network has been active
1839 * (in a high power state) but not being able to blame on an app.
1840 *
1841 * {@hide}
1842 */
1843 public abstract long getMobileRadioActiveUnknownTime(int which);
1844
1845 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001846 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001847 *
1848 * {@hide}
1849 */
1850 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001851
Dianne Hackborn627bba72009-03-24 22:32:56 -07001852 public static final int DATA_CONNECTION_NONE = 0;
1853 public static final int DATA_CONNECTION_GPRS = 1;
1854 public static final int DATA_CONNECTION_EDGE = 2;
1855 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001856 public static final int DATA_CONNECTION_CDMA = 4;
1857 public static final int DATA_CONNECTION_EVDO_0 = 5;
1858 public static final int DATA_CONNECTION_EVDO_A = 6;
1859 public static final int DATA_CONNECTION_1xRTT = 7;
1860 public static final int DATA_CONNECTION_HSDPA = 8;
1861 public static final int DATA_CONNECTION_HSUPA = 9;
1862 public static final int DATA_CONNECTION_HSPA = 10;
1863 public static final int DATA_CONNECTION_IDEN = 11;
1864 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001865 public static final int DATA_CONNECTION_LTE = 13;
1866 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001867 public static final int DATA_CONNECTION_HSPAP = 15;
1868 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001869
Dianne Hackborn627bba72009-03-24 22:32:56 -07001870 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001871 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001872 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001873 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001874 };
1875
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001876 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001877
1878 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001879 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001880 * the given data connection.
1881 *
1882 * {@hide}
1883 */
1884 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001885 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001888 * Returns the number of times the phone has entered the given data
1889 * connection type.
1890 *
1891 * {@hide}
1892 */
1893 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001894
Dianne Hackborn3251b902014-06-20 14:40:53 -07001895 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1896 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1897 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1898 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1899 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1900 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1901 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1902 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1903 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1904 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1905 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1906 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1907 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1908
1909 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1910
1911 static final String[] WIFI_SUPPL_STATE_NAMES = {
1912 "invalid", "disconn", "disabled", "inactive", "scanning",
1913 "authenticating", "associating", "associated", "4-way-handshake",
1914 "group-handshake", "completed", "dormant", "uninit"
1915 };
1916
1917 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1918 "inv", "dsc", "dis", "inact", "scan",
1919 "auth", "ascing", "asced", "4-way",
1920 "group", "compl", "dorm", "uninit"
1921 };
1922
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001923 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1924 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001925 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001926 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1927 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001928 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001929 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1930 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1931 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001932 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001933 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001934 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001935 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001936 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1937 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001938 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1939 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1940 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1941 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1942 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1943 new String[] {"in", "out", "emergency", "off"},
1944 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001945 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1946 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1947 SignalStrength.SIGNAL_STRENGTH_NAMES,
1948 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001949 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1950 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1951 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001952 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001953
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001954 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1955 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001956 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001957 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001958 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001959 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001960 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001961 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
1962 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
1963 new String[] { "off", "light", "full", "???" },
1964 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001965 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
1966 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
1967 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001968 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1969 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1970 new String[] { "0", "1", "2", "3", "4" },
1971 new String[] { "0", "1", "2", "3", "4" }),
1972 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1973 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1974 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07001975 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001976 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001977 };
1978
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001979 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001980 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001981 "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist",
1982 "screenwake",
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001983 };
1984
1985 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001986 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001987 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
1988 "Esw",
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001989 };
1990
Dianne Hackborn617f8772009-03-31 15:04:46 -07001991 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001992 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001993 * running on battery.
1994 *
1995 * {@hide}
1996 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001997 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001998
1999 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002000 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002001 * been in the running state while the device was running on battery.
2002 *
2003 * {@hide}
2004 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002005 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002006
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002007 public static final int WIFI_STATE_OFF = 0;
2008 public static final int WIFI_STATE_OFF_SCANNING = 1;
2009 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2010 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2011 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2012 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2013 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2014 public static final int WIFI_STATE_SOFT_AP = 7;
2015
2016 static final String[] WIFI_STATE_NAMES = {
2017 "off", "scanning", "no_net", "disconn",
2018 "sta", "p2p", "sta_p2p", "soft_ap"
2019 };
2020
2021 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2022
2023 /**
2024 * Returns the time in microseconds that WiFi has been running in the given state.
2025 *
2026 * {@hide}
2027 */
2028 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002029 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002030
2031 /**
2032 * Returns the number of times that WiFi has entered the given state.
2033 *
2034 * {@hide}
2035 */
2036 public abstract int getWifiStateCount(int wifiState, int which);
2037
The Android Open Source Project10592532009-03-18 17:39:46 -07002038 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002039 * Returns the time in microseconds that the wifi supplicant has been
2040 * in a given state.
2041 *
2042 * {@hide}
2043 */
2044 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2045
2046 /**
2047 * Returns the number of times that the wifi supplicant has transitioned
2048 * to a given state.
2049 *
2050 * {@hide}
2051 */
2052 public abstract int getWifiSupplStateCount(int state, int which);
2053
2054 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2055
2056 /**
2057 * Returns the time in microseconds that WIFI has been running with
2058 * the given signal strength.
2059 *
2060 * {@hide}
2061 */
2062 public abstract long getWifiSignalStrengthTime(int strengthBin,
2063 long elapsedRealtimeUs, int which);
2064
2065 /**
2066 * Returns the number of times WIFI has entered the given signal strength.
2067 *
2068 * {@hide}
2069 */
2070 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2071
2072 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002073 * Returns the time in microseconds that the flashlight has been on while the device was
2074 * running on battery.
2075 *
2076 * {@hide}
2077 */
2078 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2079
2080 /**
2081 * Returns the number of times that the flashlight has been turned on while the device was
2082 * running on battery.
2083 *
2084 * {@hide}
2085 */
2086 public abstract long getFlashlightOnCount(int which);
2087
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002088 /**
2089 * Returns the time in microseconds that the camera has been on while the device was
2090 * running on battery.
2091 *
2092 * {@hide}
2093 */
2094 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2095
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002096 /**
2097 * Returns the time in microseconds that bluetooth scans were running while the device was
2098 * on battery.
2099 *
2100 * {@hide}
2101 */
2102 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002103
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002104 public static final int NETWORK_MOBILE_RX_DATA = 0;
2105 public static final int NETWORK_MOBILE_TX_DATA = 1;
2106 public static final int NETWORK_WIFI_RX_DATA = 2;
2107 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002108 public static final int NETWORK_BT_RX_DATA = 4;
2109 public static final int NETWORK_BT_TX_DATA = 5;
2110 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_BT_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002111
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002112 public abstract long getNetworkActivityBytes(int type, int which);
2113 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002114
Adam Lesinskie08af192015-03-25 16:42:59 -07002115 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002116 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002117 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002118 * actual power data.
2119 */
2120 public abstract boolean hasWifiActivityReporting();
2121
2122 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002123 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2124 * in various radio controller states, such as transmit, receive, and idle.
2125 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002126 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002127 public abstract ControllerActivityCounter getWifiControllerActivity();
2128
2129 /**
2130 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2131 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2132 * actual power data.
2133 */
2134 public abstract boolean hasBluetoothActivityReporting();
2135
2136 /**
2137 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2138 * in various radio controller states, such as transmit, receive, and idle.
2139 * @return non-null {@link ControllerActivityCounter}
2140 */
2141 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2142
2143 /**
2144 * Returns true if the BatteryStats object has detailed modem power reports.
2145 * When true, calling {@link #getModemControllerActivity()} will yield the
2146 * actual power data.
2147 */
2148 public abstract boolean hasModemActivityReporting();
2149
2150 /**
2151 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2152 * in various radio controller states, such as transmit, receive, and idle.
2153 * @return non-null {@link ControllerActivityCounter}
2154 */
2155 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002156
The Android Open Source Project10592532009-03-18 17:39:46 -07002157 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002158 * Return the wall clock time when battery stats data collection started.
2159 */
2160 public abstract long getStartClockTime();
2161
2162 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002163 * Return platform version tag that we were running in when the battery stats started.
2164 */
2165 public abstract String getStartPlatformVersion();
2166
2167 /**
2168 * Return platform version tag that we were running in when the battery stats ended.
2169 */
2170 public abstract String getEndPlatformVersion();
2171
2172 /**
2173 * Return the internal version code of the parcelled format.
2174 */
2175 public abstract int getParcelVersion();
2176
2177 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 * Return whether we are currently running on battery.
2179 */
2180 public abstract boolean getIsOnBattery();
2181
2182 /**
2183 * Returns a SparseArray containing the statistics for each uid.
2184 */
2185 public abstract SparseArray<? extends Uid> getUidStats();
2186
2187 /**
2188 * Returns the current battery uptime in microseconds.
2189 *
2190 * @param curTime the amount of elapsed realtime in microseconds.
2191 */
2192 public abstract long getBatteryUptime(long curTime);
2193
2194 /**
2195 * Returns the current battery realtime in microseconds.
2196 *
2197 * @param curTime the amount of elapsed realtime in microseconds.
2198 */
2199 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07002200
2201 /**
Evan Millar633a1742009-04-02 16:36:33 -07002202 * Returns the battery percentage level at the last time the device was unplugged from power, or
2203 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002204 */
Evan Millar633a1742009-04-02 16:36:33 -07002205 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07002206
2207 /**
Evan Millar633a1742009-04-02 16:36:33 -07002208 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2209 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002210 */
Evan Millar633a1742009-04-02 16:36:33 -07002211 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002212
2213 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002214 * Get the amount the battery has discharged since the stats were
2215 * last reset after charging, as a lower-end approximation.
2216 */
2217 public abstract int getLowDischargeAmountSinceCharge();
2218
2219 /**
2220 * Get the amount the battery has discharged since the stats were
2221 * last reset after charging, as an upper-end approximation.
2222 */
2223 public abstract int getHighDischargeAmountSinceCharge();
2224
2225 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002226 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2227 */
2228 public abstract int getDischargeAmount(int which);
2229
2230 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002231 * Get the amount the battery has discharged while the screen was on,
2232 * since the last time power was unplugged.
2233 */
2234 public abstract int getDischargeAmountScreenOn();
2235
2236 /**
2237 * Get the amount the battery has discharged while the screen was on,
2238 * since the last time the device was charged.
2239 */
2240 public abstract int getDischargeAmountScreenOnSinceCharge();
2241
2242 /**
2243 * Get the amount the battery has discharged while the screen was off,
2244 * since the last time power was unplugged.
2245 */
2246 public abstract int getDischargeAmountScreenOff();
2247
2248 /**
2249 * Get the amount the battery has discharged while the screen was off,
2250 * since the last time the device was charged.
2251 */
2252 public abstract int getDischargeAmountScreenOffSinceCharge();
2253
2254 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 * Returns the total, last, or current battery uptime in microseconds.
2256 *
2257 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002258 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259 */
2260 public abstract long computeBatteryUptime(long curTime, int which);
2261
2262 /**
2263 * Returns the total, last, or current battery realtime in microseconds.
2264 *
2265 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002266 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 */
2268 public abstract long computeBatteryRealtime(long curTime, int which);
2269
2270 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002271 * Returns the total, last, or current battery screen off uptime in microseconds.
2272 *
2273 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002274 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002275 */
2276 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2277
2278 /**
2279 * Returns the total, last, or current battery screen off realtime in microseconds.
2280 *
2281 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002282 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002283 */
2284 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2285
2286 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 * Returns the total, last, or current uptime in microseconds.
2288 *
2289 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002290 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 */
2292 public abstract long computeUptime(long curTime, int which);
2293
2294 /**
2295 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002296 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002298 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002299 */
2300 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002301
2302 /**
2303 * Compute an approximation for how much run time (in microseconds) is remaining on
2304 * the battery. Returns -1 if no time can be computed: either there is not
2305 * enough current data to make a decision, or the battery is currently
2306 * charging.
2307 *
2308 * @param curTime The current elepsed realtime in microseconds.
2309 */
2310 public abstract long computeBatteryTimeRemaining(long curTime);
2311
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002312 // The part of a step duration that is the actual time.
2313 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2314
2315 // Bits in a step duration that are the new battery level we are at.
2316 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002317 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002318
2319 // Bits in a step duration that are the initial mode we were in at that step.
2320 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002321 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002322
2323 // Bits in a step duration that indicate which modes changed during that step.
2324 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002325 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002326
2327 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2328 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2329
2330 // Step duration mode: power save is on.
2331 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2332
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002333 // Step duration mode: device is currently in idle mode.
2334 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2335
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002336 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2337 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002338 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2339 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002340 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2341 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2342 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2343 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2344 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002345 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2346 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002347 };
2348 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2349 (Display.STATE_OFF-1),
2350 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002351 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002352 (Display.STATE_ON-1),
2353 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2354 (Display.STATE_DOZE-1),
2355 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2356 (Display.STATE_DOZE_SUSPEND-1),
2357 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002358 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002359 };
2360 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2361 "screen off",
2362 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002363 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002364 "screen on",
2365 "screen on power save",
2366 "screen doze",
2367 "screen doze power save",
2368 "screen doze-suspend",
2369 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002370 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002371 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002372
2373 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002374 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2375 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2376 * a coulomb counter.
2377 */
2378 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2379
2380 /**
2381 * Return the counter keeping track of the amount of battery discharge measured in
2382 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2383 * a coulomb counter.
2384 */
2385 public abstract LongCounter getDischargeCoulombCounter();
2386
2387 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002388 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002389 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002390 public abstract LevelStepTracker getDischargeLevelStepTracker();
2391
2392 /**
2393 * Return the array of daily discharge step durations.
2394 */
2395 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002396
2397 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002398 * Compute an approximation for how much time (in microseconds) remains until the battery
2399 * is fully charged. Returns -1 if no time can be computed: either there is not
2400 * enough current data to make a decision, or the battery is currently
2401 * discharging.
2402 *
2403 * @param curTime The current elepsed realtime in microseconds.
2404 */
2405 public abstract long computeChargeTimeRemaining(long curTime);
2406
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002407 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002408 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002409 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002410 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002411
2412 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002413 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002414 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002415 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002416
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002417 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2418
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002419 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002420
Evan Millarc64edde2009-04-18 12:26:32 -07002421 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002423 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2424
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002425 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 long days = seconds / (60 * 60 * 24);
2427 if (days != 0) {
2428 out.append(days);
2429 out.append("d ");
2430 }
2431 long used = days * 60 * 60 * 24;
2432
2433 long hours = (seconds - used) / (60 * 60);
2434 if (hours != 0 || used != 0) {
2435 out.append(hours);
2436 out.append("h ");
2437 }
2438 used += hours * 60 * 60;
2439
2440 long mins = (seconds-used) / 60;
2441 if (mins != 0 || used != 0) {
2442 out.append(mins);
2443 out.append("m ");
2444 }
2445 used += mins * 60;
2446
2447 if (seconds != 0 || used != 0) {
2448 out.append(seconds-used);
2449 out.append("s ");
2450 }
2451 }
2452
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002453 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002454 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002455 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 sb.append(time - (sec * 1000));
2457 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 }
2459
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002460 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002461 long sec = time / 1000;
2462 formatTimeRaw(sb, sec);
2463 sb.append(time - (sec * 1000));
2464 sb.append("ms");
2465 }
2466
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002467 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002468 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002469 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002470 }
2471 float perc = ((float)num) / ((float)den) * 100;
2472 mFormatBuilder.setLength(0);
2473 mFormatter.format("%.1f%%", perc);
2474 return mFormatBuilder.toString();
2475 }
2476
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002477 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002478 mFormatBuilder.setLength(0);
2479
2480 if (bytes < BYTES_PER_KB) {
2481 return bytes + "B";
2482 } else if (bytes < BYTES_PER_MB) {
2483 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2484 return mFormatBuilder.toString();
2485 } else if (bytes < BYTES_PER_GB){
2486 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2487 return mFormatBuilder.toString();
2488 } else {
2489 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2490 return mFormatBuilder.toString();
2491 }
2492 }
2493
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002494 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002495 if (timer != null) {
2496 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002497 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002498 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2499 return totalTimeMillis;
2500 }
2501 return 0;
2502 }
2503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 /**
2505 *
2506 * @param sb a StringBuilder object.
2507 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002508 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002509 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002510 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 * @param linePrefix a String to be prepended to each line of output.
2512 * @return the line prefix
2513 */
2514 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002515 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002518 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002519
Evan Millarc64edde2009-04-18 12:26:32 -07002520 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 if (totalTimeMillis != 0) {
2522 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002523 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002524 if (name != null) {
2525 sb.append(name);
2526 sb.append(' ');
2527 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 sb.append('(');
2529 sb.append(count);
2530 sb.append(" times)");
2531 return ", ";
2532 }
2533 }
2534 return linePrefix;
2535 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002536
2537 /**
2538 *
2539 * @param pw a PrintWriter object to print to.
2540 * @param sb a StringBuilder object.
2541 * @param timer a Timer object contining the wakelock times.
2542 * @param rawRealtime the current on-battery time in microseconds.
2543 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2544 * @param prefix a String to be prepended to each line of output.
2545 * @param type the name of the timer.
2546 */
2547 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
2548 long rawRealtime, int which, String prefix, String type) {
2549 if (timer != null) {
2550 // Convert from microseconds to milliseconds with rounding
2551 final long totalTime = (timer.getTotalTimeLocked(
2552 rawRealtime, which) + 500) / 1000;
2553 final int count = timer.getCountLocked(which);
2554 if (totalTime != 0) {
2555 sb.setLength(0);
2556 sb.append(prefix);
2557 sb.append(" ");
2558 sb.append(type);
2559 sb.append(": ");
2560 formatTimeMs(sb, totalTime);
2561 sb.append("realtime (");
2562 sb.append(count);
2563 sb.append(" times)");
2564 pw.println(sb.toString());
2565 return true;
2566 }
2567 }
2568 return false;
2569 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570
2571 /**
2572 * Checkin version of wakelock printer. Prints simple comma-separated list.
2573 *
2574 * @param sb a StringBuilder object.
2575 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002576 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002578 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 * @param linePrefix a String to be prepended to each line of output.
2580 * @return the line prefix
2581 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002582 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2583 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002584 long totalTimeMicros = 0;
2585 int count = 0;
2586 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002587 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002588 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 }
2590 sb.append(linePrefix);
2591 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2592 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002593 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 sb.append(count);
2595 return ",";
2596 }
2597
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002598 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2599 String type) {
2600 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2601 pw.print(',');
2602 pw.print(uid);
2603 pw.print(',');
2604 pw.print(category);
2605 pw.print(',');
2606 pw.print(type);
2607 }
2608
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 /**
2610 * Dump a comma-separated line of values for terse checkin mode.
2611 *
2612 * @param pw the PageWriter to dump log to
2613 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2614 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2615 * @param args type-dependent data arguments
2616 */
2617 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2618 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002619 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002620 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002621 pw.print(',');
2622 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002624 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002626
2627 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002628 * Dump a given timer stat for terse checkin mode.
2629 *
2630 * @param pw the PageWriter to dump log to
2631 * @param uid the UID to log
2632 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2633 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2634 * @param timer a {@link Timer} to dump stats for
2635 * @param rawRealtime the current elapsed realtime of the system in microseconds
2636 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2637 */
2638 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2639 Timer timer, long rawRealtime, int which) {
2640 if (timer != null) {
2641 // Convert from microseconds to milliseconds with rounding
2642 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2643 / 1000;
2644 final int count = timer.getCountLocked(which);
2645 if (totalTime != 0) {
2646 dumpLine(pw, uid, category, type, totalTime, count);
2647 }
2648 }
2649 }
2650
2651 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002652 * Checks if the ControllerActivityCounter has any data worth dumping.
2653 */
2654 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2655 if (counter == null) {
2656 return false;
2657 }
2658
2659 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2660 || counter.getRxTimeCounter().getCountLocked(which) != 0
2661 || counter.getPowerCounter().getCountLocked(which) != 0) {
2662 return true;
2663 }
2664
2665 for (LongCounter c : counter.getTxTimeCounters()) {
2666 if (c.getCountLocked(which) != 0) {
2667 return true;
2668 }
2669 }
2670 return false;
2671 }
2672
2673 /**
2674 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2675 * The order of the arguments in the final check in line is:
2676 *
2677 * idle, rx, power, tx...
2678 *
2679 * where tx... is one or more transmit level times.
2680 */
2681 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2682 String type,
2683 ControllerActivityCounter counter,
2684 int which) {
2685 if (!controllerActivityHasData(counter, which)) {
2686 return;
2687 }
2688
2689 dumpLineHeader(pw, uid, category, type);
2690 pw.print(",");
2691 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2692 pw.print(",");
2693 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2694 pw.print(",");
2695 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2696 for (LongCounter c : counter.getTxTimeCounters()) {
2697 pw.print(",");
2698 pw.print(c.getCountLocked(which));
2699 }
2700 pw.println();
2701 }
2702
2703 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2704 String prefix, String controllerName,
2705 ControllerActivityCounter counter,
2706 int which) {
2707 if (controllerActivityHasData(counter, which)) {
2708 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2709 }
2710 }
2711
2712 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2713 String controllerName,
2714 ControllerActivityCounter counter, int which) {
2715 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2716 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2717 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2718 long totalTxTimeMs = 0;
2719 for (LongCounter txState : counter.getTxTimeCounters()) {
2720 totalTxTimeMs += txState.getCountLocked(which);
2721 }
2722
2723 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2724
2725 sb.setLength(0);
2726 sb.append(prefix);
2727 sb.append(" ");
2728 sb.append(controllerName);
2729 sb.append(" Idle time: ");
2730 formatTimeMs(sb, idleTimeMs);
2731 sb.append("(");
2732 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2733 sb.append(")");
2734 pw.println(sb.toString());
2735
2736 sb.setLength(0);
2737 sb.append(prefix);
2738 sb.append(" ");
2739 sb.append(controllerName);
2740 sb.append(" Rx time: ");
2741 formatTimeMs(sb, rxTimeMs);
2742 sb.append("(");
2743 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
2744 sb.append(")");
2745 pw.println(sb.toString());
2746
2747 sb.setLength(0);
2748 sb.append(prefix);
2749 sb.append(" ");
2750 sb.append(controllerName);
2751 sb.append(" Tx time: ");
2752 formatTimeMs(sb, totalTxTimeMs);
2753 sb.append("(");
2754 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
2755 sb.append(")");
2756 pw.println(sb.toString());
2757
2758 final int numTxLvls = counter.getTxTimeCounters().length;
2759 if (numTxLvls > 1) {
2760 for (int lvl = 0; lvl < numTxLvls; lvl++) {
2761 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
2762 sb.setLength(0);
2763 sb.append(prefix);
2764 sb.append(" [");
2765 sb.append(lvl);
2766 sb.append("] ");
2767 formatTimeMs(sb, txLvlTimeMs);
2768 sb.append("(");
2769 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
2770 sb.append(")");
2771 pw.println(sb.toString());
2772 }
2773 }
2774
2775 sb.setLength(0);
2776 sb.append(prefix);
2777 sb.append(" ");
2778 sb.append(controllerName);
2779 sb.append(" Power drain: ").append(
2780 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
2781 sb.append("mAh");
2782 pw.println(sb.toString());
2783 }
2784
2785 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07002786 * Temporary for settings.
2787 */
2788 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2789 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2790 }
2791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002792 /**
2793 * Checkin server version of dump to produce more compact, computer-readable log.
2794 *
2795 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002797 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2798 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002799 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2800 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2801 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2803 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002804 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2805 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2806 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 final long totalRealtime = computeRealtime(rawRealtime, which);
2808 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002809 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002810 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002811 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002812 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
2813 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002814 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002815 rawRealtime, which);
2816 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
2817 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002818 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002819 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002820 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002821 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002822 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
2823 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
2824 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002825
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002826 final StringBuilder sb = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002828 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07002829 final int NU = uidStats.size();
2830
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002831 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002832
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 // Dump "battery" stat
2834 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002835 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002836 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002837 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002838 getStartClockTime(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07002839 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
2840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002842 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002843 long fullWakeLockTimeTotal = 0;
2844 long partialWakeLockTimeTotal = 0;
2845
2846 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002847 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002848
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002849 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
2850 = u.getWakelockStats();
2851 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2852 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07002853
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002854 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2855 if (fullWakeTimer != null) {
2856 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2857 which);
2858 }
2859
2860 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2861 if (partialWakeTimer != null) {
2862 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
2863 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002864 }
2865 }
2866 }
Adam Lesinskie283d332015-04-16 12:29:25 -07002867
2868 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002869 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2870 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2871 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2872 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2873 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2874 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2875 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2876 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002877 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
2878 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002879 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2880 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002881 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
2882 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002883
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002884 // Dump Modem controller stats
2885 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
2886 getModemControllerActivity(), which);
2887
Adam Lesinskie283d332015-04-16 12:29:25 -07002888 // Dump Wifi controller stats
2889 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2890 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002891 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08002892 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002893
2894 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
2895 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002896
2897 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002898 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
2899 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002900
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002901 // Dump misc stats
2902 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07002903 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002904 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07002905 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002906 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002907 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002908 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
2909 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07002910 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002911 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
2912 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
2913 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
2914 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002915 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002916
2917 // Dump screen brightness stats
2918 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2919 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002920 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002921 }
2922 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002923
Dianne Hackborn627bba72009-03-24 22:32:56 -07002924 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002925 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2926 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002927 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002928 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002929 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002930 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002931 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002932 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002933 args[i] = getPhoneSignalStrengthCount(i, which);
2934 }
2935 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002936
Dianne Hackborn627bba72009-03-24 22:32:56 -07002937 // Dump network type stats
2938 args = new Object[NUM_DATA_CONNECTION_TYPES];
2939 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002940 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002941 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002942 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2943 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2944 args[i] = getPhoneDataConnectionCount(i, which);
2945 }
2946 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002947
2948 // Dump wifi state stats
2949 args = new Object[NUM_WIFI_STATES];
2950 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002951 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002952 }
2953 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2954 for (int i=0; i<NUM_WIFI_STATES; i++) {
2955 args[i] = getWifiStateCount(i, which);
2956 }
2957 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2958
Dianne Hackborn3251b902014-06-20 14:40:53 -07002959 // Dump wifi suppl state stats
2960 args = new Object[NUM_WIFI_SUPPL_STATES];
2961 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2962 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2963 }
2964 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2965 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2966 args[i] = getWifiSupplStateCount(i, which);
2967 }
2968 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
2969
2970 // Dump wifi signal strength stats
2971 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
2972 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2973 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
2974 }
2975 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
2976 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2977 args[i] = getWifiSignalStrengthCount(i, which);
2978 }
2979 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
2980
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002981 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002982 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07002983 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002984 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002985
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002986 if (which == STATS_SINCE_UNPLUGGED) {
2987 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2988 getDischargeStartLevel()-getDischargeCurrentLevel(),
2989 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07002990 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
2991 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002992 } else {
2993 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2994 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002995 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07002996 getDischargeAmountScreenOffSinceCharge(),
2997 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002998 }
2999
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003000 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003001 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003002 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003003 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003004 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003005 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003006 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003007 sb.toString());
3008 }
Evan Millarc64edde2009-04-18 12:26:32 -07003009 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003010 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003011 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003012 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3013 // Not doing the regular wake lock formatting to remain compatible
3014 // with the old checkin format.
3015 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3016 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003017 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003018 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003019 }
3020 }
Evan Millarc64edde2009-04-18 12:26:32 -07003021 }
3022
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003023 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003024 helper.create(this);
3025 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003026 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003027 if (sippers != null && sippers.size() > 0) {
3028 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3029 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003030 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003031 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3032 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3033 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003034 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003035 int uid = 0;
3036 String label;
3037 switch (bs.drainType) {
3038 case IDLE:
3039 label="idle";
3040 break;
3041 case CELL:
3042 label="cell";
3043 break;
3044 case PHONE:
3045 label="phone";
3046 break;
3047 case WIFI:
3048 label="wifi";
3049 break;
3050 case BLUETOOTH:
3051 label="blue";
3052 break;
3053 case SCREEN:
3054 label="scrn";
3055 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003056 case FLASHLIGHT:
3057 label="flashlight";
3058 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003059 case APP:
3060 uid = bs.uidObj.getUid();
3061 label = "uid";
3062 break;
3063 case USER:
3064 uid = UserHandle.getUid(bs.userId, 0);
3065 label = "user";
3066 break;
3067 case UNACCOUNTED:
3068 label = "unacc";
3069 break;
3070 case OVERCOUNTED:
3071 label = "over";
3072 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003073 case CAMERA:
3074 label = "camera";
3075 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003076 default:
3077 label = "???";
3078 }
3079 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07003080 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003081 }
3082 }
3083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 for (int iu = 0; iu < NU; iu++) {
3085 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003086 if (reqUid >= 0 && uid != reqUid) {
3087 continue;
3088 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003089 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003091 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003092 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3093 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3094 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3095 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3096 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3097 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3098 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3099 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
3100 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3101 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003102 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3103 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003104 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3105 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003106 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
3107 || btBytesRx > 0 || btBytesTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003108 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3109 wifiBytesRx, wifiBytesTx,
3110 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003111 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003112 mobileActiveTime, mobileActiveCount,
3113 btBytesRx, btBytesTx);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003114 }
3115
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003116 // Dump modem controller data, per UID.
3117 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3118 u.getModemControllerActivity(), which);
3119
3120 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003121 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3122 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3123 final int wifiScanCount = u.getWifiScanCount(which);
3124 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003125 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003126 || uidWifiRunningTime != 0) {
3127 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3128 uidWifiRunningTime, wifiScanCount,
Kweku Adams5b2747e2016-04-25 10:44:05 -07003129 /* legacy fields follow, keep at 0 */ 0, 0, 0);
The Android Open Source Project10592532009-03-18 17:39:46 -07003130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003132 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3133 u.getWifiControllerActivity(), which);
3134
Adam Lesinskiba9d8932016-04-12 12:06:03 -07003135 dumpTimer(pw, uid, category, BLUETOOTH_MISC_DATA, u.getBluetoothScanTimer(),
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003136 rawRealtime, which);
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003137
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003138 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3139 u.getBluetoothControllerActivity(), which);
3140
Dianne Hackborn617f8772009-03-31 15:04:46 -07003141 if (u.hasUserActivity()) {
3142 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3143 boolean hasData = false;
3144 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3145 int val = u.getUserActivityCount(i, which);
3146 args[i] = val;
3147 if (val != 0) hasData = true;
3148 }
3149 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003150 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003151 }
3152 }
3153
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003154 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3155 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3156 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3157 String linePrefix = "";
3158 sb.setLength(0);
3159 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3160 rawRealtime, "f", which, linePrefix);
3161 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
3162 rawRealtime, "p", which, linePrefix);
3163 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3164 rawRealtime, "w", which, linePrefix);
3165
3166 // Only log if we had at lease one wakelock...
3167 if (sb.length() > 0) {
3168 String name = wakelocks.keyAt(iw);
3169 if (name.indexOf(',') >= 0) {
3170 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003171 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003172 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003173 }
3174 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003175
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003176 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3177 for (int isy=syncs.size()-1; isy>=0; isy--) {
3178 final Timer timer = syncs.valueAt(isy);
3179 // Convert from microseconds to milliseconds with rounding
3180 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3181 final int count = timer.getCountLocked(which);
3182 if (totalTime != 0) {
3183 dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003184 }
3185 }
3186
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003187 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3188 for (int ij=jobs.size()-1; ij>=0; ij--) {
3189 final Timer timer = jobs.valueAt(ij);
3190 // Convert from microseconds to milliseconds with rounding
3191 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3192 final int count = timer.getCountLocked(which);
3193 if (totalTime != 0) {
3194 dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003195 }
3196 }
3197
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003198 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3199 rawRealtime, which);
3200 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3201 rawRealtime, which);
3202 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3203 rawRealtime, which);
3204 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3205 rawRealtime, which);
3206
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003207 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3208 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003209 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003210 final Uid.Sensor se = sensors.valueAt(ise);
3211 final int sensorNumber = sensors.keyAt(ise);
3212 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003213 if (timer != null) {
3214 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003215 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3216 / 1000;
3217 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003218 if (totalTime != 0) {
3219 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
3220 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 }
3222 }
3223
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003224 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3225 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003226
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003227 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3228 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003229
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003230 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003231 long totalStateTime = 0;
3232 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003233 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3234 totalStateTime += time;
3235 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003236 }
3237 if (totalStateTime > 0) {
3238 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3239 }
3240
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003241 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3242 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
3243 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
3244 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
3245 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
3246 powerCpuMaUs / 1000);
3247 }
3248
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003249 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3250 = u.getProcessStats();
3251 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3252 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003253
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003254 final long userMillis = ps.getUserTime(which);
3255 final long systemMillis = ps.getSystemTime(which);
3256 final long foregroundMillis = ps.getForegroundTime(which);
3257 final int starts = ps.getStarts(which);
3258 final int numCrashes = ps.getNumCrashes(which);
3259 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003260
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003261 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3262 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
3263 dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis,
3264 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 }
3266 }
3267
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003268 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3269 = u.getPackageStats();
3270 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3271 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3272 int wakeups = 0;
3273 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3274 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003275 int count = alarms.valueAt(iwa).getCountLocked(which);
3276 wakeups += count;
3277 String name = alarms.keyAt(iwa).replace(',', '_');
3278 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003279 }
3280 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3281 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3282 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3283 final long startTime = ss.getStartTime(batteryUptime, which);
3284 final int starts = ss.getStarts(which);
3285 final int launches = ss.getLaunches(which);
3286 if (startTime != 0 || starts != 0 || launches != 0) {
3287 dumpLine(pw, uid, category, APK_DATA,
3288 wakeups, // wakeup alarms
3289 packageStats.keyAt(ipkg), // Apk
3290 serviceStats.keyAt(isvc), // service
3291 startTime / 1000, // time spent started, in ms
3292 starts,
3293 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003294 }
3295 }
3296 }
3297 }
3298 }
3299
Dianne Hackborn81038902012-11-26 17:04:09 -08003300 static final class TimerEntry {
3301 final String mName;
3302 final int mId;
3303 final BatteryStats.Timer mTimer;
3304 final long mTime;
3305 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3306 mName = name;
3307 mId = id;
3308 mTimer = timer;
3309 mTime = time;
3310 }
3311 }
3312
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003313 private void printmAh(PrintWriter printer, double power) {
3314 printer.print(BatteryStatsHelper.makemAh(power));
3315 }
3316
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003317 private void printmAh(StringBuilder sb, double power) {
3318 sb.append(BatteryStatsHelper.makemAh(power));
3319 }
3320
Dianne Hackbornd953c532014-08-16 18:17:38 -07003321 /**
3322 * Temporary for settings.
3323 */
3324 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3325 int reqUid) {
3326 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3327 }
3328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003329 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003330 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003331 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3333 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3334 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335
3336 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3337 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3338 final long totalRealtime = computeRealtime(rawRealtime, which);
3339 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003340 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3341 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3342 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003343 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3344 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003345
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003346 final StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07003347
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003348 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003349 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003351 sb.setLength(0);
3352 sb.append(prefix);
3353 sb.append(" Time on battery: ");
3354 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3355 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3356 sb.append(") realtime, ");
3357 formatTimeMs(sb, whichBatteryUptime / 1000);
3358 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3359 sb.append(") uptime");
3360 pw.println(sb.toString());
3361 sb.setLength(0);
3362 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003363 sb.append(" Time on battery screen off: ");
3364 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3365 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3366 sb.append(") realtime, ");
3367 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3368 sb.append("(");
3369 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3370 sb.append(") uptime");
3371 pw.println(sb.toString());
3372 sb.setLength(0);
3373 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003374 sb.append(" Total run time: ");
3375 formatTimeMs(sb, totalRealtime / 1000);
3376 sb.append("realtime, ");
3377 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003378 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003379 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003380 if (batteryTimeRemaining >= 0) {
3381 sb.setLength(0);
3382 sb.append(prefix);
3383 sb.append(" Battery time remaining: ");
3384 formatTimeMs(sb, batteryTimeRemaining / 1000);
3385 pw.println(sb.toString());
3386 }
3387 if (chargeTimeRemaining >= 0) {
3388 sb.setLength(0);
3389 sb.append(prefix);
3390 sb.append(" Charge time remaining: ");
3391 formatTimeMs(sb, chargeTimeRemaining / 1000);
3392 pw.println(sb.toString());
3393 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003394
3395 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3396 final long dischargeCount = dischargeCounter.getCountLocked(which);
3397 if (dischargeCount >= 0) {
3398 sb.setLength(0);
3399 sb.append(prefix);
3400 sb.append(" Discharge: ");
3401 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3402 sb.append(" mAh");
3403 pw.println(sb.toString());
3404 }
3405
3406 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3407 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3408 if (dischargeScreenOffCount >= 0) {
3409 sb.setLength(0);
3410 sb.append(prefix);
3411 sb.append(" Screen off discharge: ");
3412 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3413 sb.append(" mAh");
3414 pw.println(sb.toString());
3415 }
3416
3417 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3418 if (dischargeScreenOnCount >= 0) {
3419 sb.setLength(0);
3420 sb.append(prefix);
3421 sb.append(" Screen on discharge: ");
3422 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3423 sb.append(" mAh");
3424 pw.println(sb.toString());
3425 }
3426
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003427 pw.print(" Start clock time: ");
3428 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3429
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003430 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003431 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003432 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003433 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3434 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003435 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003436 rawRealtime, which);
3437 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3438 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003439 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003440 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003441 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3442 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3443 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003444 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003445 sb.append(prefix);
3446 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3447 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003448 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003449 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3450 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003451 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003452 pw.println(sb.toString());
3453 sb.setLength(0);
3454 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003455 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003456 boolean didOne = false;
3457 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003458 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003459 if (time == 0) {
3460 continue;
3461 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003462 sb.append("\n ");
3463 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003464 didOne = true;
3465 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3466 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003467 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003468 sb.append("(");
3469 sb.append(formatRatioLocked(time, screenOnTime));
3470 sb.append(")");
3471 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003472 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003473 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003474 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003475 sb.setLength(0);
3476 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003477 sb.append(" Power save mode enabled: ");
3478 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003479 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003480 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003481 sb.append(")");
3482 pw.println(sb.toString());
3483 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003484 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003485 sb.setLength(0);
3486 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003487 sb.append(" Device light idling: ");
3488 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003489 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003490 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3491 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003492 sb.append("x");
3493 pw.println(sb.toString());
3494 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003495 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003496 sb.setLength(0);
3497 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003498 sb.append(" Idle mode light time: ");
3499 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003500 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003501 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3502 sb.append(") ");
3503 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003504 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003505 sb.append(" -- longest ");
3506 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3507 pw.println(sb.toString());
3508 }
3509 if (deviceIdlingTime != 0) {
3510 sb.setLength(0);
3511 sb.append(prefix);
3512 sb.append(" Device full idling: ");
3513 formatTimeMs(sb, deviceIdlingTime / 1000);
3514 sb.append("(");
3515 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003516 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003517 sb.append("x");
3518 pw.println(sb.toString());
3519 }
3520 if (deviceIdleModeFullTime != 0) {
3521 sb.setLength(0);
3522 sb.append(prefix);
3523 sb.append(" Idle mode full time: ");
3524 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3525 sb.append("(");
3526 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3527 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003528 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003529 sb.append("x");
3530 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003531 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003532 pw.println(sb.toString());
3533 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003534 if (phoneOnTime != 0) {
3535 sb.setLength(0);
3536 sb.append(prefix);
3537 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3538 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003539 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003540 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003541 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003542 if (connChanges != 0) {
3543 pw.print(prefix);
3544 pw.print(" Connectivity changes: "); pw.println(connChanges);
3545 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003546
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003547 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003548 long fullWakeLockTimeTotalMicros = 0;
3549 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003550
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003551 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003552
Evan Millar22ac0432009-03-31 11:33:18 -07003553 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003554 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003555
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003556 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3557 = u.getWakelockStats();
3558 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3559 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003560
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003561 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3562 if (fullWakeTimer != null) {
3563 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3564 rawRealtime, which);
3565 }
3566
3567 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3568 if (partialWakeTimer != null) {
3569 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3570 rawRealtime, which);
3571 if (totalTimeMicros > 0) {
3572 if (reqUid < 0) {
3573 // Only show the ordered list of all wake
3574 // locks if the caller is not asking for data
3575 // about a specific uid.
3576 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3577 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003578 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003579 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003580 }
3581 }
3582 }
3583 }
3584
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003585 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3586 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3587 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3588 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3589 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3590 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3591 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3592 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08003593 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3594 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003595
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003596 if (fullWakeLockTimeTotalMicros != 0) {
3597 sb.setLength(0);
3598 sb.append(prefix);
3599 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3600 (fullWakeLockTimeTotalMicros + 500) / 1000);
3601 pw.println(sb.toString());
3602 }
3603
3604 if (partialWakeLockTimeTotalMicros != 0) {
3605 sb.setLength(0);
3606 sb.append(prefix);
3607 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3608 (partialWakeLockTimeTotalMicros + 500) / 1000);
3609 pw.println(sb.toString());
3610 }
3611
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003612 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003613 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3614 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3615 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3616 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003617 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003618 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003619 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003620 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003621 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003622 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003623 if (time == 0) {
3624 continue;
3625 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003626 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003627 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003628 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003629 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003630 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003631 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003632 sb.append("(");
3633 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003634 sb.append(") ");
3635 sb.append(getPhoneSignalStrengthCount(i, which));
3636 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003637 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003638 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003639 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003640
3641 sb.setLength(0);
3642 sb.append(prefix);
3643 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003644 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003645 pw.println(sb.toString());
3646
Dianne Hackborn627bba72009-03-24 22:32:56 -07003647 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003648 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003649 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003650 didOne = false;
3651 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003652 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003653 if (time == 0) {
3654 continue;
3655 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003656 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003657 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003658 didOne = true;
3659 sb.append(DATA_CONNECTION_NAMES[i]);
3660 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003661 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003662 sb.append("(");
3663 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003664 sb.append(") ");
3665 sb.append(getPhoneDataConnectionCount(i, which));
3666 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003667 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003668 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003669 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003670
3671 sb.setLength(0);
3672 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003673 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003674 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003675 formatTimeMs(sb, mobileActiveTime / 1000);
3676 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3677 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3678 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003679 pw.println(sb.toString());
3680
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003681 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3682 if (mobileActiveUnknownTime != 0) {
3683 sb.setLength(0);
3684 sb.append(prefix);
3685 sb.append(" Mobile radio active unknown time: ");
3686 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3687 sb.append("(");
3688 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3689 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3690 sb.append("x");
3691 pw.println(sb.toString());
3692 }
3693
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003694 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3695 if (mobileActiveAdjustedTime != 0) {
3696 sb.setLength(0);
3697 sb.append(prefix);
3698 sb.append(" Mobile radio active adjusted time: ");
3699 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3700 sb.append("(");
3701 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3702 sb.append(")");
3703 pw.println(sb.toString());
3704 }
3705
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003706 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
3707
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003708 pw.print(prefix);
3709 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3710 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3711 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3712 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003713 sb.setLength(0);
3714 sb.append(prefix);
3715 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3716 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3717 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3718 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003719 sb.append(")");
3720 pw.println(sb.toString());
3721
3722 sb.setLength(0);
3723 sb.append(prefix);
3724 sb.append(" Wifi states:");
3725 didOne = false;
3726 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003727 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003728 if (time == 0) {
3729 continue;
3730 }
3731 sb.append("\n ");
3732 didOne = true;
3733 sb.append(WIFI_STATE_NAMES[i]);
3734 sb.append(" ");
3735 formatTimeMs(sb, time/1000);
3736 sb.append("(");
3737 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3738 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003739 sb.append(getWifiStateCount(i, which));
3740 sb.append("x");
3741 }
3742 if (!didOne) sb.append(" (no activity)");
3743 pw.println(sb.toString());
3744
3745 sb.setLength(0);
3746 sb.append(prefix);
3747 sb.append(" Wifi supplicant states:");
3748 didOne = false;
3749 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3750 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3751 if (time == 0) {
3752 continue;
3753 }
3754 sb.append("\n ");
3755 didOne = true;
3756 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3757 sb.append(" ");
3758 formatTimeMs(sb, time/1000);
3759 sb.append("(");
3760 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3761 sb.append(") ");
3762 sb.append(getWifiSupplStateCount(i, which));
3763 sb.append("x");
3764 }
3765 if (!didOne) sb.append(" (no activity)");
3766 pw.println(sb.toString());
3767
3768 sb.setLength(0);
3769 sb.append(prefix);
3770 sb.append(" Wifi signal levels:");
3771 didOne = false;
3772 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3773 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3774 if (time == 0) {
3775 continue;
3776 }
3777 sb.append("\n ");
3778 sb.append(prefix);
3779 didOne = true;
3780 sb.append("level(");
3781 sb.append(i);
3782 sb.append(") ");
3783 formatTimeMs(sb, time/1000);
3784 sb.append("(");
3785 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3786 sb.append(") ");
3787 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003788 sb.append("x");
3789 }
3790 if (!didOne) sb.append(" (no activity)");
3791 pw.println(sb.toString());
3792
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003793 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07003794
Adam Lesinski50e47602015-12-04 17:04:54 -08003795 pw.print(prefix);
3796 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
3797 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
3798
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003799 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
3800 sb.setLength(0);
3801 sb.append(prefix);
3802 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
3803 pw.println(sb.toString());
3804
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003805 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
3806 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003807
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003808 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003809
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003810 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003811 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003812 pw.print(prefix); pw.println(" Device is currently unplugged");
3813 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3814 pw.println(getDischargeStartLevel());
3815 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3816 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003817 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003818 pw.print(prefix); pw.println(" Device is currently plugged into power");
3819 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3820 pw.println(getDischargeStartLevel());
3821 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3822 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003823 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003824 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3825 pw.println(getDischargeAmountScreenOn());
3826 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3827 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003828 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003829 } else {
3830 pw.print(prefix); pw.println(" Device battery use since last full charge");
3831 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3832 pw.println(getLowDischargeAmountSinceCharge());
3833 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3834 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003835 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3836 pw.println(getDischargeAmountScreenOnSinceCharge());
3837 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3838 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003839 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003840 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003841
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003842 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003843 helper.create(this);
3844 helper.refreshStats(which, UserHandle.USER_ALL);
3845 List<BatterySipper> sippers = helper.getUsageList();
3846 if (sippers != null && sippers.size() > 0) {
3847 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3848 pw.print(prefix); pw.print(" Capacity: ");
3849 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003850 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003851 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3852 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3853 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3854 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003855 pw.println();
3856 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003857 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003858 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003859 switch (bs.drainType) {
3860 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003861 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003862 break;
3863 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003864 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003865 break;
3866 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003867 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003868 break;
3869 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003870 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003871 break;
3872 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003873 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003874 break;
3875 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003876 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003877 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003878 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003879 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003880 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003881 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003882 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003883 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003884 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003885 break;
3886 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003887 pw.print(" User "); pw.print(bs.userId);
3888 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003889 break;
3890 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003891 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003892 break;
3893 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003894 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003895 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003896 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003897 pw.print(" Camera: ");
3898 break;
3899 default:
3900 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003901 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003902 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003903 printmAh(pw, bs.totalPowerMah);
3904
Adam Lesinski57123002015-06-12 16:12:07 -07003905 if (bs.usagePowerMah != bs.totalPowerMah) {
3906 // If the usage (generic power) isn't the whole amount, we list out
3907 // what components are involved in the calculation.
3908
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003909 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07003910 if (bs.usagePowerMah != 0) {
3911 pw.print(" usage=");
3912 printmAh(pw, bs.usagePowerMah);
3913 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003914 if (bs.cpuPowerMah != 0) {
3915 pw.print(" cpu=");
3916 printmAh(pw, bs.cpuPowerMah);
3917 }
3918 if (bs.wakeLockPowerMah != 0) {
3919 pw.print(" wake=");
3920 printmAh(pw, bs.wakeLockPowerMah);
3921 }
3922 if (bs.mobileRadioPowerMah != 0) {
3923 pw.print(" radio=");
3924 printmAh(pw, bs.mobileRadioPowerMah);
3925 }
3926 if (bs.wifiPowerMah != 0) {
3927 pw.print(" wifi=");
3928 printmAh(pw, bs.wifiPowerMah);
3929 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003930 if (bs.bluetoothPowerMah != 0) {
3931 pw.print(" bt=");
3932 printmAh(pw, bs.bluetoothPowerMah);
3933 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003934 if (bs.gpsPowerMah != 0) {
3935 pw.print(" gps=");
3936 printmAh(pw, bs.gpsPowerMah);
3937 }
3938 if (bs.sensorPowerMah != 0) {
3939 pw.print(" sensor=");
3940 printmAh(pw, bs.sensorPowerMah);
3941 }
3942 if (bs.cameraPowerMah != 0) {
3943 pw.print(" camera=");
3944 printmAh(pw, bs.cameraPowerMah);
3945 }
3946 if (bs.flashlightPowerMah != 0) {
3947 pw.print(" flash=");
3948 printmAh(pw, bs.flashlightPowerMah);
3949 }
3950 pw.print(" )");
3951 }
3952 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003953 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08003954 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003955 }
3956
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003957 sippers = helper.getMobilemsppList();
3958 if (sippers != null && sippers.size() > 0) {
3959 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003960 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003961 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003962 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003963 sb.setLength(0);
3964 sb.append(prefix); sb.append(" Uid ");
3965 UserHandle.formatUid(sb, bs.uidObj.getUid());
3966 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
3967 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
3968 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003969 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003970 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003971 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003972 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003973 sb.setLength(0);
3974 sb.append(prefix);
3975 sb.append(" TOTAL TIME: ");
3976 formatTimeMs(sb, totalTime);
3977 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
3978 sb.append(")");
3979 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003980 pw.println();
3981 }
3982
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003983 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
3984 @Override
3985 public int compare(TimerEntry lhs, TimerEntry rhs) {
3986 long lhsTime = lhs.mTime;
3987 long rhsTime = rhs.mTime;
3988 if (lhsTime < rhsTime) {
3989 return 1;
3990 }
3991 if (lhsTime > rhsTime) {
3992 return -1;
3993 }
3994 return 0;
3995 }
3996 };
3997
3998 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003999 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4000 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004001 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004002 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4003 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4004 : kernelWakelocks.entrySet()) {
4005 final BatteryStats.Timer timer = ent.getValue();
4006 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004007 if (totalTimeMillis > 0) {
4008 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4009 }
4010 }
4011 if (ktimers.size() > 0) {
4012 Collections.sort(ktimers, timerComparator);
4013 pw.print(prefix); pw.println(" All kernel wake locks:");
4014 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004015 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004016 String linePrefix = ": ";
4017 sb.setLength(0);
4018 sb.append(prefix);
4019 sb.append(" Kernel Wake lock ");
4020 sb.append(timer.mName);
4021 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4022 which, linePrefix);
4023 if (!linePrefix.equals(": ")) {
4024 sb.append(" realtime");
4025 // Only print out wake locks that were held
4026 pw.println(sb.toString());
4027 }
4028 }
4029 pw.println();
4030 }
4031 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004032
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004033 if (timers.size() > 0) {
4034 Collections.sort(timers, timerComparator);
4035 pw.print(prefix); pw.println(" All partial wake locks:");
4036 for (int i=0; i<timers.size(); i++) {
4037 TimerEntry timer = timers.get(i);
4038 sb.setLength(0);
4039 sb.append(" Wake lock ");
4040 UserHandle.formatUid(sb, timer.mId);
4041 sb.append(" ");
4042 sb.append(timer.mName);
4043 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4044 sb.append(" realtime");
4045 pw.println(sb.toString());
4046 }
4047 timers.clear();
4048 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004049 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004050
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004051 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004052 if (wakeupReasons.size() > 0) {
4053 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004054 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004055 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004056 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004057 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4058 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004059 }
4060 Collections.sort(reasons, timerComparator);
4061 for (int i=0; i<reasons.size(); i++) {
4062 TimerEntry timer = reasons.get(i);
4063 String linePrefix = ": ";
4064 sb.setLength(0);
4065 sb.append(prefix);
4066 sb.append(" Wakeup reason ");
4067 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004068 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4069 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004070 pw.println(sb.toString());
4071 }
4072 pw.println();
4073 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004074 }
Evan Millar22ac0432009-03-31 11:33:18 -07004075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 for (int iu=0; iu<NU; iu++) {
4077 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004078 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004079 continue;
4080 }
4081
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004082 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004083
4084 pw.print(prefix);
4085 pw.print(" ");
4086 UserHandle.formatUid(pw, uid);
4087 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004088 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004089
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004090 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4091 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4092 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4093 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004094 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4095 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4096
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004097 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4098 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004099 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4100 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004101
4102 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4103 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4104
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004105 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4106 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4107 final int wifiScanCount = u.getWifiScanCount(which);
4108 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004109
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004110 if (mobileRxBytes > 0 || mobileTxBytes > 0
4111 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004112 pw.print(prefix); pw.print(" Mobile network: ");
4113 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004114 pw.print(formatBytesLocked(mobileTxBytes));
4115 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4116 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004117 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004118 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4119 sb.setLength(0);
4120 sb.append(prefix); sb.append(" Mobile radio active: ");
4121 formatTimeMs(sb, uidMobileActiveTime / 1000);
4122 sb.append("(");
4123 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4124 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4125 long packets = mobileRxPackets + mobileTxPackets;
4126 if (packets == 0) {
4127 packets = 1;
4128 }
4129 sb.append(" @ ");
4130 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4131 sb.append(" mspp");
4132 pw.println(sb.toString());
4133 }
4134
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004135 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4136 u.getModemControllerActivity(), which);
4137
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004138 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004139 pw.print(prefix); pw.print(" Wi-Fi network: ");
4140 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004141 pw.print(formatBytesLocked(wifiTxBytes));
4142 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4143 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004144 }
4145
Dianne Hackborn62793e42015-03-09 11:15:41 -07004146 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004147 || uidWifiRunningTime != 0) {
4148 sb.setLength(0);
4149 sb.append(prefix); sb.append(" Wifi Running: ");
4150 formatTimeMs(sb, uidWifiRunningTime / 1000);
4151 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4152 whichBatteryRealtime)); sb.append(")\n");
4153 sb.append(prefix); sb.append(" Full Wifi Lock: ");
4154 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4155 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4156 whichBatteryRealtime)); sb.append(")\n");
4157 sb.append(prefix); sb.append(" Wifi Scan: ");
4158 formatTimeMs(sb, wifiScanTime / 1000);
4159 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004160 whichBatteryRealtime)); sb.append(") ");
4161 sb.append(wifiScanCount);
4162 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004163 pw.println(sb.toString());
4164 }
4165
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004166 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4167 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004168
Adam Lesinski50e47602015-12-04 17:04:54 -08004169 if (btRxBytes > 0 || btTxBytes > 0) {
4170 pw.print(prefix); pw.print(" Bluetooth network: ");
4171 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4172 pw.print(formatBytesLocked(btTxBytes));
4173 pw.println(" sent");
4174 }
4175
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004176 uidActivity |= printTimer(pw, sb, u.getBluetoothScanTimer(), rawRealtime, which, prefix,
4177 "Bluetooth Scan");
4178
Dianne Hackborn617f8772009-03-31 15:04:46 -07004179 if (u.hasUserActivity()) {
4180 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004181 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004182 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004183 if (val != 0) {
4184 if (!hasData) {
4185 sb.setLength(0);
4186 sb.append(" User activity: ");
4187 hasData = true;
4188 } else {
4189 sb.append(", ");
4190 }
4191 sb.append(val);
4192 sb.append(" ");
4193 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4194 }
4195 }
4196 if (hasData) {
4197 pw.println(sb.toString());
4198 }
4199 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004200
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004201 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4202 = u.getWakelockStats();
4203 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004204 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004205 int countWakelock = 0;
4206 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4207 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4208 String linePrefix = ": ";
4209 sb.setLength(0);
4210 sb.append(prefix);
4211 sb.append(" Wake lock ");
4212 sb.append(wakelocks.keyAt(iw));
4213 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4214 "full", which, linePrefix);
4215 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
4216 "partial", which, linePrefix);
4217 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4218 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004219 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4220 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004221 sb.append(" realtime");
4222 pw.println(sb.toString());
4223 uidActivity = true;
4224 countWakelock++;
4225
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004226 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4227 rawRealtime, which);
4228 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4229 rawRealtime, which);
4230 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4231 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004232 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004233 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004234 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004235 if (countWakelock > 1) {
4236 if (totalFullWakelock != 0 || totalPartialWakelock != 0
4237 || totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004238 sb.setLength(0);
4239 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004240 sb.append(" TOTAL wake: ");
4241 boolean needComma = false;
4242 if (totalFullWakelock != 0) {
4243 needComma = true;
4244 formatTimeMs(sb, totalFullWakelock);
4245 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004246 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004247 if (totalPartialWakelock != 0) {
4248 if (needComma) {
4249 sb.append(", ");
4250 }
4251 needComma = true;
4252 formatTimeMs(sb, totalPartialWakelock);
4253 sb.append("partial");
4254 }
4255 if (totalWindowWakelock != 0) {
4256 if (needComma) {
4257 sb.append(", ");
4258 }
4259 needComma = true;
4260 formatTimeMs(sb, totalWindowWakelock);
4261 sb.append("window");
4262 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004263 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004264 if (needComma) {
4265 sb.append(",");
4266 }
4267 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004268 formatTimeMs(sb, totalDrawWakelock);
4269 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004270 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004271 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004272 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004273 }
4274 }
4275
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004276 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4277 for (int isy=syncs.size()-1; isy>=0; isy--) {
4278 final Timer timer = syncs.valueAt(isy);
4279 // Convert from microseconds to milliseconds with rounding
4280 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4281 final int count = timer.getCountLocked(which);
4282 sb.setLength(0);
4283 sb.append(prefix);
4284 sb.append(" Sync ");
4285 sb.append(syncs.keyAt(isy));
4286 sb.append(": ");
4287 if (totalTime != 0) {
4288 formatTimeMs(sb, totalTime);
4289 sb.append("realtime (");
4290 sb.append(count);
4291 sb.append(" times)");
4292 } else {
4293 sb.append("(not used)");
4294 }
4295 pw.println(sb.toString());
4296 uidActivity = true;
4297 }
4298
4299 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4300 for (int ij=jobs.size()-1; ij>=0; ij--) {
4301 final Timer timer = jobs.valueAt(ij);
4302 // Convert from microseconds to milliseconds with rounding
4303 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4304 final int count = timer.getCountLocked(which);
4305 sb.setLength(0);
4306 sb.append(prefix);
4307 sb.append(" Job ");
4308 sb.append(jobs.keyAt(ij));
4309 sb.append(": ");
4310 if (totalTime != 0) {
4311 formatTimeMs(sb, totalTime);
4312 sb.append("realtime (");
4313 sb.append(count);
4314 sb.append(" times)");
4315 } else {
4316 sb.append("(not used)");
4317 }
4318 pw.println(sb.toString());
4319 uidActivity = true;
4320 }
4321
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004322 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
4323 prefix, "Flashlight");
4324 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
4325 prefix, "Camera");
4326 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
4327 prefix, "Video");
4328 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
4329 prefix, "Audio");
4330
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004331 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4332 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004333 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004334 final Uid.Sensor se = sensors.valueAt(ise);
4335 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004336 sb.setLength(0);
4337 sb.append(prefix);
4338 sb.append(" Sensor ");
4339 int handle = se.getHandle();
4340 if (handle == Uid.Sensor.GPS) {
4341 sb.append("GPS");
4342 } else {
4343 sb.append(handle);
4344 }
4345 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004347 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004348 if (timer != null) {
4349 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004350 final long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn61659e52014-07-09 16:13:01 -07004351 rawRealtime, which) + 500) / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004352 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004353 //timer.logState();
4354 if (totalTime != 0) {
4355 formatTimeMs(sb, totalTime);
4356 sb.append("realtime (");
4357 sb.append(count);
4358 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004359 } else {
4360 sb.append("(not used)");
4361 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004362 } else {
4363 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004364 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004365
4366 pw.println(sb.toString());
4367 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004368 }
4369
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004370 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4371 "Vibrator");
4372 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4373 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004374
Dianne Hackborn61659e52014-07-09 16:13:01 -07004375 long totalStateTime = 0;
4376 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4377 long time = u.getProcessStateTime(ips, rawRealtime, which);
4378 if (time > 0) {
4379 totalStateTime += time;
4380 sb.setLength(0);
4381 sb.append(prefix);
4382 sb.append(" ");
4383 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4384 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08004385 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004386 pw.println(sb.toString());
4387 uidActivity = true;
4388 }
4389 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08004390 if (totalStateTime > 0) {
4391 sb.setLength(0);
4392 sb.append(prefix);
4393 sb.append(" Total running: ");
4394 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4395 pw.println(sb.toString());
4396 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004397
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004398 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4399 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004400 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
4401 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004402 sb.setLength(0);
4403 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004404 sb.append(" Total cpu time: u=");
4405 formatTimeMs(sb, userCpuTimeUs / 1000);
4406 sb.append("s=");
4407 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004408 sb.append("p=");
4409 printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0));
4410 sb.append("mAh");
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004411 pw.println(sb.toString());
4412 }
4413
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004414 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4415 = u.getProcessStats();
4416 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4417 final Uid.Proc ps = processStats.valueAt(ipr);
4418 long userTime;
4419 long systemTime;
4420 long foregroundTime;
4421 int starts;
4422 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004424 userTime = ps.getUserTime(which);
4425 systemTime = ps.getSystemTime(which);
4426 foregroundTime = ps.getForegroundTime(which);
4427 starts = ps.getStarts(which);
4428 final int numCrashes = ps.getNumCrashes(which);
4429 final int numAnrs = ps.getNumAnrs(which);
4430 numExcessive = which == STATS_SINCE_CHARGED
4431 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004432
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004433 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
4434 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
4435 sb.setLength(0);
4436 sb.append(prefix); sb.append(" Proc ");
4437 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
4438 sb.append(prefix); sb.append(" CPU: ");
4439 formatTimeMs(sb, userTime); sb.append("usr + ");
4440 formatTimeMs(sb, systemTime); sb.append("krn ; ");
4441 formatTimeMs(sb, foregroundTime); sb.append("fg");
4442 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
4443 sb.append("\n"); sb.append(prefix); sb.append(" ");
4444 boolean hasOne = false;
4445 if (starts != 0) {
4446 hasOne = true;
4447 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07004448 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004449 if (numCrashes != 0) {
4450 if (hasOne) {
4451 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004452 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004453 hasOne = true;
4454 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004455 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004456 if (numAnrs != 0) {
4457 if (hasOne) {
4458 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004459 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004460 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004461 }
4462 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004463 pw.println(sb.toString());
4464 for (int e=0; e<numExcessive; e++) {
4465 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
4466 if (ew != null) {
4467 pw.print(prefix); pw.print(" * Killed for ");
4468 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
4469 pw.print("wake lock");
4470 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
4471 pw.print("cpu");
4472 } else {
4473 pw.print("unknown");
4474 }
4475 pw.print(" use: ");
4476 TimeUtils.formatDuration(ew.usedTime, pw);
4477 pw.print(" over ");
4478 TimeUtils.formatDuration(ew.overTime, pw);
4479 if (ew.overTime != 0) {
4480 pw.print(" (");
4481 pw.print((ew.usedTime*100)/ew.overTime);
4482 pw.println("%)");
4483 }
4484 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485 }
4486 uidActivity = true;
4487 }
4488 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004489
4490 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4491 = u.getPackageStats();
4492 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4493 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
4494 pw.println(":");
4495 boolean apkActivity = false;
4496 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4497 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4498 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
4499 pw.print(prefix); pw.print(" Wakeup alarm ");
4500 pw.print(alarms.keyAt(iwa)); pw.print(": ");
4501 pw.print(alarms.valueAt(iwa).getCountLocked(which));
4502 pw.println(" times");
4503 apkActivity = true;
4504 }
4505 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4506 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4507 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4508 final long startTime = ss.getStartTime(batteryUptime, which);
4509 final int starts = ss.getStarts(which);
4510 final int launches = ss.getLaunches(which);
4511 if (startTime != 0 || starts != 0 || launches != 0) {
4512 sb.setLength(0);
4513 sb.append(prefix); sb.append(" Service ");
4514 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
4515 sb.append(prefix); sb.append(" Created for: ");
4516 formatTimeMs(sb, startTime / 1000);
4517 sb.append("uptime\n");
4518 sb.append(prefix); sb.append(" Starts: ");
4519 sb.append(starts);
4520 sb.append(", launches: "); sb.append(launches);
4521 pw.println(sb.toString());
4522 apkActivity = true;
4523 }
4524 }
4525 if (!apkActivity) {
4526 pw.print(prefix); pw.println(" (nothing executed)");
4527 }
4528 uidActivity = true;
4529 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004530 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004531 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004532 }
4533 }
4534 }
4535
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004536 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004537 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004538 int diff = oldval ^ newval;
4539 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004540 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004541 for (int i=0; i<descriptions.length; i++) {
4542 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004543 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004544 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004545 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004546 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004547 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004548 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
4549 didWake = true;
4550 pw.print("=");
4551 if (longNames) {
4552 UserHandle.formatUid(pw, wakelockTag.uid);
4553 pw.print(":\"");
4554 pw.print(wakelockTag.string);
4555 pw.print("\"");
4556 } else {
4557 pw.print(wakelockTag.poolIdx);
4558 }
4559 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004560 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004561 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004562 pw.print("=");
4563 int val = (newval&bd.mask)>>bd.shift;
4564 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004565 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004566 } else {
4567 pw.print(val);
4568 }
4569 }
4570 }
4571 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004572 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07004573 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004574 if (longNames) {
4575 UserHandle.formatUid(pw, wakelockTag.uid);
4576 pw.print(":\"");
4577 pw.print(wakelockTag.string);
4578 pw.print("\"");
4579 } else {
4580 pw.print(wakelockTag.poolIdx);
4581 }
4582 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004583 }
4584
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004585 public void prepareForDumpLocked() {
4586 }
4587
4588 public static class HistoryPrinter {
4589 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004590 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004591 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004592 int oldStatus = -1;
4593 int oldHealth = -1;
4594 int oldPlug = -1;
4595 int oldTemp = -1;
4596 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004597 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004598 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004599
Dianne Hackborn3251b902014-06-20 14:40:53 -07004600 void reset() {
4601 oldState = oldState2 = 0;
4602 oldLevel = -1;
4603 oldStatus = -1;
4604 oldHealth = -1;
4605 oldPlug = -1;
4606 oldTemp = -1;
4607 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004608 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07004609 }
4610
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004611 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004612 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004613 if (!checkin) {
4614 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004615 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004616 pw.print(" (");
4617 pw.print(rec.numReadInts);
4618 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004619 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004620 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4621 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004622 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004623 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004624 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004625 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004626 }
4627 lastTime = rec.time;
4628 }
4629 if (rec.cmd == HistoryItem.CMD_START) {
4630 if (checkin) {
4631 pw.print(":");
4632 }
4633 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004634 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004635 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4636 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004637 if (checkin) {
4638 pw.print(":");
4639 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004640 if (rec.cmd == HistoryItem.CMD_RESET) {
4641 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004642 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004643 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004644 pw.print("TIME:");
4645 if (checkin) {
4646 pw.println(rec.currentTime);
4647 } else {
4648 pw.print(" ");
4649 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4650 rec.currentTime).toString());
4651 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004652 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4653 if (checkin) {
4654 pw.print(":");
4655 }
4656 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004657 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4658 if (checkin) {
4659 pw.print(":");
4660 }
4661 pw.println("*OVERFLOW*");
4662 } else {
4663 if (!checkin) {
4664 if (rec.batteryLevel < 10) pw.print("00");
4665 else if (rec.batteryLevel < 100) pw.print("0");
4666 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004667 if (verbose) {
4668 pw.print(" ");
4669 if (rec.states < 0) ;
4670 else if (rec.states < 0x10) pw.print("0000000");
4671 else if (rec.states < 0x100) pw.print("000000");
4672 else if (rec.states < 0x1000) pw.print("00000");
4673 else if (rec.states < 0x10000) pw.print("0000");
4674 else if (rec.states < 0x100000) pw.print("000");
4675 else if (rec.states < 0x1000000) pw.print("00");
4676 else if (rec.states < 0x10000000) pw.print("0");
4677 pw.print(Integer.toHexString(rec.states));
4678 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004679 } else {
4680 if (oldLevel != rec.batteryLevel) {
4681 oldLevel = rec.batteryLevel;
4682 pw.print(",Bl="); pw.print(rec.batteryLevel);
4683 }
4684 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004685 if (oldStatus != rec.batteryStatus) {
4686 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004687 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004688 switch (oldStatus) {
4689 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004690 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004691 break;
4692 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004693 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004694 break;
4695 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004696 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004697 break;
4698 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004699 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004700 break;
4701 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004702 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004703 break;
4704 default:
4705 pw.print(oldStatus);
4706 break;
4707 }
4708 }
4709 if (oldHealth != rec.batteryHealth) {
4710 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004711 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004712 switch (oldHealth) {
4713 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004714 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004715 break;
4716 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004717 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004718 break;
4719 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004720 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004721 break;
4722 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004723 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004724 break;
4725 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004726 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004727 break;
4728 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004729 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004730 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004731 case BatteryManager.BATTERY_HEALTH_COLD:
4732 pw.print(checkin ? "c" : "cold");
4733 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004734 default:
4735 pw.print(oldHealth);
4736 break;
4737 }
4738 }
4739 if (oldPlug != rec.batteryPlugType) {
4740 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004741 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004742 switch (oldPlug) {
4743 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004744 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004745 break;
4746 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004747 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004748 break;
4749 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004750 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004751 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004752 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004753 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004754 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004755 default:
4756 pw.print(oldPlug);
4757 break;
4758 }
4759 }
4760 if (oldTemp != rec.batteryTemperature) {
4761 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004762 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004763 pw.print(oldTemp);
4764 }
4765 if (oldVolt != rec.batteryVoltage) {
4766 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004767 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004768 pw.print(oldVolt);
4769 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004770 final int chargeMAh = rec.batteryChargeUAh / 1000;
4771 if (oldChargeMAh != chargeMAh) {
4772 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07004773 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004774 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07004775 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004776 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004777 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004778 printBitDescriptions(pw, oldState2, rec.states2, null,
4779 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004780 if (rec.wakeReasonTag != null) {
4781 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004782 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004783 pw.print(rec.wakeReasonTag.poolIdx);
4784 } else {
4785 pw.print(" wake_reason=");
4786 pw.print(rec.wakeReasonTag.uid);
4787 pw.print(":\"");
4788 pw.print(rec.wakeReasonTag.string);
4789 pw.print("\"");
4790 }
4791 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004792 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004793 pw.print(checkin ? "," : " ");
4794 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4795 pw.print("+");
4796 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4797 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004798 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004799 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4800 : HISTORY_EVENT_NAMES;
4801 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4802 | HistoryItem.EVENT_FLAG_FINISH);
4803 if (idx >= 0 && idx < eventNames.length) {
4804 pw.print(eventNames[idx]);
4805 } else {
4806 pw.print(checkin ? "Ev" : "event");
4807 pw.print(idx);
4808 }
4809 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004810 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004811 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004812 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004813 UserHandle.formatUid(pw, rec.eventTag.uid);
4814 pw.print(":\"");
4815 pw.print(rec.eventTag.string);
4816 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004817 }
4818 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004819 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004820 if (rec.stepDetails != null) {
4821 if (!checkin) {
4822 pw.print(" Details: cpu=");
4823 pw.print(rec.stepDetails.userTime);
4824 pw.print("u+");
4825 pw.print(rec.stepDetails.systemTime);
4826 pw.print("s");
4827 if (rec.stepDetails.appCpuUid1 >= 0) {
4828 pw.print(" (");
4829 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4830 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4831 if (rec.stepDetails.appCpuUid2 >= 0) {
4832 pw.print(", ");
4833 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4834 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4835 }
4836 if (rec.stepDetails.appCpuUid3 >= 0) {
4837 pw.print(", ");
4838 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4839 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4840 }
4841 pw.print(')');
4842 }
4843 pw.println();
4844 pw.print(" /proc/stat=");
4845 pw.print(rec.stepDetails.statUserTime);
4846 pw.print(" usr, ");
4847 pw.print(rec.stepDetails.statSystemTime);
4848 pw.print(" sys, ");
4849 pw.print(rec.stepDetails.statIOWaitTime);
4850 pw.print(" io, ");
4851 pw.print(rec.stepDetails.statIrqTime);
4852 pw.print(" irq, ");
4853 pw.print(rec.stepDetails.statSoftIrqTime);
4854 pw.print(" sirq, ");
4855 pw.print(rec.stepDetails.statIdlTime);
4856 pw.print(" idle");
4857 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4858 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4859 + rec.stepDetails.statSoftIrqTime;
4860 int total = totalRun + rec.stepDetails.statIdlTime;
4861 if (total > 0) {
4862 pw.print(" (");
4863 float perc = ((float)totalRun) / ((float)total) * 100;
4864 pw.print(String.format("%.1f%%", perc));
4865 pw.print(" of ");
4866 StringBuilder sb = new StringBuilder(64);
4867 formatTimeMsNoSpace(sb, total*10);
4868 pw.print(sb);
4869 pw.print(")");
4870 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07004871 pw.print(", PlatformIdleStat ");
4872 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004873 pw.println();
4874 } else {
4875 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4876 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4877 pw.print(rec.stepDetails.userTime);
4878 pw.print(":");
4879 pw.print(rec.stepDetails.systemTime);
4880 if (rec.stepDetails.appCpuUid1 >= 0) {
4881 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4882 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4883 if (rec.stepDetails.appCpuUid2 >= 0) {
4884 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4885 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4886 }
4887 if (rec.stepDetails.appCpuUid3 >= 0) {
4888 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4889 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4890 }
4891 }
4892 pw.println();
4893 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4894 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4895 pw.print(rec.stepDetails.statUserTime);
4896 pw.print(',');
4897 pw.print(rec.stepDetails.statSystemTime);
4898 pw.print(',');
4899 pw.print(rec.stepDetails.statIOWaitTime);
4900 pw.print(',');
4901 pw.print(rec.stepDetails.statIrqTime);
4902 pw.print(',');
4903 pw.print(rec.stepDetails.statSoftIrqTime);
4904 pw.print(',');
4905 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07004906 pw.print(',');
4907 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004908 pw.println();
4909 }
4910 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004911 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004912 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004913 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004914 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004915
4916 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4917 UserHandle.formatUid(pw, uid);
4918 pw.print("=");
4919 pw.print(utime);
4920 pw.print("u+");
4921 pw.print(stime);
4922 pw.print("s");
4923 }
4924
4925 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
4926 pw.print('/');
4927 pw.print(uid);
4928 pw.print(":");
4929 pw.print(utime);
4930 pw.print(":");
4931 pw.print(stime);
4932 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004933 }
4934
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004935 private void printSizeValue(PrintWriter pw, long size) {
4936 float result = size;
4937 String suffix = "";
4938 if (result >= 10*1024) {
4939 suffix = "KB";
4940 result = result / 1024;
4941 }
4942 if (result >= 10*1024) {
4943 suffix = "MB";
4944 result = result / 1024;
4945 }
4946 if (result >= 10*1024) {
4947 suffix = "GB";
4948 result = result / 1024;
4949 }
4950 if (result >= 10*1024) {
4951 suffix = "TB";
4952 result = result / 1024;
4953 }
4954 if (result >= 10*1024) {
4955 suffix = "PB";
4956 result = result / 1024;
4957 }
4958 pw.print((int)result);
4959 pw.print(suffix);
4960 }
4961
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004962 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
4963 String label3, long estimatedTime) {
4964 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004965 return false;
4966 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004967 pw.print(label1);
4968 pw.print(label2);
4969 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004970 StringBuilder sb = new StringBuilder(64);
4971 formatTimeMs(sb, estimatedTime);
4972 pw.print(sb);
4973 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004974 return true;
4975 }
4976
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004977 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
4978 LevelStepTracker steps, boolean checkin) {
4979 if (steps == null) {
4980 return false;
4981 }
4982 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004983 if (count <= 0) {
4984 return false;
4985 }
4986 if (!checkin) {
4987 pw.println(header);
4988 }
Kweku Adams030980a2015-04-01 16:07:48 -07004989 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004990 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004991 long duration = steps.getDurationAt(i);
4992 int level = steps.getLevelAt(i);
4993 long initMode = steps.getInitModeAt(i);
4994 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004995 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004996 lineArgs[0] = Long.toString(duration);
4997 lineArgs[1] = Integer.toString(level);
4998 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4999 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5000 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5001 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5002 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5003 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005004 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005005 }
5006 } else {
5007 lineArgs[2] = "";
5008 }
5009 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5010 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5011 } else {
5012 lineArgs[3] = "";
5013 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005014 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005015 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005016 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005017 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005018 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005019 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5020 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005021 pw.print(prefix);
5022 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005023 TimeUtils.formatDuration(duration, pw);
5024 pw.print(" to "); pw.print(level);
5025 boolean haveModes = false;
5026 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5027 pw.print(" (");
5028 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5029 case Display.STATE_OFF: pw.print("screen-off"); break;
5030 case Display.STATE_ON: pw.print("screen-on"); break;
5031 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5032 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005033 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005034 }
5035 haveModes = true;
5036 }
5037 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5038 pw.print(haveModes ? ", " : " (");
5039 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5040 ? "power-save-on" : "power-save-off");
5041 haveModes = true;
5042 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005043 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5044 pw.print(haveModes ? ", " : " (");
5045 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5046 ? "device-idle-on" : "device-idle-off");
5047 haveModes = true;
5048 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005049 if (haveModes) {
5050 pw.print(")");
5051 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005052 pw.println();
5053 }
5054 }
5055 return true;
5056 }
5057
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005058 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005059 public static final int DUMP_DAILY_ONLY = 1<<2;
5060 public static final int DUMP_HISTORY_ONLY = 1<<3;
5061 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5062 public static final int DUMP_VERBOSE = 1<<5;
5063 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005064
Dianne Hackborn37de0982014-05-09 09:32:18 -07005065 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5066 final HistoryPrinter hprinter = new HistoryPrinter();
5067 final HistoryItem rec = new HistoryItem();
5068 long lastTime = -1;
5069 long baseTime = -1;
5070 boolean printed = false;
5071 HistoryEventTracker tracker = null;
5072 while (getNextHistoryLocked(rec)) {
5073 lastTime = rec.time;
5074 if (baseTime < 0) {
5075 baseTime = lastTime;
5076 }
5077 if (rec.time >= histStart) {
5078 if (histStart >= 0 && !printed) {
5079 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005080 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005081 || rec.cmd == HistoryItem.CMD_START
5082 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005083 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005084 hprinter.printNextItem(pw, rec, baseTime, checkin,
5085 (flags&DUMP_VERBOSE) != 0);
5086 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005087 } else if (rec.currentTime != 0) {
5088 printed = true;
5089 byte cmd = rec.cmd;
5090 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005091 hprinter.printNextItem(pw, rec, baseTime, checkin,
5092 (flags&DUMP_VERBOSE) != 0);
5093 rec.cmd = cmd;
5094 }
5095 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005096 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5097 hprinter.printNextItem(pw, rec, baseTime, checkin,
5098 (flags&DUMP_VERBOSE) != 0);
5099 rec.cmd = HistoryItem.CMD_UPDATE;
5100 }
5101 int oldEventCode = rec.eventCode;
5102 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005103 rec.eventTag = new HistoryTag();
5104 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5105 HashMap<String, SparseIntArray> active
5106 = tracker.getStateForEvent(i);
5107 if (active == null) {
5108 continue;
5109 }
5110 for (HashMap.Entry<String, SparseIntArray> ent
5111 : active.entrySet()) {
5112 SparseIntArray uids = ent.getValue();
5113 for (int j=0; j<uids.size(); j++) {
5114 rec.eventCode = i;
5115 rec.eventTag.string = ent.getKey();
5116 rec.eventTag.uid = uids.keyAt(j);
5117 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005118 hprinter.printNextItem(pw, rec, baseTime, checkin,
5119 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005120 rec.wakeReasonTag = null;
5121 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005122 }
5123 }
5124 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005125 rec.eventCode = oldEventCode;
5126 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005127 tracker = null;
5128 }
5129 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005130 hprinter.printNextItem(pw, rec, baseTime, checkin,
5131 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005132 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5133 // This is an attempt to aggregate the previous state and generate
5134 // fake events to reflect that state at the point where we start
5135 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005136 if (tracker == null) {
5137 tracker = new HistoryEventTracker();
5138 }
5139 tracker.updateState(rec.eventCode, rec.eventTag.string,
5140 rec.eventTag.uid, rec.eventTag.poolIdx);
5141 }
5142 }
5143 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005144 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005145 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5146 }
5147 }
5148
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005149 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5150 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5151 if (steps == null) {
5152 return;
5153 }
5154 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5155 if (timeRemaining >= 0) {
5156 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5157 tmpSb.setLength(0);
5158 formatTimeMs(tmpSb, timeRemaining);
5159 pw.print(tmpSb);
5160 pw.print(" (from "); pw.print(tmpOutInt[0]);
5161 pw.println(" steps)");
5162 }
5163 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5164 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5165 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5166 if (estimatedTime > 0) {
5167 pw.print(prefix); pw.print(label); pw.print(" ");
5168 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5169 pw.print(" time: ");
5170 tmpSb.setLength(0);
5171 formatTimeMs(tmpSb, estimatedTime);
5172 pw.print(tmpSb);
5173 pw.print(" (from "); pw.print(tmpOutInt[0]);
5174 pw.println(" steps)");
5175 }
5176 }
5177 }
5178
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005179 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5180 ArrayList<PackageChange> changes) {
5181 if (changes == null) {
5182 return;
5183 }
5184 pw.print(prefix); pw.println("Package changes:");
5185 for (int i=0; i<changes.size(); i++) {
5186 PackageChange pc = changes.get(i);
5187 if (pc.mUpdate) {
5188 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5189 pw.print(" vers="); pw.println(pc.mVersionCode);
5190 } else {
5191 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5192 }
5193 }
5194 }
5195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005196 /**
5197 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5198 *
5199 * @param pw a Printer to receive the dump output.
5200 */
5201 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005202 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005203 prepareForDumpLocked();
5204
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005205 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005206 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005207
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005208 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005209 final long historyTotalSize = getHistoryTotalSize();
5210 final long historyUsedSize = getHistoryUsedSize();
5211 if (startIteratingHistoryLocked()) {
5212 try {
5213 pw.print("Battery History (");
5214 pw.print((100*historyUsedSize)/historyTotalSize);
5215 pw.print("% used, ");
5216 printSizeValue(pw, historyUsedSize);
5217 pw.print(" used of ");
5218 printSizeValue(pw, historyTotalSize);
5219 pw.print(", ");
5220 pw.print(getHistoryStringPoolSize());
5221 pw.print(" strings using ");
5222 printSizeValue(pw, getHistoryStringPoolBytes());
5223 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005224 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005225 pw.println();
5226 } finally {
5227 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005228 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005229 }
5230
5231 if (startIteratingOldHistoryLocked()) {
5232 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005233 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005234 pw.println("Old battery History:");
5235 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005236 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005237 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005238 if (baseTime < 0) {
5239 baseTime = rec.time;
5240 }
5241 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005242 }
5243 pw.println();
5244 } finally {
5245 finishIteratingOldHistoryLocked();
5246 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005247 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005248 }
5249
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005250 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005251 return;
5252 }
5253
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005254 if (!filtering) {
5255 SparseArray<? extends Uid> uidStats = getUidStats();
5256 final int NU = uidStats.size();
5257 boolean didPid = false;
5258 long nowRealtime = SystemClock.elapsedRealtime();
5259 for (int i=0; i<NU; i++) {
5260 Uid uid = uidStats.valueAt(i);
5261 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
5262 if (pids != null) {
5263 for (int j=0; j<pids.size(); j++) {
5264 Uid.Pid pid = pids.valueAt(j);
5265 if (!didPid) {
5266 pw.println("Per-PID Stats:");
5267 didPid = true;
5268 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005269 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
5270 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005271 pw.print(" PID "); pw.print(pids.keyAt(j));
5272 pw.print(" wake time: ");
5273 TimeUtils.formatDuration(time, pw);
5274 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005275 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005276 }
5277 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005278 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005279 pw.println();
5280 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005281 }
5282
5283 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005284 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
5285 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005286 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5287 if (timeRemaining >= 0) {
5288 pw.print(" Estimated discharge time remaining: ");
5289 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5290 pw.println();
5291 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005292 final LevelStepTracker steps = getDischargeLevelStepTracker();
5293 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5294 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
5295 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5296 STEP_LEVEL_MODE_VALUES[i], null));
5297 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005298 pw.println();
5299 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005300 if (dumpDurationSteps(pw, " ", "Charge step durations:",
5301 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005302 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5303 if (timeRemaining >= 0) {
5304 pw.print(" Estimated charge time remaining: ");
5305 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5306 pw.println();
5307 }
5308 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005309 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005310 }
5311 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
5312 pw.println("Daily stats:");
5313 pw.print(" Current start time: ");
5314 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5315 getCurrentDailyStartTime()).toString());
5316 pw.print(" Next min deadline: ");
5317 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5318 getNextMinDailyDeadline()).toString());
5319 pw.print(" Next max deadline: ");
5320 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5321 getNextMaxDailyDeadline()).toString());
5322 StringBuilder sb = new StringBuilder(64);
5323 int[] outInt = new int[1];
5324 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
5325 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005326 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
5327 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005328 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005329 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
5330 dsteps, false)) {
5331 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5332 sb, outInt);
5333 }
5334 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
5335 csteps, false)) {
5336 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5337 sb, outInt);
5338 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005339 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005340 } else {
5341 pw.println(" Current daily steps:");
5342 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5343 sb, outInt);
5344 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5345 sb, outInt);
5346 }
5347 }
5348 DailyItem dit;
5349 int curIndex = 0;
5350 while ((dit=getDailyItemLocked(curIndex)) != null) {
5351 curIndex++;
5352 if ((flags&DUMP_DAILY_ONLY) != 0) {
5353 pw.println();
5354 }
5355 pw.print(" Daily from ");
5356 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
5357 pw.print(" to ");
5358 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
5359 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005360 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005361 if (dumpDurationSteps(pw, " ",
5362 " Discharge step durations:", dit.mDischargeSteps, false)) {
5363 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5364 sb, outInt);
5365 }
5366 if (dumpDurationSteps(pw, " ",
5367 " Charge step durations:", dit.mChargeSteps, false)) {
5368 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5369 sb, outInt);
5370 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005371 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005372 } else {
5373 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5374 sb, outInt);
5375 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5376 sb, outInt);
5377 }
5378 }
5379 pw.println();
5380 }
5381 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005382 pw.println("Statistics since last charge:");
5383 pw.println(" System starts: " + getStartCount()
5384 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005385 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5386 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005387 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005389 }
5390
5391 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005392 public void dumpCheckinLocked(Context context, PrintWriter pw,
5393 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005394 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005395
5396 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005397 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5398 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005399
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005400 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5401
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005402 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005403 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005404
5405 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005406 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005407 try {
5408 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5409 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5410 pw.print(HISTORY_STRING_POOL); pw.print(',');
5411 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005412 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005413 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005414 pw.print(",\"");
5415 String str = getHistoryTagPoolString(i);
5416 str = str.replace("\\", "\\\\");
5417 str = str.replace("\"", "\\\"");
5418 pw.print(str);
5419 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005420 pw.println();
5421 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005422 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005423 } finally {
5424 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08005425 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005426 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005427 }
5428
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005429 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005430 return;
5431 }
5432
Dianne Hackborne4a59512010-12-07 11:08:07 -08005433 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005434 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08005435 for (int i=0; i<apps.size(); i++) {
5436 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005437 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
5438 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08005439 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005440 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
5441 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005442 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005443 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005444 }
5445 SparseArray<? extends Uid> uidStats = getUidStats();
5446 final int NU = uidStats.size();
5447 String[] lineArgs = new String[2];
5448 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005449 int uid = UserHandle.getAppId(uidStats.keyAt(i));
5450 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
5451 if (pkgs != null && !pkgs.second.value) {
5452 pkgs.second.value = true;
5453 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08005454 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005455 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005456 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
5457 (Object[])lineArgs);
5458 }
5459 }
5460 }
5461 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005462 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005463 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005464 String[] lineArgs = new String[1];
5465 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5466 if (timeRemaining >= 0) {
5467 lineArgs[0] = Long.toString(timeRemaining);
5468 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
5469 (Object[])lineArgs);
5470 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005471 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005472 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5473 if (timeRemaining >= 0) {
5474 lineArgs[0] = Long.toString(timeRemaining);
5475 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
5476 (Object[])lineArgs);
5477 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07005478 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
5479 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005480 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005481 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005482}