blob: af9c99f20ae3fd00035947e70e1af6e98dd4b206 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.os;
18
19import java.io.PrintWriter;
Dianne Hackborne4a59512010-12-07 11:08:07 -080020import java.util.ArrayList;
Dianne Hackborn81038902012-11-26 17:04:09 -080021import java.util.Collections;
22import java.util.Comparator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import java.util.Formatter;
Dianne Hackborn37de0982014-05-09 09:32:18 -070024import java.util.HashMap;
Dianne Hackborne4a59512010-12-07 11:08:07 -080025import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import java.util.Map;
27
Dianne Hackborna7c837f2014-01-15 16:20:44 -080028import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080029import android.content.pm.ApplicationInfo;
Wink Saville52840902011-02-18 12:40:47 -080030import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080031import android.text.format.DateFormat;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070032import android.util.ArrayMap;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070033import android.util.MutableBoolean;
34import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.util.Printer;
36import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070037import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070038import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070039import android.view.Display;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080040import com.android.internal.os.BatterySipper;
41import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43/**
44 * A class providing access to battery usage statistics, including information on
45 * wakelocks, processes, packages, and services. All times are represented in microseconds
46 * except where indicated otherwise.
47 * @hide
48 */
49public abstract class BatteryStats implements Parcelable {
50
51 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070052
53 /** @hide */
54 public static final String SERVICE_NAME = "batterystats";
55
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 /**
57 * A constant indicating a partial wake lock timer.
58 */
59 public static final int WAKE_TYPE_PARTIAL = 0;
60
61 /**
62 * A constant indicating a full wake lock timer.
63 */
64 public static final int WAKE_TYPE_FULL = 1;
65
66 /**
67 * A constant indicating a window wake lock timer.
68 */
69 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 /**
72 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 */
74 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070075
76 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070077 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070078 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070079 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070080
81 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070082 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070083 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070084 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070085
86 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070087 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070088 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070089 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
Dianne Hackborn62793e42015-03-09 11:15:41 -070091 /**
92 * A constant indicating a wifi multicast timer
93 */
94 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070097 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070098 */
99 public static final int VIDEO_TURNED_ON = 8;
100
101 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800102 * A constant indicating a vibrator on timer
103 */
104 public static final int VIBRATOR_ON = 9;
105
106 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700107 * A constant indicating a foreground activity timer
108 */
109 public static final int FOREGROUND_ACTIVITY = 10;
110
111 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700112 * A constant indicating a wifi batched scan is active
113 */
114 public static final int WIFI_BATCHED_SCAN = 11;
115
116 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700117 * A constant indicating a process state timer
118 */
119 public static final int PROCESS_STATE = 12;
120
121 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700122 * A constant indicating a sync timer
123 */
124 public static final int SYNC = 13;
125
126 /**
127 * A constant indicating a job timer
128 */
129 public static final int JOB = 14;
130
131 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800132 * A constant indicating an audio turn on timer
133 */
134 public static final int AUDIO_TURNED_ON = 15;
135
136 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700137 * A constant indicating a flashlight turn on timer
138 */
139 public static final int FLASHLIGHT_TURNED_ON = 16;
140
141 /**
142 * A constant indicating a camera turn on timer
143 */
144 public static final int CAMERA_TURNED_ON = 17;
145
146 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700147 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700148 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700149 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700150
151 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800152 * A constant indicating a bluetooth scan timer.
153 */
154 public static final int BLUETOOTH_SCAN_ON = 19;
155
156 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 * Include all of the data in the stats, including previously saved data.
158 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700159 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160
161 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 * Include only the current run in the stats.
163 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700164 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165
166 /**
167 * Include only the run since the last time the device was unplugged in the stats.
168 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700169 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700170
171 // NOTE: Update this list if you add/change any stats above.
172 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700173 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700174 private static final String[] STAT_NAMES = { "l", "c", "u" };
175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700177 * Current version of checkin data format.
178 */
Adam Lesinskib55d7412016-06-09 17:46:19 -0700179 static final String CHECKIN_VERSION = "18";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700180
181 /**
182 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700184 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700185
Evan Millar22ac0432009-03-31 11:33:18 -0700186 private static final long BYTES_PER_KB = 1024;
187 private static final long BYTES_PER_MB = 1048576; // 1024^2
188 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700190 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800191 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700192 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700194 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700195 private static final String CPU_DATA = "cpu";
Evan Millare84de8d2009-04-02 22:16:12 -0700196 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800197 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700198 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700199 private static final String STATE_TIME_DATA = "st";
Evan Millare84de8d2009-04-02 22:16:12 -0700200 private static final String WAKELOCK_DATA = "wl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700201 private static final String SYNC_DATA = "sy";
202 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700203 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700204 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700205 private static final String NETWORK_DATA = "nt";
206 private static final String USER_ACTIVITY_DATA = "ua";
207 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800208 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700209 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700210 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700211 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800212 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
213 private static final String WIFI_CONTROLLER_DATA = "wfcd";
214 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
215 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700216 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700217 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800218 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800219 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
220 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800221 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700222 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700223 private static final String SCREEN_BRIGHTNESS_DATA = "br";
224 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700225 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700226 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
227 private static final String DATA_CONNECTION_TIME_DATA = "dct";
228 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800229 private static final String WIFI_STATE_TIME_DATA = "wst";
230 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700231 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
232 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
233 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
234 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800235 private static final String POWER_USE_SUMMARY_DATA = "pws";
236 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700237 private static final String DISCHARGE_STEP_DATA = "dsd";
238 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700239 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
240 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700241 private static final String FLASHLIGHT_DATA = "fla";
242 private static final String CAMERA_DATA = "cam";
243 private static final String VIDEO_DATA = "vid";
244 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245
Adam Lesinski010bf372016-04-11 12:18:18 -0700246 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
247
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700248 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 private final Formatter mFormatter = new Formatter(mFormatBuilder);
250
251 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700252 * State for keeping track of counting information.
253 */
254 public static abstract class Counter {
255
256 /**
257 * Returns the count associated with this Counter for the
258 * selected type of statistics.
259 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700260 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700261 */
Evan Millarc64edde2009-04-18 12:26:32 -0700262 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700263
264 /**
265 * Temporary for debugging.
266 */
267 public abstract void logState(Printer pw, String prefix);
268 }
269
270 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700271 * State for keeping track of long counting information.
272 */
273 public static abstract class LongCounter {
274
275 /**
276 * Returns the count associated with this Counter for the
277 * selected type of statistics.
278 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700279 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700280 */
281 public abstract long getCountLocked(int which);
282
283 /**
284 * Temporary for debugging.
285 */
286 public abstract void logState(Printer pw, String prefix);
287 }
288
289 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800290 * Container class that aggregates counters for transmit, receive, and idle state of a
291 * radio controller.
292 */
293 public static abstract class ControllerActivityCounter {
294 /**
295 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
296 * idle state.
297 */
298 public abstract LongCounter getIdleTimeCounter();
299
300 /**
301 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
302 * receive state.
303 */
304 public abstract LongCounter getRxTimeCounter();
305
306 /**
307 * An array of {@link LongCounter}, representing various transmit levels, where each level
308 * may draw a different amount of power. The levels themselves are controller-specific.
309 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
310 * various transmit level states.
311 */
312 public abstract LongCounter[] getTxTimeCounters();
313
314 /**
315 * @return a non-null {@link LongCounter} representing the power consumed by the controller
316 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
317 * yield a value of 0 if the device doesn't support power calculations.
318 */
319 public abstract LongCounter getPowerCounter();
320 }
321
322 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 * State for keeping track of timing information.
324 */
325 public static abstract class Timer {
326
327 /**
328 * Returns the count associated with this Timer for the
329 * selected type of statistics.
330 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700331 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 */
Evan Millarc64edde2009-04-18 12:26:32 -0700333 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334
335 /**
336 * Returns the total time in microseconds associated with this Timer for the
337 * selected type of statistics.
338 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800339 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700340 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 * @return a time in microseconds
342 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800343 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700346 * Returns the total time in microseconds associated with this Timer since the
347 * 'mark' was last set.
348 *
349 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
350 * @return a time in microseconds
351 */
352 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
353
354 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 * Temporary for debugging.
356 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700357 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 }
359
360 /**
361 * The statistics associated with a particular uid.
362 */
363 public static abstract class Uid {
364
365 /**
366 * Returns a mapping containing wakelock statistics.
367 *
368 * @return a Map from Strings to Uid.Wakelock objects.
369 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700370 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371
372 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700373 * Returns a mapping containing sync statistics.
374 *
375 * @return a Map from Strings to Timer objects.
376 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700377 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700378
379 /**
380 * Returns a mapping containing scheduled job statistics.
381 *
382 * @return a Map from Strings to Timer objects.
383 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700384 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700385
386 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 * The statistics associated with a particular wake lock.
388 */
389 public static abstract class Wakelock {
390 public abstract Timer getWakeTime(int type);
391 }
392
393 /**
394 * Returns a mapping containing sensor statistics.
395 *
396 * @return a Map from Integer sensor ids to Uid.Sensor objects.
397 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700398 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399
400 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700401 * Returns a mapping containing active process data.
402 */
403 public abstract SparseArray<? extends Pid> getPidStats();
404
405 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 * Returns a mapping containing process statistics.
407 *
408 * @return a Map from Strings to Uid.Proc objects.
409 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700410 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411
412 /**
413 * Returns a mapping containing package statistics.
414 *
415 * @return a Map from Strings to Uid.Pkg objects.
416 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700417 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700418
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800419 public abstract ControllerActivityCounter getWifiControllerActivity();
420 public abstract ControllerActivityCounter getBluetoothControllerActivity();
421 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800422
423 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 * {@hide}
425 */
426 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700427
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800428 public abstract void noteWifiRunningLocked(long elapsedRealtime);
429 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
430 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
431 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
432 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
433 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
434 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
435 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
436 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
437 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800438 public abstract void noteActivityResumedLocked(long elapsedRealtime);
439 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800440 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
441 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
442 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700443 public abstract int getWifiScanCount(int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800444 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700445 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800446 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700447 public abstract Timer getAudioTurnedOnTimer();
448 public abstract Timer getVideoTurnedOnTimer();
449 public abstract Timer getFlashlightTurnedOnTimer();
450 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700451 public abstract Timer getForegroundActivityTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800452 public abstract Timer getBluetoothScanTimer();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700453
Dianne Hackborna0200e32016-03-30 18:01:41 -0700454 // Note: the following times are disjoint. They can be added together to find the
455 // total time a uid has had any processes running at all.
456
457 /**
458 * Time this uid has any processes in the top state (or above such as persistent).
459 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800460 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700461 /**
462 * Time this uid has any process with a started out bound foreground service, but
463 * none in the "top" state.
464 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800465 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700466 /**
467 * Time this uid has any process that is top while the device is sleeping, but none
468 * in the "foreground service" or better state.
469 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800470 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700471 /**
472 * Time this uid has any process in an active foreground state, but none in the
473 * "top sleeping" or better state.
474 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800475 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700476 /**
477 * Time this uid has any process in an active background state, but none in the
478 * "foreground" or better state.
479 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800480 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700481 /**
482 * Time this uid has any processes that are sitting around cached, not in one of the
483 * other active states.
484 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800485 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700486 /**
487 * Total number of process states we track.
488 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800489 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700490
491 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800492 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700493 };
494
495 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800496 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700497
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800498 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499
Robert Greenwalta029ea12013-09-25 16:38:12 -0700500 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
501
Dianne Hackborn617f8772009-03-31 15:04:46 -0700502 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700503 * Note that these must match the constants in android.os.PowerManager.
504 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
505 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700506 */
507 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700508 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700509 };
510
Phil Weaverda80d672016-03-15 16:25:46 -0700511 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700512
Dianne Hackborn617f8772009-03-31 15:04:46 -0700513 public abstract void noteUserActivityLocked(int type);
514 public abstract boolean hasUserActivity();
515 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700516
517 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800518 public abstract long getNetworkActivityBytes(int type, int which);
519 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800520 public abstract long getMobileRadioActiveTime(int which);
521 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700522
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700523 /**
524 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
525 */
526 public abstract long getUserCpuTimeUs(int which);
527
528 /**
529 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
530 */
531 public abstract long getSystemCpuTimeUs(int which);
532
533 /**
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700534 * Get the total cpu power consumed (in milli-ampere-microseconds).
535 */
536 public abstract long getCpuPowerMaUs(int which);
537
538 /**
Adam Lesinski6832f392015-09-05 18:05:40 -0700539 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a
540 * given CPU cluster.
541 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700542 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700543 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700544 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
545 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700546 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700547 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700548
Adam Lesinski5f056f62016-07-14 16:56:08 -0700549 /**
550 * Returns the number of times this UID woke up the Application Processor to
551 * process a mobile radio packet.
552 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
553 */
554 public abstract long getMobileRadioApWakeupCount(int which);
555
556 /**
557 * Returns the number of times this UID woke up the Application Processor to
558 * process a WiFi packet.
559 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
560 */
561 public abstract long getWifiRadioApWakeupCount(int which);
562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800564 /*
565 * FIXME: it's not correct to use this magic value because it
566 * could clash with a sensor handle (which are defined by
567 * the sensor HAL, and therefore out of our control
568 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 // Magic sensor number for the GPS.
570 public static final int GPS = -10000;
571
572 public abstract int getHandle();
573
574 public abstract Timer getSensorTime();
575 }
576
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700577 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800578 public int mWakeNesting;
579 public long mWakeSumMs;
580 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700581 }
582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 /**
584 * The statistics associated with a particular process.
585 */
586 public static abstract class Proc {
587
Dianne Hackborn287952c2010-09-22 22:34:31 -0700588 public static class ExcessivePower {
589 public static final int TYPE_WAKE = 1;
590 public static final int TYPE_CPU = 2;
591
592 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700593 public long overTime;
594 public long usedTime;
595 }
596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800598 * Returns true if this process is still active in the battery stats.
599 */
600 public abstract boolean isActive();
601
602 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700603 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700605 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 */
607 public abstract long getUserTime(int which);
608
609 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700610 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700612 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 */
614 public abstract long getSystemTime(int which);
615
616 /**
617 * Returns the number of times the process has been started.
618 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700619 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 */
621 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700622
623 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800624 * Returns the number of times the process has crashed.
625 *
626 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
627 */
628 public abstract int getNumCrashes(int which);
629
630 /**
631 * Returns the number of times the process has ANRed.
632 *
633 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
634 */
635 public abstract int getNumAnrs(int which);
636
637 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700638 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700639 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700640 * @return foreground cpu time in microseconds
641 */
642 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700643
Dianne Hackborn287952c2010-09-22 22:34:31 -0700644 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700645
Dianne Hackborn287952c2010-09-22 22:34:31 -0700646 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 }
648
649 /**
650 * The statistics associated with a particular package.
651 */
652 public static abstract class Pkg {
653
654 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700655 * Returns information about all wakeup alarms that have been triggered for this
656 * package. The mapping keys are tag names for the alarms, the counter contains
657 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700659 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660
661 /**
662 * Returns a mapping containing service statistics.
663 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700664 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665
666 /**
667 * The statistics associated with a particular service.
668 */
Joe Onoratoabded112016-02-08 16:49:39 -0800669 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670
671 /**
672 * Returns the amount of time spent started.
673 *
674 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700675 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 * @return
677 */
678 public abstract long getStartTime(long batteryUptime, int which);
679
680 /**
681 * Returns the total number of times startService() has been called.
682 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700683 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 */
685 public abstract int getStarts(int which);
686
687 /**
688 * Returns the total number times the service has been launched.
689 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700690 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 */
692 public abstract int getLaunches(int which);
693 }
694 }
695 }
696
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800697 public static final class LevelStepTracker {
698 public long mLastStepTime = -1;
699 public int mNumStepDurations;
700 public final long[] mStepDurations;
701
702 public LevelStepTracker(int maxLevelSteps) {
703 mStepDurations = new long[maxLevelSteps];
704 }
705
706 public LevelStepTracker(int numSteps, long[] steps) {
707 mNumStepDurations = numSteps;
708 mStepDurations = new long[numSteps];
709 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
710 }
711
712 public long getDurationAt(int index) {
713 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
714 }
715
716 public int getLevelAt(int index) {
717 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
718 >> STEP_LEVEL_LEVEL_SHIFT);
719 }
720
721 public int getInitModeAt(int index) {
722 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
723 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
724 }
725
726 public int getModModeAt(int index) {
727 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
728 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
729 }
730
731 private void appendHex(long val, int topOffset, StringBuilder out) {
732 boolean hasData = false;
733 while (topOffset >= 0) {
734 int digit = (int)( (val>>topOffset) & 0xf );
735 topOffset -= 4;
736 if (!hasData && digit == 0) {
737 continue;
738 }
739 hasData = true;
740 if (digit >= 0 && digit <= 9) {
741 out.append((char)('0' + digit));
742 } else {
743 out.append((char)('a' + digit - 10));
744 }
745 }
746 }
747
748 public void encodeEntryAt(int index, StringBuilder out) {
749 long item = mStepDurations[index];
750 long duration = item & STEP_LEVEL_TIME_MASK;
751 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
752 >> STEP_LEVEL_LEVEL_SHIFT);
753 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
754 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
755 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
756 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
757 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
758 case Display.STATE_OFF: out.append('f'); break;
759 case Display.STATE_ON: out.append('o'); break;
760 case Display.STATE_DOZE: out.append('d'); break;
761 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
762 }
763 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
764 out.append('p');
765 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700766 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
767 out.append('i');
768 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800769 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
770 case Display.STATE_OFF: out.append('F'); break;
771 case Display.STATE_ON: out.append('O'); break;
772 case Display.STATE_DOZE: out.append('D'); break;
773 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
774 }
775 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
776 out.append('P');
777 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700778 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
779 out.append('I');
780 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800781 out.append('-');
782 appendHex(level, 4, out);
783 out.append('-');
784 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
785 }
786
787 public void decodeEntryAt(int index, String value) {
788 final int N = value.length();
789 int i = 0;
790 char c;
791 long out = 0;
792 while (i < N && (c=value.charAt(i)) != '-') {
793 i++;
794 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800795 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800796 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800797 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800798 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800799 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800800 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800801 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
802 << STEP_LEVEL_INITIAL_MODE_SHIFT);
803 break;
804 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
805 << STEP_LEVEL_INITIAL_MODE_SHIFT);
806 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700807 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
808 << STEP_LEVEL_INITIAL_MODE_SHIFT);
809 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800810 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
811 break;
812 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
813 break;
814 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
815 break;
816 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
817 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
818 break;
819 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
820 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800821 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700822 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
823 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
824 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800825 }
826 }
827 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800828 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800829 while (i < N && (c=value.charAt(i)) != '-') {
830 i++;
831 level <<= 4;
832 if (c >= '0' && c <= '9') {
833 level += c - '0';
834 } else if (c >= 'a' && c <= 'f') {
835 level += c - 'a' + 10;
836 } else if (c >= 'A' && c <= 'F') {
837 level += c - 'A' + 10;
838 }
839 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800840 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800841 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
842 long duration = 0;
843 while (i < N && (c=value.charAt(i)) != '-') {
844 i++;
845 duration <<= 4;
846 if (c >= '0' && c <= '9') {
847 duration += c - '0';
848 } else if (c >= 'a' && c <= 'f') {
849 duration += c - 'a' + 10;
850 } else if (c >= 'A' && c <= 'F') {
851 duration += c - 'A' + 10;
852 }
853 }
854 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
855 }
856
857 public void init() {
858 mLastStepTime = -1;
859 mNumStepDurations = 0;
860 }
861
862 public void clearTime() {
863 mLastStepTime = -1;
864 }
865
866 public long computeTimePerLevel() {
867 final long[] steps = mStepDurations;
868 final int numSteps = mNumStepDurations;
869
870 // For now we'll do a simple average across all steps.
871 if (numSteps <= 0) {
872 return -1;
873 }
874 long total = 0;
875 for (int i=0; i<numSteps; i++) {
876 total += steps[i] & STEP_LEVEL_TIME_MASK;
877 }
878 return total / numSteps;
879 /*
880 long[] buckets = new long[numSteps];
881 int numBuckets = 0;
882 int numToAverage = 4;
883 int i = 0;
884 while (i < numSteps) {
885 long totalTime = 0;
886 int num = 0;
887 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
888 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
889 num++;
890 }
891 buckets[numBuckets] = totalTime / num;
892 numBuckets++;
893 numToAverage *= 2;
894 i += num;
895 }
896 if (numBuckets < 1) {
897 return -1;
898 }
899 long averageTime = buckets[numBuckets-1];
900 for (i=numBuckets-2; i>=0; i--) {
901 averageTime = (averageTime + buckets[i]) / 2;
902 }
903 return averageTime;
904 */
905 }
906
907 public long computeTimeEstimate(long modesOfInterest, long modeValues,
908 int[] outNumOfInterest) {
909 final long[] steps = mStepDurations;
910 final int count = mNumStepDurations;
911 if (count <= 0) {
912 return -1;
913 }
914 long total = 0;
915 int numOfInterest = 0;
916 for (int i=0; i<count; i++) {
917 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
918 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
919 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
920 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
921 // If the modes of interest didn't change during this step period...
922 if ((modMode&modesOfInterest) == 0) {
923 // And the mode values during this period match those we are measuring...
924 if ((initMode&modesOfInterest) == modeValues) {
925 // Then this can be used to estimate the total time!
926 numOfInterest++;
927 total += steps[i] & STEP_LEVEL_TIME_MASK;
928 }
929 }
930 }
931 if (numOfInterest <= 0) {
932 return -1;
933 }
934
935 if (outNumOfInterest != null) {
936 outNumOfInterest[0] = numOfInterest;
937 }
938
939 // The estimated time is the average time we spend in each level, multipled
940 // by 100 -- the total number of battery levels
941 return (total / numOfInterest) * 100;
942 }
943
944 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
945 int stepCount = mNumStepDurations;
946 final long lastStepTime = mLastStepTime;
947 if (lastStepTime >= 0 && numStepLevels > 0) {
948 final long[] steps = mStepDurations;
949 long duration = elapsedRealtime - lastStepTime;
950 for (int i=0; i<numStepLevels; i++) {
951 System.arraycopy(steps, 0, steps, 1, steps.length-1);
952 long thisDuration = duration / (numStepLevels-i);
953 duration -= thisDuration;
954 if (thisDuration > STEP_LEVEL_TIME_MASK) {
955 thisDuration = STEP_LEVEL_TIME_MASK;
956 }
957 steps[0] = thisDuration | modeBits;
958 }
959 stepCount += numStepLevels;
960 if (stepCount > steps.length) {
961 stepCount = steps.length;
962 }
963 }
964 mNumStepDurations = stepCount;
965 mLastStepTime = elapsedRealtime;
966 }
967
968 public void readFromParcel(Parcel in) {
969 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -0700970 if (N > mStepDurations.length) {
971 throw new ParcelFormatException("more step durations than available: " + N);
972 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800973 mNumStepDurations = N;
974 for (int i=0; i<N; i++) {
975 mStepDurations[i] = in.readLong();
976 }
977 }
978
979 public void writeToParcel(Parcel out) {
980 final int N = mNumStepDurations;
981 out.writeInt(N);
982 for (int i=0; i<N; i++) {
983 out.writeLong(mStepDurations[i]);
984 }
985 }
986 }
987
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700988 public static final class PackageChange {
989 public String mPackageName;
990 public boolean mUpdate;
991 public int mVersionCode;
992 }
993
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800994 public static final class DailyItem {
995 public long mStartTime;
996 public long mEndTime;
997 public LevelStepTracker mDischargeSteps;
998 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700999 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001000 }
1001
1002 public abstract DailyItem getDailyItemLocked(int daysAgo);
1003
1004 public abstract long getCurrentDailyStartTime();
1005
1006 public abstract long getNextMinDailyDeadline();
1007
1008 public abstract long getNextMaxDailyDeadline();
1009
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001010 public final static class HistoryTag {
1011 public String string;
1012 public int uid;
1013
1014 public int poolIdx;
1015
1016 public void setTo(HistoryTag o) {
1017 string = o.string;
1018 uid = o.uid;
1019 poolIdx = o.poolIdx;
1020 }
1021
1022 public void setTo(String _string, int _uid) {
1023 string = _string;
1024 uid = _uid;
1025 poolIdx = -1;
1026 }
1027
1028 public void writeToParcel(Parcel dest, int flags) {
1029 dest.writeString(string);
1030 dest.writeInt(uid);
1031 }
1032
1033 public void readFromParcel(Parcel src) {
1034 string = src.readString();
1035 uid = src.readInt();
1036 poolIdx = -1;
1037 }
1038
1039 @Override
1040 public boolean equals(Object o) {
1041 if (this == o) return true;
1042 if (o == null || getClass() != o.getClass()) return false;
1043
1044 HistoryTag that = (HistoryTag) o;
1045
1046 if (uid != that.uid) return false;
1047 if (!string.equals(that.string)) return false;
1048
1049 return true;
1050 }
1051
1052 @Override
1053 public int hashCode() {
1054 int result = string.hashCode();
1055 result = 31 * result + uid;
1056 return result;
1057 }
1058 }
1059
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001060 /**
1061 * Optional detailed information that can go into a history step. This is typically
1062 * generated each time the battery level changes.
1063 */
1064 public final static class HistoryStepDetails {
1065 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1066 public int userTime;
1067 public int systemTime;
1068
1069 // Top three apps using CPU in the last step, with times in 1/100 second.
1070 public int appCpuUid1;
1071 public int appCpuUTime1;
1072 public int appCpuSTime1;
1073 public int appCpuUid2;
1074 public int appCpuUTime2;
1075 public int appCpuSTime2;
1076 public int appCpuUid3;
1077 public int appCpuUTime3;
1078 public int appCpuSTime3;
1079
1080 // Information from /proc/stat
1081 public int statUserTime;
1082 public int statSystemTime;
1083 public int statIOWaitTime;
1084 public int statIrqTime;
1085 public int statSoftIrqTime;
1086 public int statIdlTime;
1087
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001088 // Platform-level low power state stats
1089 public String statPlatformIdleState;
1090
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001091 public HistoryStepDetails() {
1092 clear();
1093 }
1094
1095 public void clear() {
1096 userTime = systemTime = 0;
1097 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1098 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1099 = appCpuUTime3 = appCpuSTime3 = 0;
1100 }
1101
1102 public void writeToParcel(Parcel out) {
1103 out.writeInt(userTime);
1104 out.writeInt(systemTime);
1105 out.writeInt(appCpuUid1);
1106 out.writeInt(appCpuUTime1);
1107 out.writeInt(appCpuSTime1);
1108 out.writeInt(appCpuUid2);
1109 out.writeInt(appCpuUTime2);
1110 out.writeInt(appCpuSTime2);
1111 out.writeInt(appCpuUid3);
1112 out.writeInt(appCpuUTime3);
1113 out.writeInt(appCpuSTime3);
1114 out.writeInt(statUserTime);
1115 out.writeInt(statSystemTime);
1116 out.writeInt(statIOWaitTime);
1117 out.writeInt(statIrqTime);
1118 out.writeInt(statSoftIrqTime);
1119 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001120 out.writeString(statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001121 }
1122
1123 public void readFromParcel(Parcel in) {
1124 userTime = in.readInt();
1125 systemTime = in.readInt();
1126 appCpuUid1 = in.readInt();
1127 appCpuUTime1 = in.readInt();
1128 appCpuSTime1 = in.readInt();
1129 appCpuUid2 = in.readInt();
1130 appCpuUTime2 = in.readInt();
1131 appCpuSTime2 = in.readInt();
1132 appCpuUid3 = in.readInt();
1133 appCpuUTime3 = in.readInt();
1134 appCpuSTime3 = in.readInt();
1135 statUserTime = in.readInt();
1136 statSystemTime = in.readInt();
1137 statIOWaitTime = in.readInt();
1138 statIrqTime = in.readInt();
1139 statSoftIrqTime = in.readInt();
1140 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001141 statPlatformIdleState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001142 }
1143 }
1144
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001145 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001146 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001147
1148 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001149 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001150
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001151 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001152 public static final byte CMD_NULL = -1;
1153 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001154 public static final byte CMD_CURRENT_TIME = 5;
1155 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001156 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001157 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001158
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001159 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001160
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001161 /**
1162 * Return whether the command code is a delta data update.
1163 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001164 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001165 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001166 }
1167
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001168 public byte batteryLevel;
1169 public byte batteryStatus;
1170 public byte batteryHealth;
1171 public byte batteryPlugType;
1172
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001173 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001174 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001175
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001176 // The charge of the battery in micro-Ampere-hours.
1177 public int batteryChargeUAh;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001178
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001179 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001180 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001181 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001182 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001183 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1184 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001185 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001186 public static final int STATE_PHONE_STATE_SHIFT = 6;
1187 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001188 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001189 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001190 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001191
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001192 // These states always appear directly in the first int token
1193 // of a delta change; they should be ones that change relatively
1194 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001195 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1196 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001197 public static final int STATE_GPS_ON_FLAG = 1<<29;
1198 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001199 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001200 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001201 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001202 // Do not use, this is used for coulomb delta count.
1203 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001204 // These are on the lower bits used for the command; if they change
1205 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001206 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001207 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001208 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001209 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1210 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1211 // empty slot
1212 // empty slot
1213 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001214
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001215 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001216 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1217
1218 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001219
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001220 public int states;
1221
Dianne Hackborn3251b902014-06-20 14:40:53 -07001222 // Constants from WIFI_SUPPL_STATE_*
1223 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1224 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1225 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1226 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1227 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1228 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1229
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001230 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001231 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1232 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1233 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001234 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001235 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1236 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1237 public static final int STATE2_CHARGING_FLAG = 1<<24;
1238 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1239 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1240 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001241 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001242
1243 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001244 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001245 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1246
1247 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001248
Dianne Hackborn40c87252014-03-19 16:55:40 -07001249 public int states2;
1250
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001251 // The wake lock that was acquired at this point.
1252 public HistoryTag wakelockTag;
1253
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001254 // Kernel wakeup reason at this point.
1255 public HistoryTag wakeReasonTag;
1256
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001257 // Non-null when there is more detailed information at this step.
1258 public HistoryStepDetails stepDetails;
1259
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001260 public static final int EVENT_FLAG_START = 0x8000;
1261 public static final int EVENT_FLAG_FINISH = 0x4000;
1262
1263 // No event in this item.
1264 public static final int EVENT_NONE = 0x0000;
1265 // Event is about a process that is running.
1266 public static final int EVENT_PROC = 0x0001;
1267 // Event is about an application package that is in the foreground.
1268 public static final int EVENT_FOREGROUND = 0x0002;
1269 // Event is about an application package that is at the top of the screen.
1270 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001271 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001272 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001273 // Events for all additional wake locks aquired/release within a wake block.
1274 // These are not generated by default.
1275 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001276 // Event is about an application executing a scheduled job.
1277 public static final int EVENT_JOB = 0x0006;
1278 // Events for users running.
1279 public static final int EVENT_USER_RUNNING = 0x0007;
1280 // Events for foreground user.
1281 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001282 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001283 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001284 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001285 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001286 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001287 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001288 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001289 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001290 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001291 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001292 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001293 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001294 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001295 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001296 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001297 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001298 // Event for a package being on the temporary whitelist.
1299 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001300 // Event for the screen waking up.
1301 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001302 // Event for the UID that woke up the application processor.
1303 // Used for wakeups coming from WiFi, modem, etc.
1304 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001305 // Event for reporting that a specific partial wake lock has been held for a long duration.
1306 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001307
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001308 // Number of event types.
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001309 public static final int EVENT_COUNT = 0x0015;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001310 // Mask to extract out only the type part of the event.
1311 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001312
1313 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1314 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1315 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1316 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1317 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1318 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001319 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1320 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001321 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1322 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001323 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1324 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1325 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1326 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1327 public static final int EVENT_USER_FOREGROUND_START =
1328 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1329 public static final int EVENT_USER_FOREGROUND_FINISH =
1330 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001331 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1332 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001333 public static final int EVENT_TEMP_WHITELIST_START =
1334 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1335 public static final int EVENT_TEMP_WHITELIST_FINISH =
1336 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001337 public static final int EVENT_LONG_WAKE_LOCK_START =
1338 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1339 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1340 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001341
1342 // For CMD_EVENT.
1343 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001344 public HistoryTag eventTag;
1345
Dianne Hackborn9a755432014-05-15 17:05:22 -07001346 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001347 public long currentTime;
1348
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001349 // Meta-data when reading.
1350 public int numReadInts;
1351
1352 // Pre-allocated objects.
1353 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001354 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001355 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001356
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001357 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001358 }
1359
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001360 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001361 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001362 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001363 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001364 }
1365
1366 public int describeContents() {
1367 return 0;
1368 }
1369
1370 public void writeToParcel(Parcel dest, int flags) {
1371 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001372 int bat = (((int)cmd)&0xff)
1373 | ((((int)batteryLevel)<<8)&0xff00)
1374 | ((((int)batteryStatus)<<16)&0xf0000)
1375 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001376 | ((((int)batteryPlugType)<<24)&0xf000000)
1377 | (wakelockTag != null ? 0x10000000 : 0)
1378 | (wakeReasonTag != null ? 0x20000000 : 0)
1379 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001380 dest.writeInt(bat);
1381 bat = (((int)batteryTemperature)&0xffff)
1382 | ((((int)batteryVoltage)<<16)&0xffff0000);
1383 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001384 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001385 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001386 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001387 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001388 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001389 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001390 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001391 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001392 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001393 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001394 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001395 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001396 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001397 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001398 dest.writeLong(currentTime);
1399 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001400 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001401
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001402 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001403 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001404 int bat = src.readInt();
1405 cmd = (byte)(bat&0xff);
1406 batteryLevel = (byte)((bat>>8)&0xff);
1407 batteryStatus = (byte)((bat>>16)&0xf);
1408 batteryHealth = (byte)((bat>>20)&0xf);
1409 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001410 int bat2 = src.readInt();
1411 batteryTemperature = (short)(bat2&0xffff);
1412 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001413 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001414 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001415 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001416 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001417 wakelockTag = localWakelockTag;
1418 wakelockTag.readFromParcel(src);
1419 } else {
1420 wakelockTag = null;
1421 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001422 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001423 wakeReasonTag = localWakeReasonTag;
1424 wakeReasonTag.readFromParcel(src);
1425 } else {
1426 wakeReasonTag = null;
1427 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001428 if ((bat&0x40000000) != 0) {
1429 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001430 eventTag = localEventTag;
1431 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001432 } else {
1433 eventCode = EVENT_NONE;
1434 eventTag = null;
1435 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001436 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001437 currentTime = src.readLong();
1438 } else {
1439 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001440 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001441 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001442 }
1443
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001444 public void clear() {
1445 time = 0;
1446 cmd = CMD_NULL;
1447 batteryLevel = 0;
1448 batteryStatus = 0;
1449 batteryHealth = 0;
1450 batteryPlugType = 0;
1451 batteryTemperature = 0;
1452 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001453 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001454 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001455 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001456 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001457 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001458 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001459 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001460 }
1461
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001462 public void setTo(HistoryItem o) {
1463 time = o.time;
1464 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001465 setToCommon(o);
1466 }
1467
1468 public void setTo(long time, byte cmd, HistoryItem o) {
1469 this.time = time;
1470 this.cmd = cmd;
1471 setToCommon(o);
1472 }
1473
1474 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001475 batteryLevel = o.batteryLevel;
1476 batteryStatus = o.batteryStatus;
1477 batteryHealth = o.batteryHealth;
1478 batteryPlugType = o.batteryPlugType;
1479 batteryTemperature = o.batteryTemperature;
1480 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001481 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001482 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001483 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001484 if (o.wakelockTag != null) {
1485 wakelockTag = localWakelockTag;
1486 wakelockTag.setTo(o.wakelockTag);
1487 } else {
1488 wakelockTag = null;
1489 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001490 if (o.wakeReasonTag != null) {
1491 wakeReasonTag = localWakeReasonTag;
1492 wakeReasonTag.setTo(o.wakeReasonTag);
1493 } else {
1494 wakeReasonTag = null;
1495 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001496 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001497 if (o.eventTag != null) {
1498 eventTag = localEventTag;
1499 eventTag.setTo(o.eventTag);
1500 } else {
1501 eventTag = null;
1502 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001503 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001504 }
1505
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001506 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001507 return batteryLevel == o.batteryLevel
1508 && batteryStatus == o.batteryStatus
1509 && batteryHealth == o.batteryHealth
1510 && batteryPlugType == o.batteryPlugType
1511 && batteryTemperature == o.batteryTemperature
1512 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001513 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001514 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001515 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001516 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001517 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001518
1519 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001520 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001521 return false;
1522 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001523 if (wakelockTag != o.wakelockTag) {
1524 if (wakelockTag == null || o.wakelockTag == null) {
1525 return false;
1526 }
1527 if (!wakelockTag.equals(o.wakelockTag)) {
1528 return false;
1529 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001530 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001531 if (wakeReasonTag != o.wakeReasonTag) {
1532 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1533 return false;
1534 }
1535 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1536 return false;
1537 }
1538 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001539 if (eventTag != o.eventTag) {
1540 if (eventTag == null || o.eventTag == null) {
1541 return false;
1542 }
1543 if (!eventTag.equals(o.eventTag)) {
1544 return false;
1545 }
1546 }
1547 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001548 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001549 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001550
1551 public final static class HistoryEventTracker {
1552 private final HashMap<String, SparseIntArray>[] mActiveEvents
1553 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1554
1555 public boolean updateState(int code, String name, int uid, int poolIdx) {
1556 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1557 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1558 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1559 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001560 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001561 mActiveEvents[idx] = active;
1562 }
1563 SparseIntArray uids = active.get(name);
1564 if (uids == null) {
1565 uids = new SparseIntArray();
1566 active.put(name, uids);
1567 }
1568 if (uids.indexOfKey(uid) >= 0) {
1569 // Already set, nothing to do!
1570 return false;
1571 }
1572 uids.put(uid, poolIdx);
1573 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1574 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1575 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1576 if (active == null) {
1577 // not currently active, nothing to do.
1578 return false;
1579 }
1580 SparseIntArray uids = active.get(name);
1581 if (uids == null) {
1582 // not currently active, nothing to do.
1583 return false;
1584 }
1585 idx = uids.indexOfKey(uid);
1586 if (idx < 0) {
1587 // not currently active, nothing to do.
1588 return false;
1589 }
1590 uids.removeAt(idx);
1591 if (uids.size() <= 0) {
1592 active.remove(name);
1593 }
1594 }
1595 return true;
1596 }
1597
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001598 public void removeEvents(int code) {
1599 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1600 mActiveEvents[idx] = null;
1601 }
1602
Dianne Hackborn37de0982014-05-09 09:32:18 -07001603 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1604 return mActiveEvents[code];
1605 }
1606 }
1607
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001608 public static final class BitDescription {
1609 public final int mask;
1610 public final int shift;
1611 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001612 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001613 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001614 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001615
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001616 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001617 this.mask = mask;
1618 this.shift = -1;
1619 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001620 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001621 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001622 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001623 }
1624
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001625 public BitDescription(int mask, int shift, String name, String shortName,
1626 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001627 this.mask = mask;
1628 this.shift = shift;
1629 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001630 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001631 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001632 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001633 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001634 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001635
Dianne Hackbornfc064132014-06-02 12:42:12 -07001636 /**
1637 * Don't allow any more batching in to the current history event. This
1638 * is called when printing partial histories, so to ensure that the next
1639 * history event will go in to a new batch after what was printed in the
1640 * last partial history.
1641 */
1642 public abstract void commitCurrentHistoryBatchLocked();
1643
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001644 public abstract int getHistoryTotalSize();
1645
1646 public abstract int getHistoryUsedSize();
1647
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001648 public abstract boolean startIteratingHistoryLocked();
1649
Dianne Hackborn099bc622014-01-22 13:39:16 -08001650 public abstract int getHistoryStringPoolSize();
1651
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001652 public abstract int getHistoryStringPoolBytes();
1653
1654 public abstract String getHistoryTagPoolString(int index);
1655
1656 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001657
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001658 public abstract boolean getNextHistoryLocked(HistoryItem out);
1659
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001660 public abstract void finishIteratingHistoryLocked();
1661
1662 public abstract boolean startIteratingOldHistoryLocked();
1663
1664 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1665
1666 public abstract void finishIteratingOldHistoryLocked();
1667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001669 * Return the base time offset for the battery history.
1670 */
1671 public abstract long getHistoryBaseTime();
1672
1673 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 * Returns the number of times the device has been started.
1675 */
1676 public abstract int getStartCount();
1677
1678 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001679 * 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 -08001680 * running on battery.
1681 *
1682 * {@hide}
1683 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001684 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001685
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001686 /**
1687 * Returns the number of times the screen was turned on.
1688 *
1689 * {@hide}
1690 */
1691 public abstract int getScreenOnCount(int which);
1692
Jeff Browne95c3cd2014-05-02 16:59:26 -07001693 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1694
Dianne Hackborn617f8772009-03-31 15:04:46 -07001695 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1696 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1697 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1698 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1699 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1700
1701 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1702 "dark", "dim", "medium", "light", "bright"
1703 };
1704
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001705 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1706 "0", "1", "2", "3", "4"
1707 };
1708
Dianne Hackborn617f8772009-03-31 15:04:46 -07001709 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001710
Dianne Hackborn617f8772009-03-31 15:04:46 -07001711 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001712 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001713 * the given brightness
1714 *
1715 * {@hide}
1716 */
1717 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001718 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001721 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001722 * running on battery.
1723 *
1724 * {@hide}
1725 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001726 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001727
1728 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001729 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001730 *
1731 * {@hide}
1732 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001733 public abstract int getPowerSaveModeEnabledCount(int which);
1734
1735 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001736 * Constant for device idle mode: not active.
1737 */
1738 public static final int DEVICE_IDLE_MODE_OFF = 0;
1739
1740 /**
1741 * Constant for device idle mode: active in lightweight mode.
1742 */
1743 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1744
1745 /**
1746 * Constant for device idle mode: active in full mode.
1747 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001748 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001749
1750 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001751 * Returns the time in microseconds that device has been in idle mode while
1752 * running on battery.
1753 *
1754 * {@hide}
1755 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001756 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001757
1758 /**
1759 * Returns the number of times that the devie has gone in to idle mode.
1760 *
1761 * {@hide}
1762 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001763 public abstract int getDeviceIdleModeCount(int mode, int which);
1764
1765 /**
1766 * Return the longest duration we spent in a particular device idle mode (fully in the
1767 * mode, not in idle maintenance etc).
1768 */
1769 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001770
1771 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001772 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001773 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001774 * counts all of the time that we consider the device to be idle, whether or not
1775 * it is currently in the actual device idle mode.
1776 *
1777 * {@hide}
1778 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001779 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001780
1781 /**
1782 * Returns the number of times that the devie has started idling.
1783 *
1784 * {@hide}
1785 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001786 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001787
1788 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001789 * Returns the number of times that connectivity state changed.
1790 *
1791 * {@hide}
1792 */
1793 public abstract int getNumConnectivityChange(int which);
1794
1795 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001796 * 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 -08001797 * running on battery.
1798 *
1799 * {@hide}
1800 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001801 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001802
1803 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001804 * Returns the number of times a phone call was activated.
1805 *
1806 * {@hide}
1807 */
1808 public abstract int getPhoneOnCount(int which);
1809
1810 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001811 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001812 * the given signal strength.
1813 *
1814 * {@hide}
1815 */
1816 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001817 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001818
Dianne Hackborn617f8772009-03-31 15:04:46 -07001819 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001820 * Returns the time in microseconds that the phone has been trying to
1821 * acquire a signal.
1822 *
1823 * {@hide}
1824 */
1825 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001826 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001827
1828 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001829 * Returns the number of times the phone has entered the given signal strength.
1830 *
1831 * {@hide}
1832 */
1833 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1834
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001835 /**
1836 * Returns the time in microseconds that the mobile network has been active
1837 * (in a high power state).
1838 *
1839 * {@hide}
1840 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001841 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001842
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001843 /**
1844 * Returns the number of times that the mobile network has transitioned to the
1845 * active state.
1846 *
1847 * {@hide}
1848 */
1849 public abstract int getMobileRadioActiveCount(int which);
1850
1851 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001852 * Returns the time in microseconds that is the difference between the mobile radio
1853 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1854 * from the radio.
1855 *
1856 * {@hide}
1857 */
1858 public abstract long getMobileRadioActiveAdjustedTime(int which);
1859
1860 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001861 * Returns the time in microseconds that the mobile network has been active
1862 * (in a high power state) but not being able to blame on an app.
1863 *
1864 * {@hide}
1865 */
1866 public abstract long getMobileRadioActiveUnknownTime(int which);
1867
1868 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001869 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001870 *
1871 * {@hide}
1872 */
1873 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001874
Dianne Hackborn627bba72009-03-24 22:32:56 -07001875 public static final int DATA_CONNECTION_NONE = 0;
1876 public static final int DATA_CONNECTION_GPRS = 1;
1877 public static final int DATA_CONNECTION_EDGE = 2;
1878 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001879 public static final int DATA_CONNECTION_CDMA = 4;
1880 public static final int DATA_CONNECTION_EVDO_0 = 5;
1881 public static final int DATA_CONNECTION_EVDO_A = 6;
1882 public static final int DATA_CONNECTION_1xRTT = 7;
1883 public static final int DATA_CONNECTION_HSDPA = 8;
1884 public static final int DATA_CONNECTION_HSUPA = 9;
1885 public static final int DATA_CONNECTION_HSPA = 10;
1886 public static final int DATA_CONNECTION_IDEN = 11;
1887 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001888 public static final int DATA_CONNECTION_LTE = 13;
1889 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001890 public static final int DATA_CONNECTION_HSPAP = 15;
1891 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001892
Dianne Hackborn627bba72009-03-24 22:32:56 -07001893 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001894 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001895 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001896 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001897 };
1898
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001899 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001900
1901 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001902 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001903 * the given data connection.
1904 *
1905 * {@hide}
1906 */
1907 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001908 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001911 * Returns the number of times the phone has entered the given data
1912 * connection type.
1913 *
1914 * {@hide}
1915 */
1916 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001917
Dianne Hackborn3251b902014-06-20 14:40:53 -07001918 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1919 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1920 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1921 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1922 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1923 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1924 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1925 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1926 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1927 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1928 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1929 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1930 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1931
1932 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1933
1934 static final String[] WIFI_SUPPL_STATE_NAMES = {
1935 "invalid", "disconn", "disabled", "inactive", "scanning",
1936 "authenticating", "associating", "associated", "4-way-handshake",
1937 "group-handshake", "completed", "dormant", "uninit"
1938 };
1939
1940 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1941 "inv", "dsc", "dis", "inact", "scan",
1942 "auth", "ascing", "asced", "4-way",
1943 "group", "compl", "dorm", "uninit"
1944 };
1945
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001946 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1947 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001948 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001949 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1950 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001951 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001952 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1953 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1954 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001955 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001956 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001957 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001958 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001959 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1960 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001961 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1962 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1963 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1964 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1965 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1966 new String[] {"in", "out", "emergency", "off"},
1967 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001968 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1969 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1970 SignalStrength.SIGNAL_STRENGTH_NAMES,
1971 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001972 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1973 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1974 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001975 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001976
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001977 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1978 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001979 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001980 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001981 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001982 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001983 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001984 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
1985 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
1986 new String[] { "off", "light", "full", "???" },
1987 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001988 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
1989 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
1990 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001991 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1992 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1993 new String[] { "0", "1", "2", "3", "4" },
1994 new String[] { "0", "1", "2", "3", "4" }),
1995 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1996 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1997 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07001998 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001999 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002000 };
2001
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002002 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002003 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002004 "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist",
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07002005 "screenwake", "wakeupap", "longwake"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002006 };
2007
2008 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002009 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002010 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07002011 "Esw", "Ewa", "Elw"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002012 };
2013
Dianne Hackborn617f8772009-03-31 15:04:46 -07002014 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002015 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002016 * running on battery.
2017 *
2018 * {@hide}
2019 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002020 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002021
2022 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002023 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002024 * been in the running state while the device was running on battery.
2025 *
2026 * {@hide}
2027 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002028 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002029
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002030 public static final int WIFI_STATE_OFF = 0;
2031 public static final int WIFI_STATE_OFF_SCANNING = 1;
2032 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2033 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2034 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2035 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2036 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2037 public static final int WIFI_STATE_SOFT_AP = 7;
2038
2039 static final String[] WIFI_STATE_NAMES = {
2040 "off", "scanning", "no_net", "disconn",
2041 "sta", "p2p", "sta_p2p", "soft_ap"
2042 };
2043
2044 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2045
2046 /**
2047 * Returns the time in microseconds that WiFi has been running in the given state.
2048 *
2049 * {@hide}
2050 */
2051 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002052 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002053
2054 /**
2055 * Returns the number of times that WiFi has entered the given state.
2056 *
2057 * {@hide}
2058 */
2059 public abstract int getWifiStateCount(int wifiState, int which);
2060
The Android Open Source Project10592532009-03-18 17:39:46 -07002061 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002062 * Returns the time in microseconds that the wifi supplicant has been
2063 * in a given state.
2064 *
2065 * {@hide}
2066 */
2067 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2068
2069 /**
2070 * Returns the number of times that the wifi supplicant has transitioned
2071 * to a given state.
2072 *
2073 * {@hide}
2074 */
2075 public abstract int getWifiSupplStateCount(int state, int which);
2076
2077 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2078
2079 /**
2080 * Returns the time in microseconds that WIFI has been running with
2081 * the given signal strength.
2082 *
2083 * {@hide}
2084 */
2085 public abstract long getWifiSignalStrengthTime(int strengthBin,
2086 long elapsedRealtimeUs, int which);
2087
2088 /**
2089 * Returns the number of times WIFI has entered the given signal strength.
2090 *
2091 * {@hide}
2092 */
2093 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2094
2095 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002096 * Returns the time in microseconds that the flashlight has been on while the device was
2097 * running on battery.
2098 *
2099 * {@hide}
2100 */
2101 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2102
2103 /**
2104 * Returns the number of times that the flashlight has been turned on while the device was
2105 * running on battery.
2106 *
2107 * {@hide}
2108 */
2109 public abstract long getFlashlightOnCount(int which);
2110
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002111 /**
2112 * Returns the time in microseconds that the camera has been on while the device was
2113 * running on battery.
2114 *
2115 * {@hide}
2116 */
2117 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2118
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002119 /**
2120 * Returns the time in microseconds that bluetooth scans were running while the device was
2121 * on battery.
2122 *
2123 * {@hide}
2124 */
2125 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002126
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002127 public static final int NETWORK_MOBILE_RX_DATA = 0;
2128 public static final int NETWORK_MOBILE_TX_DATA = 1;
2129 public static final int NETWORK_WIFI_RX_DATA = 2;
2130 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002131 public static final int NETWORK_BT_RX_DATA = 4;
2132 public static final int NETWORK_BT_TX_DATA = 5;
2133 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_BT_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002134
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002135 public abstract long getNetworkActivityBytes(int type, int which);
2136 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002137
Adam Lesinskie08af192015-03-25 16:42:59 -07002138 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002139 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002140 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002141 * actual power data.
2142 */
2143 public abstract boolean hasWifiActivityReporting();
2144
2145 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002146 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2147 * in various radio controller states, such as transmit, receive, and idle.
2148 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002149 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002150 public abstract ControllerActivityCounter getWifiControllerActivity();
2151
2152 /**
2153 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2154 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2155 * actual power data.
2156 */
2157 public abstract boolean hasBluetoothActivityReporting();
2158
2159 /**
2160 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2161 * in various radio controller states, such as transmit, receive, and idle.
2162 * @return non-null {@link ControllerActivityCounter}
2163 */
2164 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2165
2166 /**
2167 * Returns true if the BatteryStats object has detailed modem power reports.
2168 * When true, calling {@link #getModemControllerActivity()} will yield the
2169 * actual power data.
2170 */
2171 public abstract boolean hasModemActivityReporting();
2172
2173 /**
2174 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2175 * in various radio controller states, such as transmit, receive, and idle.
2176 * @return non-null {@link ControllerActivityCounter}
2177 */
2178 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002179
The Android Open Source Project10592532009-03-18 17:39:46 -07002180 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002181 * Return the wall clock time when battery stats data collection started.
2182 */
2183 public abstract long getStartClockTime();
2184
2185 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002186 * Return platform version tag that we were running in when the battery stats started.
2187 */
2188 public abstract String getStartPlatformVersion();
2189
2190 /**
2191 * Return platform version tag that we were running in when the battery stats ended.
2192 */
2193 public abstract String getEndPlatformVersion();
2194
2195 /**
2196 * Return the internal version code of the parcelled format.
2197 */
2198 public abstract int getParcelVersion();
2199
2200 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 * Return whether we are currently running on battery.
2202 */
2203 public abstract boolean getIsOnBattery();
2204
2205 /**
2206 * Returns a SparseArray containing the statistics for each uid.
2207 */
2208 public abstract SparseArray<? extends Uid> getUidStats();
2209
2210 /**
2211 * Returns the current battery uptime in microseconds.
2212 *
2213 * @param curTime the amount of elapsed realtime in microseconds.
2214 */
2215 public abstract long getBatteryUptime(long curTime);
2216
2217 /**
2218 * Returns the current battery realtime in microseconds.
2219 *
2220 * @param curTime the amount of elapsed realtime in microseconds.
2221 */
2222 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07002223
2224 /**
Evan Millar633a1742009-04-02 16:36:33 -07002225 * Returns the battery percentage level at the last time the device was unplugged from power, or
2226 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002227 */
Evan Millar633a1742009-04-02 16:36:33 -07002228 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07002229
2230 /**
Evan Millar633a1742009-04-02 16:36:33 -07002231 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2232 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002233 */
Evan Millar633a1742009-04-02 16:36:33 -07002234 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002235
2236 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002237 * Get the amount the battery has discharged since the stats were
2238 * last reset after charging, as a lower-end approximation.
2239 */
2240 public abstract int getLowDischargeAmountSinceCharge();
2241
2242 /**
2243 * Get the amount the battery has discharged since the stats were
2244 * last reset after charging, as an upper-end approximation.
2245 */
2246 public abstract int getHighDischargeAmountSinceCharge();
2247
2248 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002249 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2250 */
2251 public abstract int getDischargeAmount(int which);
2252
2253 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002254 * Get the amount the battery has discharged while the screen was on,
2255 * since the last time power was unplugged.
2256 */
2257 public abstract int getDischargeAmountScreenOn();
2258
2259 /**
2260 * Get the amount the battery has discharged while the screen was on,
2261 * since the last time the device was charged.
2262 */
2263 public abstract int getDischargeAmountScreenOnSinceCharge();
2264
2265 /**
2266 * Get the amount the battery has discharged while the screen was off,
2267 * since the last time power was unplugged.
2268 */
2269 public abstract int getDischargeAmountScreenOff();
2270
2271 /**
2272 * Get the amount the battery has discharged while the screen was off,
2273 * since the last time the device was charged.
2274 */
2275 public abstract int getDischargeAmountScreenOffSinceCharge();
2276
2277 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 * Returns the total, last, or current battery uptime in microseconds.
2279 *
2280 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002281 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 */
2283 public abstract long computeBatteryUptime(long curTime, int which);
2284
2285 /**
2286 * Returns the total, last, or current battery realtime in microseconds.
2287 *
2288 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002289 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 */
2291 public abstract long computeBatteryRealtime(long curTime, int which);
2292
2293 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002294 * Returns the total, last, or current battery screen off uptime in microseconds.
2295 *
2296 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002297 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002298 */
2299 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2300
2301 /**
2302 * Returns the total, last, or current battery screen off realtime in microseconds.
2303 *
2304 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002305 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002306 */
2307 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2308
2309 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310 * Returns the total, last, or current uptime in microseconds.
2311 *
2312 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002313 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 */
2315 public abstract long computeUptime(long curTime, int which);
2316
2317 /**
2318 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002319 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002321 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 */
2323 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002324
2325 /**
2326 * Compute an approximation for how much run time (in microseconds) is remaining on
2327 * the battery. Returns -1 if no time can be computed: either there is not
2328 * enough current data to make a decision, or the battery is currently
2329 * charging.
2330 *
2331 * @param curTime The current elepsed realtime in microseconds.
2332 */
2333 public abstract long computeBatteryTimeRemaining(long curTime);
2334
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002335 // The part of a step duration that is the actual time.
2336 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2337
2338 // Bits in a step duration that are the new battery level we are at.
2339 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002340 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002341
2342 // Bits in a step duration that are the initial mode we were in at that step.
2343 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002344 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002345
2346 // Bits in a step duration that indicate which modes changed during that step.
2347 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002348 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002349
2350 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2351 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2352
2353 // Step duration mode: power save is on.
2354 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2355
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002356 // Step duration mode: device is currently in idle mode.
2357 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2358
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002359 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2360 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002361 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2362 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002363 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2364 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2365 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2366 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2367 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002368 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2369 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002370 };
2371 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2372 (Display.STATE_OFF-1),
2373 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002374 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002375 (Display.STATE_ON-1),
2376 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2377 (Display.STATE_DOZE-1),
2378 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2379 (Display.STATE_DOZE_SUSPEND-1),
2380 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002381 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002382 };
2383 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2384 "screen off",
2385 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002386 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002387 "screen on",
2388 "screen on power save",
2389 "screen doze",
2390 "screen doze power save",
2391 "screen doze-suspend",
2392 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002393 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002394 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002395
2396 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002397 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2398 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2399 * a coulomb counter.
2400 */
2401 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2402
2403 /**
2404 * Return the counter keeping track of the amount of battery discharge measured in
2405 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2406 * a coulomb counter.
2407 */
2408 public abstract LongCounter getDischargeCoulombCounter();
2409
2410 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002411 * Returns the estimated real battery capacity, which may be less than the capacity
2412 * declared by the PowerProfile.
2413 * @return The estimated battery capacity in mAh.
2414 */
2415 public abstract int getEstimatedBatteryCapacity();
2416
2417 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002418 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002419 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002420 public abstract LevelStepTracker getDischargeLevelStepTracker();
2421
2422 /**
2423 * Return the array of daily discharge step durations.
2424 */
2425 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002426
2427 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002428 * Compute an approximation for how much time (in microseconds) remains until the battery
2429 * is fully charged. Returns -1 if no time can be computed: either there is not
2430 * enough current data to make a decision, or the battery is currently
2431 * discharging.
2432 *
2433 * @param curTime The current elepsed realtime in microseconds.
2434 */
2435 public abstract long computeChargeTimeRemaining(long curTime);
2436
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002437 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002438 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002439 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002440 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002441
2442 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002443 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002444 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002445 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002446
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002447 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2448
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002449 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002450
Evan Millarc64edde2009-04-18 12:26:32 -07002451 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002453 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2454
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002455 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456 long days = seconds / (60 * 60 * 24);
2457 if (days != 0) {
2458 out.append(days);
2459 out.append("d ");
2460 }
2461 long used = days * 60 * 60 * 24;
2462
2463 long hours = (seconds - used) / (60 * 60);
2464 if (hours != 0 || used != 0) {
2465 out.append(hours);
2466 out.append("h ");
2467 }
2468 used += hours * 60 * 60;
2469
2470 long mins = (seconds-used) / 60;
2471 if (mins != 0 || used != 0) {
2472 out.append(mins);
2473 out.append("m ");
2474 }
2475 used += mins * 60;
2476
2477 if (seconds != 0 || used != 0) {
2478 out.append(seconds-used);
2479 out.append("s ");
2480 }
2481 }
2482
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002483 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002485 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 sb.append(time - (sec * 1000));
2487 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 }
2489
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002490 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002491 long sec = time / 1000;
2492 formatTimeRaw(sb, sec);
2493 sb.append(time - (sec * 1000));
2494 sb.append("ms");
2495 }
2496
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002497 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002498 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002499 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 }
2501 float perc = ((float)num) / ((float)den) * 100;
2502 mFormatBuilder.setLength(0);
2503 mFormatter.format("%.1f%%", perc);
2504 return mFormatBuilder.toString();
2505 }
2506
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002507 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002508 mFormatBuilder.setLength(0);
2509
2510 if (bytes < BYTES_PER_KB) {
2511 return bytes + "B";
2512 } else if (bytes < BYTES_PER_MB) {
2513 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2514 return mFormatBuilder.toString();
2515 } else if (bytes < BYTES_PER_GB){
2516 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2517 return mFormatBuilder.toString();
2518 } else {
2519 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2520 return mFormatBuilder.toString();
2521 }
2522 }
2523
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002524 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002525 if (timer != null) {
2526 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002527 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002528 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2529 return totalTimeMillis;
2530 }
2531 return 0;
2532 }
2533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 /**
2535 *
2536 * @param sb a StringBuilder object.
2537 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002538 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002540 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 * @param linePrefix a String to be prepended to each line of output.
2542 * @return the line prefix
2543 */
2544 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002545 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002548 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002549
Evan Millarc64edde2009-04-18 12:26:32 -07002550 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 if (totalTimeMillis != 0) {
2552 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002553 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002554 if (name != null) {
2555 sb.append(name);
2556 sb.append(' ');
2557 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 sb.append('(');
2559 sb.append(count);
2560 sb.append(" times)");
2561 return ", ";
2562 }
2563 }
2564 return linePrefix;
2565 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002566
2567 /**
2568 *
2569 * @param pw a PrintWriter object to print to.
2570 * @param sb a StringBuilder object.
2571 * @param timer a Timer object contining the wakelock times.
2572 * @param rawRealtime the current on-battery time in microseconds.
2573 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2574 * @param prefix a String to be prepended to each line of output.
2575 * @param type the name of the timer.
2576 */
2577 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
2578 long rawRealtime, int which, String prefix, String type) {
2579 if (timer != null) {
2580 // Convert from microseconds to milliseconds with rounding
2581 final long totalTime = (timer.getTotalTimeLocked(
2582 rawRealtime, which) + 500) / 1000;
2583 final int count = timer.getCountLocked(which);
2584 if (totalTime != 0) {
2585 sb.setLength(0);
2586 sb.append(prefix);
2587 sb.append(" ");
2588 sb.append(type);
2589 sb.append(": ");
2590 formatTimeMs(sb, totalTime);
2591 sb.append("realtime (");
2592 sb.append(count);
2593 sb.append(" times)");
2594 pw.println(sb.toString());
2595 return true;
2596 }
2597 }
2598 return false;
2599 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600
2601 /**
2602 * Checkin version of wakelock printer. Prints simple comma-separated list.
2603 *
2604 * @param sb a StringBuilder object.
2605 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002606 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002608 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 * @param linePrefix a String to be prepended to each line of output.
2610 * @return the line prefix
2611 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002612 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2613 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 long totalTimeMicros = 0;
2615 int count = 0;
2616 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002617 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002618 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002619 }
2620 sb.append(linePrefix);
2621 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2622 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002623 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 sb.append(count);
2625 return ",";
2626 }
2627
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002628 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2629 String type) {
2630 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2631 pw.print(',');
2632 pw.print(uid);
2633 pw.print(',');
2634 pw.print(category);
2635 pw.print(',');
2636 pw.print(type);
2637 }
2638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002639 /**
2640 * Dump a comma-separated line of values for terse checkin mode.
2641 *
2642 * @param pw the PageWriter to dump log to
2643 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2644 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2645 * @param args type-dependent data arguments
2646 */
2647 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2648 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002649 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002650 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002651 pw.print(',');
2652 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002654 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002656
2657 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002658 * Dump a given timer stat for terse checkin mode.
2659 *
2660 * @param pw the PageWriter to dump log to
2661 * @param uid the UID to log
2662 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2663 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2664 * @param timer a {@link Timer} to dump stats for
2665 * @param rawRealtime the current elapsed realtime of the system in microseconds
2666 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2667 */
2668 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2669 Timer timer, long rawRealtime, int which) {
2670 if (timer != null) {
2671 // Convert from microseconds to milliseconds with rounding
2672 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2673 / 1000;
2674 final int count = timer.getCountLocked(which);
2675 if (totalTime != 0) {
2676 dumpLine(pw, uid, category, type, totalTime, count);
2677 }
2678 }
2679 }
2680
2681 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002682 * Checks if the ControllerActivityCounter has any data worth dumping.
2683 */
2684 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2685 if (counter == null) {
2686 return false;
2687 }
2688
2689 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2690 || counter.getRxTimeCounter().getCountLocked(which) != 0
2691 || counter.getPowerCounter().getCountLocked(which) != 0) {
2692 return true;
2693 }
2694
2695 for (LongCounter c : counter.getTxTimeCounters()) {
2696 if (c.getCountLocked(which) != 0) {
2697 return true;
2698 }
2699 }
2700 return false;
2701 }
2702
2703 /**
2704 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2705 * The order of the arguments in the final check in line is:
2706 *
2707 * idle, rx, power, tx...
2708 *
2709 * where tx... is one or more transmit level times.
2710 */
2711 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2712 String type,
2713 ControllerActivityCounter counter,
2714 int which) {
2715 if (!controllerActivityHasData(counter, which)) {
2716 return;
2717 }
2718
2719 dumpLineHeader(pw, uid, category, type);
2720 pw.print(",");
2721 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2722 pw.print(",");
2723 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2724 pw.print(",");
2725 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2726 for (LongCounter c : counter.getTxTimeCounters()) {
2727 pw.print(",");
2728 pw.print(c.getCountLocked(which));
2729 }
2730 pw.println();
2731 }
2732
2733 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2734 String prefix, String controllerName,
2735 ControllerActivityCounter counter,
2736 int which) {
2737 if (controllerActivityHasData(counter, which)) {
2738 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2739 }
2740 }
2741
2742 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2743 String controllerName,
2744 ControllerActivityCounter counter, int which) {
2745 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2746 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2747 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2748 long totalTxTimeMs = 0;
2749 for (LongCounter txState : counter.getTxTimeCounters()) {
2750 totalTxTimeMs += txState.getCountLocked(which);
2751 }
2752
2753 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2754
2755 sb.setLength(0);
2756 sb.append(prefix);
2757 sb.append(" ");
2758 sb.append(controllerName);
2759 sb.append(" Idle time: ");
2760 formatTimeMs(sb, idleTimeMs);
2761 sb.append("(");
2762 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2763 sb.append(")");
2764 pw.println(sb.toString());
2765
2766 sb.setLength(0);
2767 sb.append(prefix);
2768 sb.append(" ");
2769 sb.append(controllerName);
2770 sb.append(" Rx time: ");
2771 formatTimeMs(sb, rxTimeMs);
2772 sb.append("(");
2773 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
2774 sb.append(")");
2775 pw.println(sb.toString());
2776
2777 sb.setLength(0);
2778 sb.append(prefix);
2779 sb.append(" ");
2780 sb.append(controllerName);
2781 sb.append(" Tx time: ");
2782 formatTimeMs(sb, totalTxTimeMs);
2783 sb.append("(");
2784 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
2785 sb.append(")");
2786 pw.println(sb.toString());
2787
2788 final int numTxLvls = counter.getTxTimeCounters().length;
2789 if (numTxLvls > 1) {
2790 for (int lvl = 0; lvl < numTxLvls; lvl++) {
2791 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
2792 sb.setLength(0);
2793 sb.append(prefix);
2794 sb.append(" [");
2795 sb.append(lvl);
2796 sb.append("] ");
2797 formatTimeMs(sb, txLvlTimeMs);
2798 sb.append("(");
2799 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
2800 sb.append(")");
2801 pw.println(sb.toString());
2802 }
2803 }
2804
2805 sb.setLength(0);
2806 sb.append(prefix);
2807 sb.append(" ");
2808 sb.append(controllerName);
2809 sb.append(" Power drain: ").append(
2810 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
2811 sb.append("mAh");
2812 pw.println(sb.toString());
2813 }
2814
2815 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07002816 * Temporary for settings.
2817 */
2818 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2819 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2820 }
2821
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 /**
2823 * Checkin server version of dump to produce more compact, computer-readable log.
2824 *
2825 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002827 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2828 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2830 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2831 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2833 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002834 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2835 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2836 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 final long totalRealtime = computeRealtime(rawRealtime, which);
2838 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002839 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002840 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002841 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002842 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
2843 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002844 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002845 rawRealtime, which);
2846 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
2847 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002848 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002849 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002850 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002851 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002852 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
2853 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
2854 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002855
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002856 final StringBuilder sb = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002858 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07002859 final int NU = uidStats.size();
2860
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002861 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 // Dump "battery" stat
2864 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002865 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002866 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002867 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002868 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002869 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
2870 getEstimatedBatteryCapacity());
Adam Lesinski67c134f2016-06-10 15:15:08 -07002871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002873 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002874 long fullWakeLockTimeTotal = 0;
2875 long partialWakeLockTimeTotal = 0;
2876
2877 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002878 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002879
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002880 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
2881 = u.getWakelockStats();
2882 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2883 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07002884
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002885 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2886 if (fullWakeTimer != null) {
2887 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2888 which);
2889 }
2890
2891 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2892 if (partialWakeTimer != null) {
2893 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
2894 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002895 }
2896 }
2897 }
Adam Lesinskie283d332015-04-16 12:29:25 -07002898
2899 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002900 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2901 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2902 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2903 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2904 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2905 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2906 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2907 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002908 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
2909 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002910 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2911 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002912 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
2913 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002914
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002915 // Dump Modem controller stats
2916 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
2917 getModemControllerActivity(), which);
2918
Adam Lesinskie283d332015-04-16 12:29:25 -07002919 // Dump Wifi controller stats
2920 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2921 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002922 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08002923 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002924
2925 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
2926 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002927
2928 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002929 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
2930 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 // Dump misc stats
2933 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07002934 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002935 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07002936 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002937 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002938 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002939 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
2940 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07002941 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002942 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
2943 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
2944 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
2945 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002946 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002947
2948 // Dump screen brightness stats
2949 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2950 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002951 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002952 }
2953 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002954
Dianne Hackborn627bba72009-03-24 22:32:56 -07002955 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002956 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2957 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002958 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002959 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002960 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002961 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002962 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002963 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002964 args[i] = getPhoneSignalStrengthCount(i, which);
2965 }
2966 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002967
Dianne Hackborn627bba72009-03-24 22:32:56 -07002968 // Dump network type stats
2969 args = new Object[NUM_DATA_CONNECTION_TYPES];
2970 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002971 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002972 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002973 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2974 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2975 args[i] = getPhoneDataConnectionCount(i, which);
2976 }
2977 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002978
2979 // Dump wifi state stats
2980 args = new Object[NUM_WIFI_STATES];
2981 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002982 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002983 }
2984 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2985 for (int i=0; i<NUM_WIFI_STATES; i++) {
2986 args[i] = getWifiStateCount(i, which);
2987 }
2988 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2989
Dianne Hackborn3251b902014-06-20 14:40:53 -07002990 // Dump wifi suppl state stats
2991 args = new Object[NUM_WIFI_SUPPL_STATES];
2992 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2993 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2994 }
2995 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2996 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2997 args[i] = getWifiSupplStateCount(i, which);
2998 }
2999 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3000
3001 // Dump wifi signal strength stats
3002 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3003 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3004 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3005 }
3006 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3007 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3008 args[i] = getWifiSignalStrengthCount(i, which);
3009 }
3010 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3011
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003012 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003013 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003014 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003017 if (which == STATS_SINCE_UNPLUGGED) {
3018 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3019 getDischargeStartLevel()-getDischargeCurrentLevel(),
3020 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003021 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
3022 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003023 } else {
3024 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3025 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003026 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003027 getDischargeAmountScreenOffSinceCharge(),
3028 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003029 }
3030
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003031 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003032 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003033 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003034 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003035 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003036 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003037 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003038 sb.toString());
3039 }
Evan Millarc64edde2009-04-18 12:26:32 -07003040 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003041 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003042 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003043 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3044 // Not doing the regular wake lock formatting to remain compatible
3045 // with the old checkin format.
3046 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3047 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003048 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003049 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003050 }
3051 }
Evan Millarc64edde2009-04-18 12:26:32 -07003052 }
3053
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003054 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003055 helper.create(this);
3056 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003057 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003058 if (sippers != null && sippers.size() > 0) {
3059 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3060 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003061 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003062 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3063 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3064 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003065 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003066 int uid = 0;
3067 String label;
3068 switch (bs.drainType) {
3069 case IDLE:
3070 label="idle";
3071 break;
3072 case CELL:
3073 label="cell";
3074 break;
3075 case PHONE:
3076 label="phone";
3077 break;
3078 case WIFI:
3079 label="wifi";
3080 break;
3081 case BLUETOOTH:
3082 label="blue";
3083 break;
3084 case SCREEN:
3085 label="scrn";
3086 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003087 case FLASHLIGHT:
3088 label="flashlight";
3089 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003090 case APP:
3091 uid = bs.uidObj.getUid();
3092 label = "uid";
3093 break;
3094 case USER:
3095 uid = UserHandle.getUid(bs.userId, 0);
3096 label = "user";
3097 break;
3098 case UNACCOUNTED:
3099 label = "unacc";
3100 break;
3101 case OVERCOUNTED:
3102 label = "over";
3103 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003104 case CAMERA:
3105 label = "camera";
3106 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003107 default:
3108 label = "???";
3109 }
3110 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07003111 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003112 }
3113 }
3114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003115 for (int iu = 0; iu < NU; iu++) {
3116 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003117 if (reqUid >= 0 && uid != reqUid) {
3118 continue;
3119 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003120 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003123 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3124 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3125 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3126 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3127 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3128 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3129 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3130 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003131 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003132 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3133 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003134 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003135 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3136 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003137 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3138 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003139 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Adam Lesinski5f056f62016-07-14 16:56:08 -07003140 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003141 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3142 wifiBytesRx, wifiBytesTx,
3143 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003144 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003145 mobileActiveTime, mobileActiveCount,
Adam Lesinski5f056f62016-07-14 16:56:08 -07003146 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003147 }
3148
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003149 // Dump modem controller data, per UID.
3150 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3151 u.getModemControllerActivity(), which);
3152
3153 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003154 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3155 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3156 final int wifiScanCount = u.getWifiScanCount(which);
3157 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003158 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003159 || uidWifiRunningTime != 0) {
3160 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3161 uidWifiRunningTime, wifiScanCount,
Kweku Adams5b2747e2016-04-25 10:44:05 -07003162 /* legacy fields follow, keep at 0 */ 0, 0, 0);
The Android Open Source Project10592532009-03-18 17:39:46 -07003163 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003165 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3166 u.getWifiControllerActivity(), which);
3167
Adam Lesinskiba9d8932016-04-12 12:06:03 -07003168 dumpTimer(pw, uid, category, BLUETOOTH_MISC_DATA, u.getBluetoothScanTimer(),
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003169 rawRealtime, which);
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003170
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003171 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3172 u.getBluetoothControllerActivity(), which);
3173
Dianne Hackborn617f8772009-03-31 15:04:46 -07003174 if (u.hasUserActivity()) {
3175 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3176 boolean hasData = false;
3177 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3178 int val = u.getUserActivityCount(i, which);
3179 args[i] = val;
3180 if (val != 0) hasData = true;
3181 }
3182 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003183 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003184 }
3185 }
3186
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003187 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3188 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3189 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3190 String linePrefix = "";
3191 sb.setLength(0);
3192 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3193 rawRealtime, "f", which, linePrefix);
3194 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
3195 rawRealtime, "p", which, linePrefix);
3196 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3197 rawRealtime, "w", which, linePrefix);
3198
3199 // Only log if we had at lease one wakelock...
3200 if (sb.length() > 0) {
3201 String name = wakelocks.keyAt(iw);
3202 if (name.indexOf(',') >= 0) {
3203 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003204 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003205 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003206 }
3207 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003208
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003209 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3210 for (int isy=syncs.size()-1; isy>=0; isy--) {
3211 final Timer timer = syncs.valueAt(isy);
3212 // Convert from microseconds to milliseconds with rounding
3213 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3214 final int count = timer.getCountLocked(which);
3215 if (totalTime != 0) {
3216 dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003217 }
3218 }
3219
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003220 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3221 for (int ij=jobs.size()-1; ij>=0; ij--) {
3222 final Timer timer = jobs.valueAt(ij);
3223 // Convert from microseconds to milliseconds with rounding
3224 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3225 final int count = timer.getCountLocked(which);
3226 if (totalTime != 0) {
3227 dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003228 }
3229 }
3230
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003231 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3232 rawRealtime, which);
3233 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3234 rawRealtime, which);
3235 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3236 rawRealtime, which);
3237 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3238 rawRealtime, which);
3239
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003240 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3241 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003242 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003243 final Uid.Sensor se = sensors.valueAt(ise);
3244 final int sensorNumber = sensors.keyAt(ise);
3245 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003246 if (timer != null) {
3247 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003248 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3249 / 1000;
3250 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003251 if (totalTime != 0) {
3252 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
3253 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003254 }
3255 }
3256
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003257 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3258 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003259
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003260 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3261 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003262
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003263 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003264 long totalStateTime = 0;
3265 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003266 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3267 totalStateTime += time;
3268 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003269 }
3270 if (totalStateTime > 0) {
3271 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3272 }
3273
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003274 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3275 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
3276 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
3277 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
3278 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
3279 powerCpuMaUs / 1000);
3280 }
3281
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003282 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3283 = u.getProcessStats();
3284 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3285 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003286
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003287 final long userMillis = ps.getUserTime(which);
3288 final long systemMillis = ps.getSystemTime(which);
3289 final long foregroundMillis = ps.getForegroundTime(which);
3290 final int starts = ps.getStarts(which);
3291 final int numCrashes = ps.getNumCrashes(which);
3292 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003293
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003294 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3295 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
3296 dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis,
3297 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 }
3299 }
3300
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003301 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3302 = u.getPackageStats();
3303 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3304 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3305 int wakeups = 0;
3306 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3307 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003308 int count = alarms.valueAt(iwa).getCountLocked(which);
3309 wakeups += count;
3310 String name = alarms.keyAt(iwa).replace(',', '_');
3311 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003312 }
3313 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3314 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3315 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3316 final long startTime = ss.getStartTime(batteryUptime, which);
3317 final int starts = ss.getStarts(which);
3318 final int launches = ss.getLaunches(which);
3319 if (startTime != 0 || starts != 0 || launches != 0) {
3320 dumpLine(pw, uid, category, APK_DATA,
3321 wakeups, // wakeup alarms
3322 packageStats.keyAt(ipkg), // Apk
3323 serviceStats.keyAt(isvc), // service
3324 startTime / 1000, // time spent started, in ms
3325 starts,
3326 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003327 }
3328 }
3329 }
3330 }
3331 }
3332
Dianne Hackborn81038902012-11-26 17:04:09 -08003333 static final class TimerEntry {
3334 final String mName;
3335 final int mId;
3336 final BatteryStats.Timer mTimer;
3337 final long mTime;
3338 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3339 mName = name;
3340 mId = id;
3341 mTimer = timer;
3342 mTime = time;
3343 }
3344 }
3345
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003346 private void printmAh(PrintWriter printer, double power) {
3347 printer.print(BatteryStatsHelper.makemAh(power));
3348 }
3349
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003350 private void printmAh(StringBuilder sb, double power) {
3351 sb.append(BatteryStatsHelper.makemAh(power));
3352 }
3353
Dianne Hackbornd953c532014-08-16 18:17:38 -07003354 /**
3355 * Temporary for settings.
3356 */
3357 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3358 int reqUid) {
3359 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3360 }
3361
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003362 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003363 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003364 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003365 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3366 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3367 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368
3369 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3370 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3371 final long totalRealtime = computeRealtime(rawRealtime, which);
3372 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003373 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3374 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3375 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003376 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3377 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003378
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003379 final StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07003380
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003381 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003382 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003384 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3385 if (estimatedBatteryCapacity > 0) {
3386 sb.setLength(0);
3387 sb.append(prefix);
3388 sb.append(" Estimated battery capacity: ");
3389 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3390 sb.append(" mAh");
3391 pw.println(sb.toString());
3392 }
3393
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003394 sb.setLength(0);
3395 sb.append(prefix);
3396 sb.append(" Time on battery: ");
3397 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3398 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3399 sb.append(") realtime, ");
3400 formatTimeMs(sb, whichBatteryUptime / 1000);
3401 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3402 sb.append(") uptime");
3403 pw.println(sb.toString());
3404 sb.setLength(0);
3405 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003406 sb.append(" Time on battery screen off: ");
3407 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3408 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3409 sb.append(") realtime, ");
3410 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3411 sb.append("(");
3412 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3413 sb.append(") uptime");
3414 pw.println(sb.toString());
3415 sb.setLength(0);
3416 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003417 sb.append(" Total run time: ");
3418 formatTimeMs(sb, totalRealtime / 1000);
3419 sb.append("realtime, ");
3420 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003421 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003422 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003423 if (batteryTimeRemaining >= 0) {
3424 sb.setLength(0);
3425 sb.append(prefix);
3426 sb.append(" Battery time remaining: ");
3427 formatTimeMs(sb, batteryTimeRemaining / 1000);
3428 pw.println(sb.toString());
3429 }
3430 if (chargeTimeRemaining >= 0) {
3431 sb.setLength(0);
3432 sb.append(prefix);
3433 sb.append(" Charge time remaining: ");
3434 formatTimeMs(sb, chargeTimeRemaining / 1000);
3435 pw.println(sb.toString());
3436 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003437
3438 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3439 final long dischargeCount = dischargeCounter.getCountLocked(which);
3440 if (dischargeCount >= 0) {
3441 sb.setLength(0);
3442 sb.append(prefix);
3443 sb.append(" Discharge: ");
3444 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3445 sb.append(" mAh");
3446 pw.println(sb.toString());
3447 }
3448
3449 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3450 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3451 if (dischargeScreenOffCount >= 0) {
3452 sb.setLength(0);
3453 sb.append(prefix);
3454 sb.append(" Screen off discharge: ");
3455 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3456 sb.append(" mAh");
3457 pw.println(sb.toString());
3458 }
3459
3460 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3461 if (dischargeScreenOnCount >= 0) {
3462 sb.setLength(0);
3463 sb.append(prefix);
3464 sb.append(" Screen on discharge: ");
3465 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3466 sb.append(" mAh");
3467 pw.println(sb.toString());
3468 }
3469
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003470 pw.print(" Start clock time: ");
3471 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3472
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003473 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003474 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003475 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003476 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3477 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003478 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003479 rawRealtime, which);
3480 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3481 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003482 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003483 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003484 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3485 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3486 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003487 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003488 sb.append(prefix);
3489 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3490 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003491 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003492 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3493 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003494 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003495 pw.println(sb.toString());
3496 sb.setLength(0);
3497 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003498 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003499 boolean didOne = false;
3500 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003501 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003502 if (time == 0) {
3503 continue;
3504 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003505 sb.append("\n ");
3506 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003507 didOne = true;
3508 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3509 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003510 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003511 sb.append("(");
3512 sb.append(formatRatioLocked(time, screenOnTime));
3513 sb.append(")");
3514 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003515 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003516 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003517 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003518 sb.setLength(0);
3519 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003520 sb.append(" Power save mode enabled: ");
3521 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003522 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003523 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003524 sb.append(")");
3525 pw.println(sb.toString());
3526 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003527 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003528 sb.setLength(0);
3529 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003530 sb.append(" Device light idling: ");
3531 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003532 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003533 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3534 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003535 sb.append("x");
3536 pw.println(sb.toString());
3537 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003538 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003539 sb.setLength(0);
3540 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003541 sb.append(" Idle mode light time: ");
3542 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003543 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003544 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3545 sb.append(") ");
3546 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003547 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003548 sb.append(" -- longest ");
3549 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3550 pw.println(sb.toString());
3551 }
3552 if (deviceIdlingTime != 0) {
3553 sb.setLength(0);
3554 sb.append(prefix);
3555 sb.append(" Device full idling: ");
3556 formatTimeMs(sb, deviceIdlingTime / 1000);
3557 sb.append("(");
3558 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003559 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003560 sb.append("x");
3561 pw.println(sb.toString());
3562 }
3563 if (deviceIdleModeFullTime != 0) {
3564 sb.setLength(0);
3565 sb.append(prefix);
3566 sb.append(" Idle mode full time: ");
3567 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3568 sb.append("(");
3569 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3570 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003571 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003572 sb.append("x");
3573 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003574 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003575 pw.println(sb.toString());
3576 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003577 if (phoneOnTime != 0) {
3578 sb.setLength(0);
3579 sb.append(prefix);
3580 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3581 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003582 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003583 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003584 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003585 if (connChanges != 0) {
3586 pw.print(prefix);
3587 pw.print(" Connectivity changes: "); pw.println(connChanges);
3588 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003589
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003590 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003591 long fullWakeLockTimeTotalMicros = 0;
3592 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003593
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003594 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003595
Evan Millar22ac0432009-03-31 11:33:18 -07003596 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003597 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003598
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003599 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3600 = u.getWakelockStats();
3601 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3602 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003603
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003604 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3605 if (fullWakeTimer != null) {
3606 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3607 rawRealtime, which);
3608 }
3609
3610 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3611 if (partialWakeTimer != null) {
3612 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3613 rawRealtime, which);
3614 if (totalTimeMicros > 0) {
3615 if (reqUid < 0) {
3616 // Only show the ordered list of all wake
3617 // locks if the caller is not asking for data
3618 // about a specific uid.
3619 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3620 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003621 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003622 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003623 }
3624 }
3625 }
3626 }
3627
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003628 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3629 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3630 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3631 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3632 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3633 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3634 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3635 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08003636 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3637 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003638
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003639 if (fullWakeLockTimeTotalMicros != 0) {
3640 sb.setLength(0);
3641 sb.append(prefix);
3642 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3643 (fullWakeLockTimeTotalMicros + 500) / 1000);
3644 pw.println(sb.toString());
3645 }
3646
3647 if (partialWakeLockTimeTotalMicros != 0) {
3648 sb.setLength(0);
3649 sb.append(prefix);
3650 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3651 (partialWakeLockTimeTotalMicros + 500) / 1000);
3652 pw.println(sb.toString());
3653 }
3654
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003655 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003656 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3657 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3658 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3659 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003660 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003661 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003662 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003663 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003664 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003665 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003666 if (time == 0) {
3667 continue;
3668 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003669 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003670 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003671 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003672 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003673 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003674 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003675 sb.append("(");
3676 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003677 sb.append(") ");
3678 sb.append(getPhoneSignalStrengthCount(i, which));
3679 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003680 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003681 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003682 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003683
3684 sb.setLength(0);
3685 sb.append(prefix);
3686 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003687 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003688 pw.println(sb.toString());
3689
Dianne Hackborn627bba72009-03-24 22:32:56 -07003690 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003691 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003692 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003693 didOne = false;
3694 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003695 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003696 if (time == 0) {
3697 continue;
3698 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003699 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003700 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003701 didOne = true;
3702 sb.append(DATA_CONNECTION_NAMES[i]);
3703 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003704 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003705 sb.append("(");
3706 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003707 sb.append(") ");
3708 sb.append(getPhoneDataConnectionCount(i, which));
3709 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003710 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003711 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003712 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003713
3714 sb.setLength(0);
3715 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003716 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003717 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003718 formatTimeMs(sb, mobileActiveTime / 1000);
3719 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3720 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3721 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003722 pw.println(sb.toString());
3723
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003724 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3725 if (mobileActiveUnknownTime != 0) {
3726 sb.setLength(0);
3727 sb.append(prefix);
3728 sb.append(" Mobile radio active unknown time: ");
3729 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3730 sb.append("(");
3731 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3732 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3733 sb.append("x");
3734 pw.println(sb.toString());
3735 }
3736
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003737 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3738 if (mobileActiveAdjustedTime != 0) {
3739 sb.setLength(0);
3740 sb.append(prefix);
3741 sb.append(" Mobile radio active adjusted time: ");
3742 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3743 sb.append("(");
3744 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3745 sb.append(")");
3746 pw.println(sb.toString());
3747 }
3748
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003749 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
3750
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003751 pw.print(prefix);
3752 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3753 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3754 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3755 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003756 sb.setLength(0);
3757 sb.append(prefix);
3758 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3759 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3760 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3761 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003762 sb.append(")");
3763 pw.println(sb.toString());
3764
3765 sb.setLength(0);
3766 sb.append(prefix);
3767 sb.append(" Wifi states:");
3768 didOne = false;
3769 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003770 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003771 if (time == 0) {
3772 continue;
3773 }
3774 sb.append("\n ");
3775 didOne = true;
3776 sb.append(WIFI_STATE_NAMES[i]);
3777 sb.append(" ");
3778 formatTimeMs(sb, time/1000);
3779 sb.append("(");
3780 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3781 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003782 sb.append(getWifiStateCount(i, which));
3783 sb.append("x");
3784 }
3785 if (!didOne) sb.append(" (no activity)");
3786 pw.println(sb.toString());
3787
3788 sb.setLength(0);
3789 sb.append(prefix);
3790 sb.append(" Wifi supplicant states:");
3791 didOne = false;
3792 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3793 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3794 if (time == 0) {
3795 continue;
3796 }
3797 sb.append("\n ");
3798 didOne = true;
3799 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3800 sb.append(" ");
3801 formatTimeMs(sb, time/1000);
3802 sb.append("(");
3803 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3804 sb.append(") ");
3805 sb.append(getWifiSupplStateCount(i, which));
3806 sb.append("x");
3807 }
3808 if (!didOne) sb.append(" (no activity)");
3809 pw.println(sb.toString());
3810
3811 sb.setLength(0);
3812 sb.append(prefix);
3813 sb.append(" Wifi signal levels:");
3814 didOne = false;
3815 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3816 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3817 if (time == 0) {
3818 continue;
3819 }
3820 sb.append("\n ");
3821 sb.append(prefix);
3822 didOne = true;
3823 sb.append("level(");
3824 sb.append(i);
3825 sb.append(") ");
3826 formatTimeMs(sb, time/1000);
3827 sb.append("(");
3828 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3829 sb.append(") ");
3830 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003831 sb.append("x");
3832 }
3833 if (!didOne) sb.append(" (no activity)");
3834 pw.println(sb.toString());
3835
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003836 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07003837
Adam Lesinski50e47602015-12-04 17:04:54 -08003838 pw.print(prefix);
3839 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
3840 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
3841
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003842 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
3843 sb.setLength(0);
3844 sb.append(prefix);
3845 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
3846 pw.println(sb.toString());
3847
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003848 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
3849 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003850
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003851 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003852
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003853 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003854 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003855 pw.print(prefix); pw.println(" Device is currently unplugged");
3856 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3857 pw.println(getDischargeStartLevel());
3858 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3859 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003860 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003861 pw.print(prefix); pw.println(" Device is currently plugged into power");
3862 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3863 pw.println(getDischargeStartLevel());
3864 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3865 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003866 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003867 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3868 pw.println(getDischargeAmountScreenOn());
3869 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3870 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003871 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003872 } else {
3873 pw.print(prefix); pw.println(" Device battery use since last full charge");
3874 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3875 pw.println(getLowDischargeAmountSinceCharge());
3876 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3877 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003878 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3879 pw.println(getDischargeAmountScreenOnSinceCharge());
3880 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3881 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003882 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003883 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003884
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003885 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003886 helper.create(this);
3887 helper.refreshStats(which, UserHandle.USER_ALL);
3888 List<BatterySipper> sippers = helper.getUsageList();
3889 if (sippers != null && sippers.size() > 0) {
3890 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3891 pw.print(prefix); pw.print(" Capacity: ");
3892 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003893 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003894 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3895 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3896 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3897 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003898 pw.println();
3899 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003900 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003901 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003902 switch (bs.drainType) {
3903 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003904 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003905 break;
3906 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003907 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003908 break;
3909 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003910 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003911 break;
3912 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003913 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003914 break;
3915 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003916 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003917 break;
3918 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003919 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003920 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003921 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003922 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003923 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003924 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003925 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003926 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003927 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003928 break;
3929 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003930 pw.print(" User "); pw.print(bs.userId);
3931 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003932 break;
3933 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003934 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003935 break;
3936 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003937 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003938 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003939 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003940 pw.print(" Camera: ");
3941 break;
3942 default:
3943 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003944 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003945 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003946 printmAh(pw, bs.totalPowerMah);
3947
Adam Lesinski57123002015-06-12 16:12:07 -07003948 if (bs.usagePowerMah != bs.totalPowerMah) {
3949 // If the usage (generic power) isn't the whole amount, we list out
3950 // what components are involved in the calculation.
3951
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003952 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07003953 if (bs.usagePowerMah != 0) {
3954 pw.print(" usage=");
3955 printmAh(pw, bs.usagePowerMah);
3956 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003957 if (bs.cpuPowerMah != 0) {
3958 pw.print(" cpu=");
3959 printmAh(pw, bs.cpuPowerMah);
3960 }
3961 if (bs.wakeLockPowerMah != 0) {
3962 pw.print(" wake=");
3963 printmAh(pw, bs.wakeLockPowerMah);
3964 }
3965 if (bs.mobileRadioPowerMah != 0) {
3966 pw.print(" radio=");
3967 printmAh(pw, bs.mobileRadioPowerMah);
3968 }
3969 if (bs.wifiPowerMah != 0) {
3970 pw.print(" wifi=");
3971 printmAh(pw, bs.wifiPowerMah);
3972 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003973 if (bs.bluetoothPowerMah != 0) {
3974 pw.print(" bt=");
3975 printmAh(pw, bs.bluetoothPowerMah);
3976 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003977 if (bs.gpsPowerMah != 0) {
3978 pw.print(" gps=");
3979 printmAh(pw, bs.gpsPowerMah);
3980 }
3981 if (bs.sensorPowerMah != 0) {
3982 pw.print(" sensor=");
3983 printmAh(pw, bs.sensorPowerMah);
3984 }
3985 if (bs.cameraPowerMah != 0) {
3986 pw.print(" camera=");
3987 printmAh(pw, bs.cameraPowerMah);
3988 }
3989 if (bs.flashlightPowerMah != 0) {
3990 pw.print(" flash=");
3991 printmAh(pw, bs.flashlightPowerMah);
3992 }
3993 pw.print(" )");
3994 }
3995 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003996 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08003997 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003998 }
3999
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004000 sippers = helper.getMobilemsppList();
4001 if (sippers != null && sippers.size() > 0) {
4002 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004003 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004004 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004005 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004006 sb.setLength(0);
4007 sb.append(prefix); sb.append(" Uid ");
4008 UserHandle.formatUid(sb, bs.uidObj.getUid());
4009 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4010 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4011 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004012 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004013 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004014 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004015 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004016 sb.setLength(0);
4017 sb.append(prefix);
4018 sb.append(" TOTAL TIME: ");
4019 formatTimeMs(sb, totalTime);
4020 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4021 sb.append(")");
4022 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004023 pw.println();
4024 }
4025
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004026 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4027 @Override
4028 public int compare(TimerEntry lhs, TimerEntry rhs) {
4029 long lhsTime = lhs.mTime;
4030 long rhsTime = rhs.mTime;
4031 if (lhsTime < rhsTime) {
4032 return 1;
4033 }
4034 if (lhsTime > rhsTime) {
4035 return -1;
4036 }
4037 return 0;
4038 }
4039 };
4040
4041 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004042 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4043 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004044 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004045 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4046 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4047 : kernelWakelocks.entrySet()) {
4048 final BatteryStats.Timer timer = ent.getValue();
4049 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004050 if (totalTimeMillis > 0) {
4051 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4052 }
4053 }
4054 if (ktimers.size() > 0) {
4055 Collections.sort(ktimers, timerComparator);
4056 pw.print(prefix); pw.println(" All kernel wake locks:");
4057 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004058 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004059 String linePrefix = ": ";
4060 sb.setLength(0);
4061 sb.append(prefix);
4062 sb.append(" Kernel Wake lock ");
4063 sb.append(timer.mName);
4064 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4065 which, linePrefix);
4066 if (!linePrefix.equals(": ")) {
4067 sb.append(" realtime");
4068 // Only print out wake locks that were held
4069 pw.println(sb.toString());
4070 }
4071 }
4072 pw.println();
4073 }
4074 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004075
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004076 if (timers.size() > 0) {
4077 Collections.sort(timers, timerComparator);
4078 pw.print(prefix); pw.println(" All partial wake locks:");
4079 for (int i=0; i<timers.size(); i++) {
4080 TimerEntry timer = timers.get(i);
4081 sb.setLength(0);
4082 sb.append(" Wake lock ");
4083 UserHandle.formatUid(sb, timer.mId);
4084 sb.append(" ");
4085 sb.append(timer.mName);
4086 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4087 sb.append(" realtime");
4088 pw.println(sb.toString());
4089 }
4090 timers.clear();
4091 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004092 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004093
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004094 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004095 if (wakeupReasons.size() > 0) {
4096 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004097 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004098 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004099 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004100 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4101 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004102 }
4103 Collections.sort(reasons, timerComparator);
4104 for (int i=0; i<reasons.size(); i++) {
4105 TimerEntry timer = reasons.get(i);
4106 String linePrefix = ": ";
4107 sb.setLength(0);
4108 sb.append(prefix);
4109 sb.append(" Wakeup reason ");
4110 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004111 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4112 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004113 pw.println(sb.toString());
4114 }
4115 pw.println();
4116 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004117 }
Evan Millar22ac0432009-03-31 11:33:18 -07004118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004119 for (int iu=0; iu<NU; iu++) {
4120 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004121 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004122 continue;
4123 }
4124
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004125 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004126
4127 pw.print(prefix);
4128 pw.print(" ");
4129 UserHandle.formatUid(pw, uid);
4130 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004131 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004132
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004133 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4134 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4135 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4136 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004137 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4138 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4139
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004140 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4141 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004142 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4143 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004144
4145 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4146 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4147
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004148 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4149 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4150 final int wifiScanCount = u.getWifiScanCount(which);
4151 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004152
Adam Lesinski5f056f62016-07-14 16:56:08 -07004153 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4154 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4155
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004156 if (mobileRxBytes > 0 || mobileTxBytes > 0
4157 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004158 pw.print(prefix); pw.print(" Mobile network: ");
4159 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004160 pw.print(formatBytesLocked(mobileTxBytes));
4161 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4162 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004163 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004164 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4165 sb.setLength(0);
4166 sb.append(prefix); sb.append(" Mobile radio active: ");
4167 formatTimeMs(sb, uidMobileActiveTime / 1000);
4168 sb.append("(");
4169 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4170 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4171 long packets = mobileRxPackets + mobileTxPackets;
4172 if (packets == 0) {
4173 packets = 1;
4174 }
4175 sb.append(" @ ");
4176 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4177 sb.append(" mspp");
4178 pw.println(sb.toString());
4179 }
4180
Adam Lesinski5f056f62016-07-14 16:56:08 -07004181 if (mobileWakeup > 0) {
4182 sb.setLength(0);
4183 sb.append(prefix);
4184 sb.append(" Mobile radio AP wakeups: ");
4185 sb.append(mobileWakeup);
4186 pw.println(sb.toString());
4187 }
4188
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004189 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4190 u.getModemControllerActivity(), which);
4191
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004192 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004193 pw.print(prefix); pw.print(" Wi-Fi network: ");
4194 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004195 pw.print(formatBytesLocked(wifiTxBytes));
4196 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4197 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004198 }
4199
Dianne Hackborn62793e42015-03-09 11:15:41 -07004200 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004201 || uidWifiRunningTime != 0) {
4202 sb.setLength(0);
4203 sb.append(prefix); sb.append(" Wifi Running: ");
4204 formatTimeMs(sb, uidWifiRunningTime / 1000);
4205 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4206 whichBatteryRealtime)); sb.append(")\n");
4207 sb.append(prefix); sb.append(" Full Wifi Lock: ");
4208 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4209 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4210 whichBatteryRealtime)); sb.append(")\n");
4211 sb.append(prefix); sb.append(" Wifi Scan: ");
4212 formatTimeMs(sb, wifiScanTime / 1000);
4213 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004214 whichBatteryRealtime)); sb.append(") ");
4215 sb.append(wifiScanCount);
4216 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004217 pw.println(sb.toString());
4218 }
4219
Adam Lesinski5f056f62016-07-14 16:56:08 -07004220 if (wifiWakeup > 0) {
4221 sb.setLength(0);
4222 sb.append(prefix);
4223 sb.append(" WiFi AP wakeups: ");
4224 sb.append(wifiWakeup);
4225 pw.println(sb.toString());
4226 }
4227
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004228 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4229 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004230
Adam Lesinski50e47602015-12-04 17:04:54 -08004231 if (btRxBytes > 0 || btTxBytes > 0) {
4232 pw.print(prefix); pw.print(" Bluetooth network: ");
4233 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4234 pw.print(formatBytesLocked(btTxBytes));
4235 pw.println(" sent");
4236 }
4237
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004238 uidActivity |= printTimer(pw, sb, u.getBluetoothScanTimer(), rawRealtime, which, prefix,
4239 "Bluetooth Scan");
4240
Dianne Hackborn617f8772009-03-31 15:04:46 -07004241 if (u.hasUserActivity()) {
4242 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004243 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004244 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004245 if (val != 0) {
4246 if (!hasData) {
4247 sb.setLength(0);
4248 sb.append(" User activity: ");
4249 hasData = true;
4250 } else {
4251 sb.append(", ");
4252 }
4253 sb.append(val);
4254 sb.append(" ");
4255 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4256 }
4257 }
4258 if (hasData) {
4259 pw.println(sb.toString());
4260 }
4261 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004263 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4264 = u.getWakelockStats();
4265 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004266 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004267 int countWakelock = 0;
4268 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4269 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4270 String linePrefix = ": ";
4271 sb.setLength(0);
4272 sb.append(prefix);
4273 sb.append(" Wake lock ");
4274 sb.append(wakelocks.keyAt(iw));
4275 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4276 "full", which, linePrefix);
4277 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
4278 "partial", which, linePrefix);
4279 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4280 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004281 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4282 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004283 sb.append(" realtime");
4284 pw.println(sb.toString());
4285 uidActivity = true;
4286 countWakelock++;
4287
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004288 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4289 rawRealtime, which);
4290 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4291 rawRealtime, which);
4292 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4293 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004294 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004295 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004296 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004297 if (countWakelock > 1) {
4298 if (totalFullWakelock != 0 || totalPartialWakelock != 0
4299 || totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004300 sb.setLength(0);
4301 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004302 sb.append(" TOTAL wake: ");
4303 boolean needComma = false;
4304 if (totalFullWakelock != 0) {
4305 needComma = true;
4306 formatTimeMs(sb, totalFullWakelock);
4307 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004308 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004309 if (totalPartialWakelock != 0) {
4310 if (needComma) {
4311 sb.append(", ");
4312 }
4313 needComma = true;
4314 formatTimeMs(sb, totalPartialWakelock);
4315 sb.append("partial");
4316 }
4317 if (totalWindowWakelock != 0) {
4318 if (needComma) {
4319 sb.append(", ");
4320 }
4321 needComma = true;
4322 formatTimeMs(sb, totalWindowWakelock);
4323 sb.append("window");
4324 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004325 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004326 if (needComma) {
4327 sb.append(",");
4328 }
4329 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004330 formatTimeMs(sb, totalDrawWakelock);
4331 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004332 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004333 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004334 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004335 }
4336 }
4337
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004338 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4339 for (int isy=syncs.size()-1; isy>=0; isy--) {
4340 final Timer timer = syncs.valueAt(isy);
4341 // Convert from microseconds to milliseconds with rounding
4342 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4343 final int count = timer.getCountLocked(which);
4344 sb.setLength(0);
4345 sb.append(prefix);
4346 sb.append(" Sync ");
4347 sb.append(syncs.keyAt(isy));
4348 sb.append(": ");
4349 if (totalTime != 0) {
4350 formatTimeMs(sb, totalTime);
4351 sb.append("realtime (");
4352 sb.append(count);
4353 sb.append(" times)");
4354 } else {
4355 sb.append("(not used)");
4356 }
4357 pw.println(sb.toString());
4358 uidActivity = true;
4359 }
4360
4361 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4362 for (int ij=jobs.size()-1; ij>=0; ij--) {
4363 final Timer timer = jobs.valueAt(ij);
4364 // Convert from microseconds to milliseconds with rounding
4365 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4366 final int count = timer.getCountLocked(which);
4367 sb.setLength(0);
4368 sb.append(prefix);
4369 sb.append(" Job ");
4370 sb.append(jobs.keyAt(ij));
4371 sb.append(": ");
4372 if (totalTime != 0) {
4373 formatTimeMs(sb, totalTime);
4374 sb.append("realtime (");
4375 sb.append(count);
4376 sb.append(" times)");
4377 } else {
4378 sb.append("(not used)");
4379 }
4380 pw.println(sb.toString());
4381 uidActivity = true;
4382 }
4383
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004384 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
4385 prefix, "Flashlight");
4386 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
4387 prefix, "Camera");
4388 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
4389 prefix, "Video");
4390 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
4391 prefix, "Audio");
4392
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004393 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4394 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004395 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004396 final Uid.Sensor se = sensors.valueAt(ise);
4397 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004398 sb.setLength(0);
4399 sb.append(prefix);
4400 sb.append(" Sensor ");
4401 int handle = se.getHandle();
4402 if (handle == Uid.Sensor.GPS) {
4403 sb.append("GPS");
4404 } else {
4405 sb.append(handle);
4406 }
4407 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004409 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004410 if (timer != null) {
4411 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004412 final long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn61659e52014-07-09 16:13:01 -07004413 rawRealtime, which) + 500) / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004414 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004415 //timer.logState();
4416 if (totalTime != 0) {
4417 formatTimeMs(sb, totalTime);
4418 sb.append("realtime (");
4419 sb.append(count);
4420 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004421 } else {
4422 sb.append("(not used)");
4423 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004424 } else {
4425 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004426 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004427
4428 pw.println(sb.toString());
4429 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004430 }
4431
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004432 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4433 "Vibrator");
4434 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4435 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004436
Dianne Hackborn61659e52014-07-09 16:13:01 -07004437 long totalStateTime = 0;
4438 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4439 long time = u.getProcessStateTime(ips, rawRealtime, which);
4440 if (time > 0) {
4441 totalStateTime += time;
4442 sb.setLength(0);
4443 sb.append(prefix);
4444 sb.append(" ");
4445 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4446 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08004447 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004448 pw.println(sb.toString());
4449 uidActivity = true;
4450 }
4451 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08004452 if (totalStateTime > 0) {
4453 sb.setLength(0);
4454 sb.append(prefix);
4455 sb.append(" Total running: ");
4456 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4457 pw.println(sb.toString());
4458 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004459
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004460 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4461 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004462 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
4463 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004464 sb.setLength(0);
4465 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004466 sb.append(" Total cpu time: u=");
4467 formatTimeMs(sb, userCpuTimeUs / 1000);
4468 sb.append("s=");
4469 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004470 sb.append("p=");
4471 printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0));
4472 sb.append("mAh");
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004473 pw.println(sb.toString());
4474 }
4475
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004476 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4477 = u.getProcessStats();
4478 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4479 final Uid.Proc ps = processStats.valueAt(ipr);
4480 long userTime;
4481 long systemTime;
4482 long foregroundTime;
4483 int starts;
4484 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004485
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004486 userTime = ps.getUserTime(which);
4487 systemTime = ps.getSystemTime(which);
4488 foregroundTime = ps.getForegroundTime(which);
4489 starts = ps.getStarts(which);
4490 final int numCrashes = ps.getNumCrashes(which);
4491 final int numAnrs = ps.getNumAnrs(which);
4492 numExcessive = which == STATS_SINCE_CHARGED
4493 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004495 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
4496 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
4497 sb.setLength(0);
4498 sb.append(prefix); sb.append(" Proc ");
4499 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
4500 sb.append(prefix); sb.append(" CPU: ");
4501 formatTimeMs(sb, userTime); sb.append("usr + ");
4502 formatTimeMs(sb, systemTime); sb.append("krn ; ");
4503 formatTimeMs(sb, foregroundTime); sb.append("fg");
4504 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
4505 sb.append("\n"); sb.append(prefix); sb.append(" ");
4506 boolean hasOne = false;
4507 if (starts != 0) {
4508 hasOne = true;
4509 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07004510 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004511 if (numCrashes != 0) {
4512 if (hasOne) {
4513 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004514 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004515 hasOne = true;
4516 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004517 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004518 if (numAnrs != 0) {
4519 if (hasOne) {
4520 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004521 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004522 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 }
4524 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004525 pw.println(sb.toString());
4526 for (int e=0; e<numExcessive; e++) {
4527 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
4528 if (ew != null) {
4529 pw.print(prefix); pw.print(" * Killed for ");
4530 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
4531 pw.print("wake lock");
4532 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
4533 pw.print("cpu");
4534 } else {
4535 pw.print("unknown");
4536 }
4537 pw.print(" use: ");
4538 TimeUtils.formatDuration(ew.usedTime, pw);
4539 pw.print(" over ");
4540 TimeUtils.formatDuration(ew.overTime, pw);
4541 if (ew.overTime != 0) {
4542 pw.print(" (");
4543 pw.print((ew.usedTime*100)/ew.overTime);
4544 pw.println("%)");
4545 }
4546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004547 }
4548 uidActivity = true;
4549 }
4550 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004551
4552 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4553 = u.getPackageStats();
4554 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4555 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
4556 pw.println(":");
4557 boolean apkActivity = false;
4558 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4559 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4560 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
4561 pw.print(prefix); pw.print(" Wakeup alarm ");
4562 pw.print(alarms.keyAt(iwa)); pw.print(": ");
4563 pw.print(alarms.valueAt(iwa).getCountLocked(which));
4564 pw.println(" times");
4565 apkActivity = true;
4566 }
4567 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4568 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4569 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4570 final long startTime = ss.getStartTime(batteryUptime, which);
4571 final int starts = ss.getStarts(which);
4572 final int launches = ss.getLaunches(which);
4573 if (startTime != 0 || starts != 0 || launches != 0) {
4574 sb.setLength(0);
4575 sb.append(prefix); sb.append(" Service ");
4576 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
4577 sb.append(prefix); sb.append(" Created for: ");
4578 formatTimeMs(sb, startTime / 1000);
4579 sb.append("uptime\n");
4580 sb.append(prefix); sb.append(" Starts: ");
4581 sb.append(starts);
4582 sb.append(", launches: "); sb.append(launches);
4583 pw.println(sb.toString());
4584 apkActivity = true;
4585 }
4586 }
4587 if (!apkActivity) {
4588 pw.print(prefix); pw.println(" (nothing executed)");
4589 }
4590 uidActivity = true;
4591 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004592 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004593 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004594 }
4595 }
4596 }
4597
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004598 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004599 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004600 int diff = oldval ^ newval;
4601 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004602 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004603 for (int i=0; i<descriptions.length; i++) {
4604 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004605 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004606 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004607 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004608 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004609 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004610 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
4611 didWake = true;
4612 pw.print("=");
4613 if (longNames) {
4614 UserHandle.formatUid(pw, wakelockTag.uid);
4615 pw.print(":\"");
4616 pw.print(wakelockTag.string);
4617 pw.print("\"");
4618 } else {
4619 pw.print(wakelockTag.poolIdx);
4620 }
4621 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004622 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004623 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004624 pw.print("=");
4625 int val = (newval&bd.mask)>>bd.shift;
4626 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004627 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004628 } else {
4629 pw.print(val);
4630 }
4631 }
4632 }
4633 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004634 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07004635 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004636 if (longNames) {
4637 UserHandle.formatUid(pw, wakelockTag.uid);
4638 pw.print(":\"");
4639 pw.print(wakelockTag.string);
4640 pw.print("\"");
4641 } else {
4642 pw.print(wakelockTag.poolIdx);
4643 }
4644 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004645 }
4646
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004647 public void prepareForDumpLocked() {
4648 }
4649
4650 public static class HistoryPrinter {
4651 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004652 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004653 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004654 int oldStatus = -1;
4655 int oldHealth = -1;
4656 int oldPlug = -1;
4657 int oldTemp = -1;
4658 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004659 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004660 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004661
Dianne Hackborn3251b902014-06-20 14:40:53 -07004662 void reset() {
4663 oldState = oldState2 = 0;
4664 oldLevel = -1;
4665 oldStatus = -1;
4666 oldHealth = -1;
4667 oldPlug = -1;
4668 oldTemp = -1;
4669 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004670 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07004671 }
4672
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004673 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004674 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004675 if (!checkin) {
4676 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004677 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004678 pw.print(" (");
4679 pw.print(rec.numReadInts);
4680 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004681 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004682 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4683 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004684 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004685 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004686 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004687 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004688 }
4689 lastTime = rec.time;
4690 }
4691 if (rec.cmd == HistoryItem.CMD_START) {
4692 if (checkin) {
4693 pw.print(":");
4694 }
4695 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004696 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004697 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4698 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004699 if (checkin) {
4700 pw.print(":");
4701 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004702 if (rec.cmd == HistoryItem.CMD_RESET) {
4703 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004704 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004705 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004706 pw.print("TIME:");
4707 if (checkin) {
4708 pw.println(rec.currentTime);
4709 } else {
4710 pw.print(" ");
4711 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4712 rec.currentTime).toString());
4713 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004714 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4715 if (checkin) {
4716 pw.print(":");
4717 }
4718 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004719 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4720 if (checkin) {
4721 pw.print(":");
4722 }
4723 pw.println("*OVERFLOW*");
4724 } else {
4725 if (!checkin) {
4726 if (rec.batteryLevel < 10) pw.print("00");
4727 else if (rec.batteryLevel < 100) pw.print("0");
4728 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004729 if (verbose) {
4730 pw.print(" ");
4731 if (rec.states < 0) ;
4732 else if (rec.states < 0x10) pw.print("0000000");
4733 else if (rec.states < 0x100) pw.print("000000");
4734 else if (rec.states < 0x1000) pw.print("00000");
4735 else if (rec.states < 0x10000) pw.print("0000");
4736 else if (rec.states < 0x100000) pw.print("000");
4737 else if (rec.states < 0x1000000) pw.print("00");
4738 else if (rec.states < 0x10000000) pw.print("0");
4739 pw.print(Integer.toHexString(rec.states));
4740 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004741 } else {
4742 if (oldLevel != rec.batteryLevel) {
4743 oldLevel = rec.batteryLevel;
4744 pw.print(",Bl="); pw.print(rec.batteryLevel);
4745 }
4746 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004747 if (oldStatus != rec.batteryStatus) {
4748 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004749 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004750 switch (oldStatus) {
4751 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004752 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004753 break;
4754 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004755 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004756 break;
4757 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004758 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004759 break;
4760 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004761 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004762 break;
4763 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004764 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004765 break;
4766 default:
4767 pw.print(oldStatus);
4768 break;
4769 }
4770 }
4771 if (oldHealth != rec.batteryHealth) {
4772 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004773 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004774 switch (oldHealth) {
4775 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004776 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004777 break;
4778 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004779 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004780 break;
4781 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004782 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004783 break;
4784 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004785 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004786 break;
4787 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004788 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004789 break;
4790 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004791 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004792 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004793 case BatteryManager.BATTERY_HEALTH_COLD:
4794 pw.print(checkin ? "c" : "cold");
4795 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004796 default:
4797 pw.print(oldHealth);
4798 break;
4799 }
4800 }
4801 if (oldPlug != rec.batteryPlugType) {
4802 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004803 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004804 switch (oldPlug) {
4805 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004806 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004807 break;
4808 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004809 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004810 break;
4811 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004812 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004813 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004814 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004815 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004816 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004817 default:
4818 pw.print(oldPlug);
4819 break;
4820 }
4821 }
4822 if (oldTemp != rec.batteryTemperature) {
4823 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004824 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004825 pw.print(oldTemp);
4826 }
4827 if (oldVolt != rec.batteryVoltage) {
4828 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004829 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004830 pw.print(oldVolt);
4831 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004832 final int chargeMAh = rec.batteryChargeUAh / 1000;
4833 if (oldChargeMAh != chargeMAh) {
4834 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07004835 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07004836 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07004837 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004838 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004839 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004840 printBitDescriptions(pw, oldState2, rec.states2, null,
4841 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004842 if (rec.wakeReasonTag != null) {
4843 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004844 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004845 pw.print(rec.wakeReasonTag.poolIdx);
4846 } else {
4847 pw.print(" wake_reason=");
4848 pw.print(rec.wakeReasonTag.uid);
4849 pw.print(":\"");
4850 pw.print(rec.wakeReasonTag.string);
4851 pw.print("\"");
4852 }
4853 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004854 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004855 pw.print(checkin ? "," : " ");
4856 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4857 pw.print("+");
4858 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4859 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004860 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004861 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4862 : HISTORY_EVENT_NAMES;
4863 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4864 | HistoryItem.EVENT_FLAG_FINISH);
4865 if (idx >= 0 && idx < eventNames.length) {
4866 pw.print(eventNames[idx]);
4867 } else {
4868 pw.print(checkin ? "Ev" : "event");
4869 pw.print(idx);
4870 }
4871 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004872 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004873 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004874 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004875 UserHandle.formatUid(pw, rec.eventTag.uid);
4876 pw.print(":\"");
4877 pw.print(rec.eventTag.string);
4878 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004879 }
4880 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004881 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004882 if (rec.stepDetails != null) {
4883 if (!checkin) {
4884 pw.print(" Details: cpu=");
4885 pw.print(rec.stepDetails.userTime);
4886 pw.print("u+");
4887 pw.print(rec.stepDetails.systemTime);
4888 pw.print("s");
4889 if (rec.stepDetails.appCpuUid1 >= 0) {
4890 pw.print(" (");
4891 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4892 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4893 if (rec.stepDetails.appCpuUid2 >= 0) {
4894 pw.print(", ");
4895 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4896 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4897 }
4898 if (rec.stepDetails.appCpuUid3 >= 0) {
4899 pw.print(", ");
4900 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4901 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4902 }
4903 pw.print(')');
4904 }
4905 pw.println();
4906 pw.print(" /proc/stat=");
4907 pw.print(rec.stepDetails.statUserTime);
4908 pw.print(" usr, ");
4909 pw.print(rec.stepDetails.statSystemTime);
4910 pw.print(" sys, ");
4911 pw.print(rec.stepDetails.statIOWaitTime);
4912 pw.print(" io, ");
4913 pw.print(rec.stepDetails.statIrqTime);
4914 pw.print(" irq, ");
4915 pw.print(rec.stepDetails.statSoftIrqTime);
4916 pw.print(" sirq, ");
4917 pw.print(rec.stepDetails.statIdlTime);
4918 pw.print(" idle");
4919 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4920 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4921 + rec.stepDetails.statSoftIrqTime;
4922 int total = totalRun + rec.stepDetails.statIdlTime;
4923 if (total > 0) {
4924 pw.print(" (");
4925 float perc = ((float)totalRun) / ((float)total) * 100;
4926 pw.print(String.format("%.1f%%", perc));
4927 pw.print(" of ");
4928 StringBuilder sb = new StringBuilder(64);
4929 formatTimeMsNoSpace(sb, total*10);
4930 pw.print(sb);
4931 pw.print(")");
4932 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07004933 pw.print(", PlatformIdleStat ");
4934 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004935 pw.println();
4936 } else {
4937 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4938 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4939 pw.print(rec.stepDetails.userTime);
4940 pw.print(":");
4941 pw.print(rec.stepDetails.systemTime);
4942 if (rec.stepDetails.appCpuUid1 >= 0) {
4943 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4944 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4945 if (rec.stepDetails.appCpuUid2 >= 0) {
4946 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4947 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4948 }
4949 if (rec.stepDetails.appCpuUid3 >= 0) {
4950 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4951 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4952 }
4953 }
4954 pw.println();
4955 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4956 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4957 pw.print(rec.stepDetails.statUserTime);
4958 pw.print(',');
4959 pw.print(rec.stepDetails.statSystemTime);
4960 pw.print(',');
4961 pw.print(rec.stepDetails.statIOWaitTime);
4962 pw.print(',');
4963 pw.print(rec.stepDetails.statIrqTime);
4964 pw.print(',');
4965 pw.print(rec.stepDetails.statSoftIrqTime);
4966 pw.print(',');
4967 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07004968 pw.print(',');
4969 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004970 pw.println();
4971 }
4972 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004973 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004974 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004975 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004976 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004977
4978 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4979 UserHandle.formatUid(pw, uid);
4980 pw.print("=");
4981 pw.print(utime);
4982 pw.print("u+");
4983 pw.print(stime);
4984 pw.print("s");
4985 }
4986
4987 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
4988 pw.print('/');
4989 pw.print(uid);
4990 pw.print(":");
4991 pw.print(utime);
4992 pw.print(":");
4993 pw.print(stime);
4994 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004995 }
4996
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004997 private void printSizeValue(PrintWriter pw, long size) {
4998 float result = size;
4999 String suffix = "";
5000 if (result >= 10*1024) {
5001 suffix = "KB";
5002 result = result / 1024;
5003 }
5004 if (result >= 10*1024) {
5005 suffix = "MB";
5006 result = result / 1024;
5007 }
5008 if (result >= 10*1024) {
5009 suffix = "GB";
5010 result = result / 1024;
5011 }
5012 if (result >= 10*1024) {
5013 suffix = "TB";
5014 result = result / 1024;
5015 }
5016 if (result >= 10*1024) {
5017 suffix = "PB";
5018 result = result / 1024;
5019 }
5020 pw.print((int)result);
5021 pw.print(suffix);
5022 }
5023
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005024 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5025 String label3, long estimatedTime) {
5026 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005027 return false;
5028 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005029 pw.print(label1);
5030 pw.print(label2);
5031 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005032 StringBuilder sb = new StringBuilder(64);
5033 formatTimeMs(sb, estimatedTime);
5034 pw.print(sb);
5035 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005036 return true;
5037 }
5038
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005039 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5040 LevelStepTracker steps, boolean checkin) {
5041 if (steps == null) {
5042 return false;
5043 }
5044 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005045 if (count <= 0) {
5046 return false;
5047 }
5048 if (!checkin) {
5049 pw.println(header);
5050 }
Kweku Adams030980a2015-04-01 16:07:48 -07005051 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005052 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005053 long duration = steps.getDurationAt(i);
5054 int level = steps.getLevelAt(i);
5055 long initMode = steps.getInitModeAt(i);
5056 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005057 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005058 lineArgs[0] = Long.toString(duration);
5059 lineArgs[1] = Integer.toString(level);
5060 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5061 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5062 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5063 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5064 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5065 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005066 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005067 }
5068 } else {
5069 lineArgs[2] = "";
5070 }
5071 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5072 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5073 } else {
5074 lineArgs[3] = "";
5075 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005076 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005077 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005078 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005079 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005080 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005081 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5082 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005083 pw.print(prefix);
5084 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005085 TimeUtils.formatDuration(duration, pw);
5086 pw.print(" to "); pw.print(level);
5087 boolean haveModes = false;
5088 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5089 pw.print(" (");
5090 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5091 case Display.STATE_OFF: pw.print("screen-off"); break;
5092 case Display.STATE_ON: pw.print("screen-on"); break;
5093 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5094 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005095 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005096 }
5097 haveModes = true;
5098 }
5099 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5100 pw.print(haveModes ? ", " : " (");
5101 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5102 ? "power-save-on" : "power-save-off");
5103 haveModes = true;
5104 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005105 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5106 pw.print(haveModes ? ", " : " (");
5107 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5108 ? "device-idle-on" : "device-idle-off");
5109 haveModes = true;
5110 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005111 if (haveModes) {
5112 pw.print(")");
5113 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005114 pw.println();
5115 }
5116 }
5117 return true;
5118 }
5119
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005120 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005121 public static final int DUMP_DAILY_ONLY = 1<<2;
5122 public static final int DUMP_HISTORY_ONLY = 1<<3;
5123 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5124 public static final int DUMP_VERBOSE = 1<<5;
5125 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005126
Dianne Hackborn37de0982014-05-09 09:32:18 -07005127 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5128 final HistoryPrinter hprinter = new HistoryPrinter();
5129 final HistoryItem rec = new HistoryItem();
5130 long lastTime = -1;
5131 long baseTime = -1;
5132 boolean printed = false;
5133 HistoryEventTracker tracker = null;
5134 while (getNextHistoryLocked(rec)) {
5135 lastTime = rec.time;
5136 if (baseTime < 0) {
5137 baseTime = lastTime;
5138 }
5139 if (rec.time >= histStart) {
5140 if (histStart >= 0 && !printed) {
5141 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005142 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005143 || rec.cmd == HistoryItem.CMD_START
5144 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005145 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005146 hprinter.printNextItem(pw, rec, baseTime, checkin,
5147 (flags&DUMP_VERBOSE) != 0);
5148 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005149 } else if (rec.currentTime != 0) {
5150 printed = true;
5151 byte cmd = rec.cmd;
5152 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005153 hprinter.printNextItem(pw, rec, baseTime, checkin,
5154 (flags&DUMP_VERBOSE) != 0);
5155 rec.cmd = cmd;
5156 }
5157 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005158 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5159 hprinter.printNextItem(pw, rec, baseTime, checkin,
5160 (flags&DUMP_VERBOSE) != 0);
5161 rec.cmd = HistoryItem.CMD_UPDATE;
5162 }
5163 int oldEventCode = rec.eventCode;
5164 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005165 rec.eventTag = new HistoryTag();
5166 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5167 HashMap<String, SparseIntArray> active
5168 = tracker.getStateForEvent(i);
5169 if (active == null) {
5170 continue;
5171 }
5172 for (HashMap.Entry<String, SparseIntArray> ent
5173 : active.entrySet()) {
5174 SparseIntArray uids = ent.getValue();
5175 for (int j=0; j<uids.size(); j++) {
5176 rec.eventCode = i;
5177 rec.eventTag.string = ent.getKey();
5178 rec.eventTag.uid = uids.keyAt(j);
5179 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005180 hprinter.printNextItem(pw, rec, baseTime, checkin,
5181 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005182 rec.wakeReasonTag = null;
5183 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005184 }
5185 }
5186 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005187 rec.eventCode = oldEventCode;
5188 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005189 tracker = null;
5190 }
5191 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005192 hprinter.printNextItem(pw, rec, baseTime, checkin,
5193 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005194 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5195 // This is an attempt to aggregate the previous state and generate
5196 // fake events to reflect that state at the point where we start
5197 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005198 if (tracker == null) {
5199 tracker = new HistoryEventTracker();
5200 }
5201 tracker.updateState(rec.eventCode, rec.eventTag.string,
5202 rec.eventTag.uid, rec.eventTag.poolIdx);
5203 }
5204 }
5205 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005206 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005207 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5208 }
5209 }
5210
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005211 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5212 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5213 if (steps == null) {
5214 return;
5215 }
5216 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5217 if (timeRemaining >= 0) {
5218 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5219 tmpSb.setLength(0);
5220 formatTimeMs(tmpSb, timeRemaining);
5221 pw.print(tmpSb);
5222 pw.print(" (from "); pw.print(tmpOutInt[0]);
5223 pw.println(" steps)");
5224 }
5225 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5226 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5227 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5228 if (estimatedTime > 0) {
5229 pw.print(prefix); pw.print(label); pw.print(" ");
5230 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5231 pw.print(" time: ");
5232 tmpSb.setLength(0);
5233 formatTimeMs(tmpSb, estimatedTime);
5234 pw.print(tmpSb);
5235 pw.print(" (from "); pw.print(tmpOutInt[0]);
5236 pw.println(" steps)");
5237 }
5238 }
5239 }
5240
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005241 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5242 ArrayList<PackageChange> changes) {
5243 if (changes == null) {
5244 return;
5245 }
5246 pw.print(prefix); pw.println("Package changes:");
5247 for (int i=0; i<changes.size(); i++) {
5248 PackageChange pc = changes.get(i);
5249 if (pc.mUpdate) {
5250 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5251 pw.print(" vers="); pw.println(pc.mVersionCode);
5252 } else {
5253 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5254 }
5255 }
5256 }
5257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005258 /**
5259 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5260 *
5261 * @param pw a Printer to receive the dump output.
5262 */
5263 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005264 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005265 prepareForDumpLocked();
5266
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005267 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005268 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005269
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005270 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005271 final long historyTotalSize = getHistoryTotalSize();
5272 final long historyUsedSize = getHistoryUsedSize();
5273 if (startIteratingHistoryLocked()) {
5274 try {
5275 pw.print("Battery History (");
5276 pw.print((100*historyUsedSize)/historyTotalSize);
5277 pw.print("% used, ");
5278 printSizeValue(pw, historyUsedSize);
5279 pw.print(" used of ");
5280 printSizeValue(pw, historyTotalSize);
5281 pw.print(", ");
5282 pw.print(getHistoryStringPoolSize());
5283 pw.print(" strings using ");
5284 printSizeValue(pw, getHistoryStringPoolBytes());
5285 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005286 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005287 pw.println();
5288 } finally {
5289 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005290 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005291 }
5292
5293 if (startIteratingOldHistoryLocked()) {
5294 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005295 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005296 pw.println("Old battery History:");
5297 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005298 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005299 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005300 if (baseTime < 0) {
5301 baseTime = rec.time;
5302 }
5303 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005304 }
5305 pw.println();
5306 } finally {
5307 finishIteratingOldHistoryLocked();
5308 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005309 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005310 }
5311
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005312 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005313 return;
5314 }
5315
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005316 if (!filtering) {
5317 SparseArray<? extends Uid> uidStats = getUidStats();
5318 final int NU = uidStats.size();
5319 boolean didPid = false;
5320 long nowRealtime = SystemClock.elapsedRealtime();
5321 for (int i=0; i<NU; i++) {
5322 Uid uid = uidStats.valueAt(i);
5323 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
5324 if (pids != null) {
5325 for (int j=0; j<pids.size(); j++) {
5326 Uid.Pid pid = pids.valueAt(j);
5327 if (!didPid) {
5328 pw.println("Per-PID Stats:");
5329 didPid = true;
5330 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005331 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
5332 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005333 pw.print(" PID "); pw.print(pids.keyAt(j));
5334 pw.print(" wake time: ");
5335 TimeUtils.formatDuration(time, pw);
5336 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005337 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005338 }
5339 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005340 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005341 pw.println();
5342 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005343 }
5344
5345 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005346 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
5347 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005348 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5349 if (timeRemaining >= 0) {
5350 pw.print(" Estimated discharge time remaining: ");
5351 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5352 pw.println();
5353 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005354 final LevelStepTracker steps = getDischargeLevelStepTracker();
5355 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5356 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
5357 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5358 STEP_LEVEL_MODE_VALUES[i], null));
5359 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005360 pw.println();
5361 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005362 if (dumpDurationSteps(pw, " ", "Charge step durations:",
5363 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005364 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5365 if (timeRemaining >= 0) {
5366 pw.print(" Estimated charge time remaining: ");
5367 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5368 pw.println();
5369 }
5370 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005371 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005372 }
5373 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
5374 pw.println("Daily stats:");
5375 pw.print(" Current start time: ");
5376 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5377 getCurrentDailyStartTime()).toString());
5378 pw.print(" Next min deadline: ");
5379 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5380 getNextMinDailyDeadline()).toString());
5381 pw.print(" Next max deadline: ");
5382 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5383 getNextMaxDailyDeadline()).toString());
5384 StringBuilder sb = new StringBuilder(64);
5385 int[] outInt = new int[1];
5386 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
5387 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005388 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
5389 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005390 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005391 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
5392 dsteps, false)) {
5393 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5394 sb, outInt);
5395 }
5396 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
5397 csteps, false)) {
5398 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5399 sb, outInt);
5400 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005401 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005402 } else {
5403 pw.println(" Current daily steps:");
5404 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5405 sb, outInt);
5406 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5407 sb, outInt);
5408 }
5409 }
5410 DailyItem dit;
5411 int curIndex = 0;
5412 while ((dit=getDailyItemLocked(curIndex)) != null) {
5413 curIndex++;
5414 if ((flags&DUMP_DAILY_ONLY) != 0) {
5415 pw.println();
5416 }
5417 pw.print(" Daily from ");
5418 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
5419 pw.print(" to ");
5420 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
5421 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005422 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005423 if (dumpDurationSteps(pw, " ",
5424 " Discharge step durations:", dit.mDischargeSteps, false)) {
5425 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5426 sb, outInt);
5427 }
5428 if (dumpDurationSteps(pw, " ",
5429 " Charge step durations:", dit.mChargeSteps, false)) {
5430 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5431 sb, outInt);
5432 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005433 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005434 } else {
5435 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5436 sb, outInt);
5437 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5438 sb, outInt);
5439 }
5440 }
5441 pw.println();
5442 }
5443 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005444 pw.println("Statistics since last charge:");
5445 pw.println(" System starts: " + getStartCount()
5446 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005447 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5448 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005449 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005450 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005451 }
5452
5453 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005454 public void dumpCheckinLocked(Context context, PrintWriter pw,
5455 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005456 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005457
5458 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005459 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5460 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005461
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005462 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5463
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005464 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005465 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005466
5467 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005468 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005469 try {
5470 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5471 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5472 pw.print(HISTORY_STRING_POOL); pw.print(',');
5473 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005474 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005475 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005476 pw.print(",\"");
5477 String str = getHistoryTagPoolString(i);
5478 str = str.replace("\\", "\\\\");
5479 str = str.replace("\"", "\\\"");
5480 pw.print(str);
5481 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005482 pw.println();
5483 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005484 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005485 } finally {
5486 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08005487 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005488 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005489 }
5490
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005491 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005492 return;
5493 }
5494
Dianne Hackborne4a59512010-12-07 11:08:07 -08005495 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005496 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08005497 for (int i=0; i<apps.size(); i++) {
5498 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005499 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
5500 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08005501 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005502 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
5503 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005504 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005505 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005506 }
5507 SparseArray<? extends Uid> uidStats = getUidStats();
5508 final int NU = uidStats.size();
5509 String[] lineArgs = new String[2];
5510 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005511 int uid = UserHandle.getAppId(uidStats.keyAt(i));
5512 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
5513 if (pkgs != null && !pkgs.second.value) {
5514 pkgs.second.value = true;
5515 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08005516 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005517 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005518 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
5519 (Object[])lineArgs);
5520 }
5521 }
5522 }
5523 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005524 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005525 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005526 String[] lineArgs = new String[1];
5527 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5528 if (timeRemaining >= 0) {
5529 lineArgs[0] = Long.toString(timeRemaining);
5530 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
5531 (Object[])lineArgs);
5532 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005533 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005534 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5535 if (timeRemaining >= 0) {
5536 lineArgs[0] = Long.toString(timeRemaining);
5537 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
5538 (Object[])lineArgs);
5539 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07005540 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
5541 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005542 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005543 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005544}