blob: 959b30946c8a0c05bfb43856eabd05c7a23ff9d0 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.os;
18
19import java.io.PrintWriter;
Dianne Hackborne4a59512010-12-07 11:08:07 -080020import java.util.ArrayList;
Dianne Hackborn81038902012-11-26 17:04:09 -080021import java.util.Collections;
22import java.util.Comparator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import java.util.Formatter;
Dianne Hackborn37de0982014-05-09 09:32:18 -070024import java.util.HashMap;
Dianne Hackborne4a59512010-12-07 11:08:07 -080025import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import java.util.Map;
27
Dianne Hackborna7c837f2014-01-15 16:20:44 -080028import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080029import android.content.pm.ApplicationInfo;
Wink Saville52840902011-02-18 12:40:47 -080030import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080031import android.text.format.DateFormat;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070032import android.util.ArrayMap;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070033import android.util.MutableBoolean;
34import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.util.Printer;
36import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070037import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070038import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070039import android.view.Display;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080040import com.android.internal.os.BatterySipper;
41import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43/**
44 * A class providing access to battery usage statistics, including information on
45 * wakelocks, processes, packages, and services. All times are represented in microseconds
46 * except where indicated otherwise.
47 * @hide
48 */
49public abstract class BatteryStats implements Parcelable {
50
51 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070052
53 /** @hide */
54 public static final String SERVICE_NAME = "batterystats";
55
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 /**
57 * A constant indicating a partial wake lock timer.
58 */
59 public static final int WAKE_TYPE_PARTIAL = 0;
60
61 /**
62 * A constant indicating a full wake lock timer.
63 */
64 public static final int WAKE_TYPE_FULL = 1;
65
66 /**
67 * A constant indicating a window wake lock timer.
68 */
69 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 /**
72 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 */
74 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070075
76 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070077 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070078 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070079 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070080
81 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070082 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070083 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070084 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070085
86 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070087 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070088 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070089 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
Dianne Hackborn62793e42015-03-09 11:15:41 -070091 /**
92 * A constant indicating a wifi multicast timer
93 */
94 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070095
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070097 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070098 */
99 public static final int VIDEO_TURNED_ON = 8;
100
101 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800102 * A constant indicating a vibrator on timer
103 */
104 public static final int VIBRATOR_ON = 9;
105
106 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700107 * A constant indicating a foreground activity timer
108 */
109 public static final int FOREGROUND_ACTIVITY = 10;
110
111 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700112 * A constant indicating a wifi batched scan is active
113 */
114 public static final int WIFI_BATCHED_SCAN = 11;
115
116 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700117 * A constant indicating a process state timer
118 */
119 public static final int PROCESS_STATE = 12;
120
121 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700122 * A constant indicating a sync timer
123 */
124 public static final int SYNC = 13;
125
126 /**
127 * A constant indicating a job timer
128 */
129 public static final int JOB = 14;
130
131 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800132 * A constant indicating an audio turn on timer
133 */
134 public static final int AUDIO_TURNED_ON = 15;
135
136 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700137 * A constant indicating a flashlight turn on timer
138 */
139 public static final int FLASHLIGHT_TURNED_ON = 16;
140
141 /**
142 * A constant indicating a camera turn on timer
143 */
144 public static final int CAMERA_TURNED_ON = 17;
145
146 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700147 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700148 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700149 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700150
151 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800152 * A constant indicating a bluetooth scan timer.
153 */
154 public static final int BLUETOOTH_SCAN_ON = 19;
155
156 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 * Include all of the data in the stats, including previously saved data.
158 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700159 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160
161 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 * Include only the current run in the stats.
163 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700164 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165
166 /**
167 * Include only the run since the last time the device was unplugged in the stats.
168 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700169 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700170
171 // NOTE: Update this list if you add/change any stats above.
172 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700173 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700174 private static final String[] STAT_NAMES = { "l", "c", "u" };
175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700177 * Current version of checkin data format.
178 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800179 static final String CHECKIN_VERSION = "17";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700180
181 /**
182 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700184 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700185
Evan Millar22ac0432009-03-31 11:33:18 -0700186 private static final long BYTES_PER_KB = 1024;
187 private static final long BYTES_PER_MB = 1048576; // 1024^2
188 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700190 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800191 private static final String UID_DATA = "uid";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700193 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700194 private static final String CPU_DATA = "cpu";
Evan Millare84de8d2009-04-02 22:16:12 -0700195 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800196 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700197 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700198 private static final String STATE_TIME_DATA = "st";
Evan Millare84de8d2009-04-02 22:16:12 -0700199 private static final String WAKELOCK_DATA = "wl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700200 private static final String SYNC_DATA = "sy";
201 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700202 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700203 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700204 private static final String NETWORK_DATA = "nt";
205 private static final String USER_ACTIVITY_DATA = "ua";
206 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800207 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700208 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700209 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700210 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800211 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
212 private static final String WIFI_CONTROLLER_DATA = "wfcd";
213 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
214 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700215 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700216 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800217 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800218 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
219 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800220 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700221 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700222 private static final String SCREEN_BRIGHTNESS_DATA = "br";
223 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700224 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700225 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
226 private static final String DATA_CONNECTION_TIME_DATA = "dct";
227 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800228 private static final String WIFI_STATE_TIME_DATA = "wst";
229 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700230 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
231 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
232 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
233 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800234 private static final String POWER_USE_SUMMARY_DATA = "pws";
235 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700236 private static final String DISCHARGE_STEP_DATA = "dsd";
237 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700238 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
239 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700240 private static final String FLASHLIGHT_DATA = "fla";
241 private static final String CAMERA_DATA = "cam";
242 private static final String VIDEO_DATA = "vid";
243 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244
Adam Lesinski010bf372016-04-11 12:18:18 -0700245 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
246
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700247 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 private final Formatter mFormatter = new Formatter(mFormatBuilder);
249
250 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700251 * State for keeping track of counting information.
252 */
253 public static abstract class Counter {
254
255 /**
256 * Returns the count associated with this Counter for the
257 * selected type of statistics.
258 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700259 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700260 */
Evan Millarc64edde2009-04-18 12:26:32 -0700261 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700262
263 /**
264 * Temporary for debugging.
265 */
266 public abstract void logState(Printer pw, String prefix);
267 }
268
269 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700270 * State for keeping track of long counting information.
271 */
272 public static abstract class LongCounter {
273
274 /**
275 * Returns the count associated with this Counter for the
276 * selected type of statistics.
277 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700278 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700279 */
280 public abstract long getCountLocked(int which);
281
282 /**
283 * Temporary for debugging.
284 */
285 public abstract void logState(Printer pw, String prefix);
286 }
287
288 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800289 * Container class that aggregates counters for transmit, receive, and idle state of a
290 * radio controller.
291 */
292 public static abstract class ControllerActivityCounter {
293 /**
294 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
295 * idle state.
296 */
297 public abstract LongCounter getIdleTimeCounter();
298
299 /**
300 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
301 * receive state.
302 */
303 public abstract LongCounter getRxTimeCounter();
304
305 /**
306 * An array of {@link LongCounter}, representing various transmit levels, where each level
307 * may draw a different amount of power. The levels themselves are controller-specific.
308 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
309 * various transmit level states.
310 */
311 public abstract LongCounter[] getTxTimeCounters();
312
313 /**
314 * @return a non-null {@link LongCounter} representing the power consumed by the controller
315 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
316 * yield a value of 0 if the device doesn't support power calculations.
317 */
318 public abstract LongCounter getPowerCounter();
319 }
320
321 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 * State for keeping track of timing information.
323 */
324 public static abstract class Timer {
325
326 /**
327 * Returns the count associated with this Timer for the
328 * selected type of statistics.
329 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700330 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 */
Evan Millarc64edde2009-04-18 12:26:32 -0700332 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333
334 /**
335 * Returns the total time in microseconds associated with this Timer for the
336 * selected type of statistics.
337 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800338 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700339 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 * @return a time in microseconds
341 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800342 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700345 * Returns the total time in microseconds associated with this Timer since the
346 * 'mark' was last set.
347 *
348 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
349 * @return a time in microseconds
350 */
351 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
352
353 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 * Temporary for debugging.
355 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700356 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 }
358
359 /**
360 * The statistics associated with a particular uid.
361 */
362 public static abstract class Uid {
363
364 /**
365 * Returns a mapping containing wakelock statistics.
366 *
367 * @return a Map from Strings to Uid.Wakelock objects.
368 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700369 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370
371 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700372 * Returns a mapping containing sync statistics.
373 *
374 * @return a Map from Strings to Timer objects.
375 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700376 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700377
378 /**
379 * Returns a mapping containing scheduled job statistics.
380 *
381 * @return a Map from Strings to Timer objects.
382 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700383 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700384
385 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 * The statistics associated with a particular wake lock.
387 */
388 public static abstract class Wakelock {
389 public abstract Timer getWakeTime(int type);
390 }
391
392 /**
393 * Returns a mapping containing sensor statistics.
394 *
395 * @return a Map from Integer sensor ids to Uid.Sensor objects.
396 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700397 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398
399 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700400 * Returns a mapping containing active process data.
401 */
402 public abstract SparseArray<? extends Pid> getPidStats();
403
404 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 * Returns a mapping containing process statistics.
406 *
407 * @return a Map from Strings to Uid.Proc objects.
408 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700409 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410
411 /**
412 * Returns a mapping containing package statistics.
413 *
414 * @return a Map from Strings to Uid.Pkg objects.
415 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700416 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700417
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800418 public abstract ControllerActivityCounter getWifiControllerActivity();
419 public abstract ControllerActivityCounter getBluetoothControllerActivity();
420 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800421
422 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 * {@hide}
424 */
425 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700426
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800427 public abstract void noteWifiRunningLocked(long elapsedRealtime);
428 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
429 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
430 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
431 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
432 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
433 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
434 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
435 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
436 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800437 public abstract void noteActivityResumedLocked(long elapsedRealtime);
438 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800439 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
440 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
441 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700442 public abstract int getWifiScanCount(int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800443 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700444 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800445 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700446 public abstract Timer getAudioTurnedOnTimer();
447 public abstract Timer getVideoTurnedOnTimer();
448 public abstract Timer getFlashlightTurnedOnTimer();
449 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700450 public abstract Timer getForegroundActivityTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800451 public abstract Timer getBluetoothScanTimer();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700452
Dianne Hackborna0200e32016-03-30 18:01:41 -0700453 // Note: the following times are disjoint. They can be added together to find the
454 // total time a uid has had any processes running at all.
455
456 /**
457 * Time this uid has any processes in the top state (or above such as persistent).
458 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800459 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700460 /**
461 * Time this uid has any process with a started out bound foreground service, but
462 * none in the "top" state.
463 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800464 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700465 /**
466 * Time this uid has any process that is top while the device is sleeping, but none
467 * in the "foreground service" or better state.
468 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800469 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700470 /**
471 * Time this uid has any process in an active foreground state, but none in the
472 * "top sleeping" or better state.
473 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800474 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700475 /**
476 * Time this uid has any process in an active background state, but none in the
477 * "foreground" or better state.
478 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800479 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700480 /**
481 * Time this uid has any processes that are sitting around cached, not in one of the
482 * other active states.
483 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800484 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700485 /**
486 * Total number of process states we track.
487 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800488 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700489
490 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800491 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700492 };
493
494 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800495 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700496
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800497 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498
Robert Greenwalta029ea12013-09-25 16:38:12 -0700499 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
500
Dianne Hackborn617f8772009-03-31 15:04:46 -0700501 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700502 * Note that these must match the constants in android.os.PowerManager.
503 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
504 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700505 */
506 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700507 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700508 };
509
Phil Weaverda80d672016-03-15 16:25:46 -0700510 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700511
Dianne Hackborn617f8772009-03-31 15:04:46 -0700512 public abstract void noteUserActivityLocked(int type);
513 public abstract boolean hasUserActivity();
514 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700515
516 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800517 public abstract long getNetworkActivityBytes(int type, int which);
518 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800519 public abstract long getMobileRadioActiveTime(int which);
520 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700521
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700522 /**
523 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
524 */
525 public abstract long getUserCpuTimeUs(int which);
526
527 /**
528 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
529 */
530 public abstract long getSystemCpuTimeUs(int which);
531
532 /**
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700533 * Get the total cpu power consumed (in milli-ampere-microseconds).
534 */
535 public abstract long getCpuPowerMaUs(int which);
536
537 /**
Adam Lesinski6832f392015-09-05 18:05:40 -0700538 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a
539 * given CPU cluster.
540 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700541 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700542 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700543 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
544 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700545 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700546 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800549 /*
550 * FIXME: it's not correct to use this magic value because it
551 * could clash with a sensor handle (which are defined by
552 * the sensor HAL, and therefore out of our control
553 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 // Magic sensor number for the GPS.
555 public static final int GPS = -10000;
556
557 public abstract int getHandle();
558
559 public abstract Timer getSensorTime();
560 }
561
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700562 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800563 public int mWakeNesting;
564 public long mWakeSumMs;
565 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700566 }
567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 /**
569 * The statistics associated with a particular process.
570 */
571 public static abstract class Proc {
572
Dianne Hackborn287952c2010-09-22 22:34:31 -0700573 public static class ExcessivePower {
574 public static final int TYPE_WAKE = 1;
575 public static final int TYPE_CPU = 2;
576
577 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700578 public long overTime;
579 public long usedTime;
580 }
581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800583 * Returns true if this process is still active in the battery stats.
584 */
585 public abstract boolean isActive();
586
587 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700588 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700590 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 */
592 public abstract long getUserTime(int which);
593
594 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700595 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700597 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 */
599 public abstract long getSystemTime(int which);
600
601 /**
602 * Returns the number of times the process has been started.
603 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700604 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 */
606 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700607
608 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800609 * Returns the number of times the process has crashed.
610 *
611 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
612 */
613 public abstract int getNumCrashes(int which);
614
615 /**
616 * Returns the number of times the process has ANRed.
617 *
618 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
619 */
620 public abstract int getNumAnrs(int which);
621
622 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700623 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700624 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700625 * @return foreground cpu time in microseconds
626 */
627 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700628
Dianne Hackborn287952c2010-09-22 22:34:31 -0700629 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700630
Dianne Hackborn287952c2010-09-22 22:34:31 -0700631 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 }
633
634 /**
635 * The statistics associated with a particular package.
636 */
637 public static abstract class Pkg {
638
639 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700640 * Returns information about all wakeup alarms that have been triggered for this
641 * package. The mapping keys are tag names for the alarms, the counter contains
642 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700644 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645
646 /**
647 * Returns a mapping containing service statistics.
648 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700649 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650
651 /**
652 * The statistics associated with a particular service.
653 */
Joe Onoratoabded112016-02-08 16:49:39 -0800654 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655
656 /**
657 * Returns the amount of time spent started.
658 *
659 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700660 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 * @return
662 */
663 public abstract long getStartTime(long batteryUptime, int which);
664
665 /**
666 * Returns the total number of times startService() has been called.
667 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700668 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 */
670 public abstract int getStarts(int which);
671
672 /**
673 * Returns the total number times the service has been launched.
674 *
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 */
677 public abstract int getLaunches(int which);
678 }
679 }
680 }
681
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800682 public static final class LevelStepTracker {
683 public long mLastStepTime = -1;
684 public int mNumStepDurations;
685 public final long[] mStepDurations;
686
687 public LevelStepTracker(int maxLevelSteps) {
688 mStepDurations = new long[maxLevelSteps];
689 }
690
691 public LevelStepTracker(int numSteps, long[] steps) {
692 mNumStepDurations = numSteps;
693 mStepDurations = new long[numSteps];
694 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
695 }
696
697 public long getDurationAt(int index) {
698 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
699 }
700
701 public int getLevelAt(int index) {
702 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
703 >> STEP_LEVEL_LEVEL_SHIFT);
704 }
705
706 public int getInitModeAt(int index) {
707 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
708 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
709 }
710
711 public int getModModeAt(int index) {
712 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
713 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
714 }
715
716 private void appendHex(long val, int topOffset, StringBuilder out) {
717 boolean hasData = false;
718 while (topOffset >= 0) {
719 int digit = (int)( (val>>topOffset) & 0xf );
720 topOffset -= 4;
721 if (!hasData && digit == 0) {
722 continue;
723 }
724 hasData = true;
725 if (digit >= 0 && digit <= 9) {
726 out.append((char)('0' + digit));
727 } else {
728 out.append((char)('a' + digit - 10));
729 }
730 }
731 }
732
733 public void encodeEntryAt(int index, StringBuilder out) {
734 long item = mStepDurations[index];
735 long duration = item & STEP_LEVEL_TIME_MASK;
736 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
737 >> STEP_LEVEL_LEVEL_SHIFT);
738 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
739 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
740 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
741 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
742 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
743 case Display.STATE_OFF: out.append('f'); break;
744 case Display.STATE_ON: out.append('o'); break;
745 case Display.STATE_DOZE: out.append('d'); break;
746 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
747 }
748 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
749 out.append('p');
750 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700751 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
752 out.append('i');
753 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800754 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
755 case Display.STATE_OFF: out.append('F'); break;
756 case Display.STATE_ON: out.append('O'); break;
757 case Display.STATE_DOZE: out.append('D'); break;
758 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
759 }
760 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
761 out.append('P');
762 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700763 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
764 out.append('I');
765 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800766 out.append('-');
767 appendHex(level, 4, out);
768 out.append('-');
769 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
770 }
771
772 public void decodeEntryAt(int index, String value) {
773 final int N = value.length();
774 int i = 0;
775 char c;
776 long out = 0;
777 while (i < N && (c=value.charAt(i)) != '-') {
778 i++;
779 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800780 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800781 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800782 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800783 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800784 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800785 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800786 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
787 << STEP_LEVEL_INITIAL_MODE_SHIFT);
788 break;
789 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
790 << STEP_LEVEL_INITIAL_MODE_SHIFT);
791 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700792 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
793 << STEP_LEVEL_INITIAL_MODE_SHIFT);
794 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800795 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
796 break;
797 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
798 break;
799 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
800 break;
801 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
802 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
803 break;
804 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
805 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800806 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700807 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
808 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
809 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800810 }
811 }
812 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800813 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800814 while (i < N && (c=value.charAt(i)) != '-') {
815 i++;
816 level <<= 4;
817 if (c >= '0' && c <= '9') {
818 level += c - '0';
819 } else if (c >= 'a' && c <= 'f') {
820 level += c - 'a' + 10;
821 } else if (c >= 'A' && c <= 'F') {
822 level += c - 'A' + 10;
823 }
824 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800825 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800826 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
827 long duration = 0;
828 while (i < N && (c=value.charAt(i)) != '-') {
829 i++;
830 duration <<= 4;
831 if (c >= '0' && c <= '9') {
832 duration += c - '0';
833 } else if (c >= 'a' && c <= 'f') {
834 duration += c - 'a' + 10;
835 } else if (c >= 'A' && c <= 'F') {
836 duration += c - 'A' + 10;
837 }
838 }
839 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
840 }
841
842 public void init() {
843 mLastStepTime = -1;
844 mNumStepDurations = 0;
845 }
846
847 public void clearTime() {
848 mLastStepTime = -1;
849 }
850
851 public long computeTimePerLevel() {
852 final long[] steps = mStepDurations;
853 final int numSteps = mNumStepDurations;
854
855 // For now we'll do a simple average across all steps.
856 if (numSteps <= 0) {
857 return -1;
858 }
859 long total = 0;
860 for (int i=0; i<numSteps; i++) {
861 total += steps[i] & STEP_LEVEL_TIME_MASK;
862 }
863 return total / numSteps;
864 /*
865 long[] buckets = new long[numSteps];
866 int numBuckets = 0;
867 int numToAverage = 4;
868 int i = 0;
869 while (i < numSteps) {
870 long totalTime = 0;
871 int num = 0;
872 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
873 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
874 num++;
875 }
876 buckets[numBuckets] = totalTime / num;
877 numBuckets++;
878 numToAverage *= 2;
879 i += num;
880 }
881 if (numBuckets < 1) {
882 return -1;
883 }
884 long averageTime = buckets[numBuckets-1];
885 for (i=numBuckets-2; i>=0; i--) {
886 averageTime = (averageTime + buckets[i]) / 2;
887 }
888 return averageTime;
889 */
890 }
891
892 public long computeTimeEstimate(long modesOfInterest, long modeValues,
893 int[] outNumOfInterest) {
894 final long[] steps = mStepDurations;
895 final int count = mNumStepDurations;
896 if (count <= 0) {
897 return -1;
898 }
899 long total = 0;
900 int numOfInterest = 0;
901 for (int i=0; i<count; i++) {
902 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
903 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
904 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
905 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
906 // If the modes of interest didn't change during this step period...
907 if ((modMode&modesOfInterest) == 0) {
908 // And the mode values during this period match those we are measuring...
909 if ((initMode&modesOfInterest) == modeValues) {
910 // Then this can be used to estimate the total time!
911 numOfInterest++;
912 total += steps[i] & STEP_LEVEL_TIME_MASK;
913 }
914 }
915 }
916 if (numOfInterest <= 0) {
917 return -1;
918 }
919
920 if (outNumOfInterest != null) {
921 outNumOfInterest[0] = numOfInterest;
922 }
923
924 // The estimated time is the average time we spend in each level, multipled
925 // by 100 -- the total number of battery levels
926 return (total / numOfInterest) * 100;
927 }
928
929 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
930 int stepCount = mNumStepDurations;
931 final long lastStepTime = mLastStepTime;
932 if (lastStepTime >= 0 && numStepLevels > 0) {
933 final long[] steps = mStepDurations;
934 long duration = elapsedRealtime - lastStepTime;
935 for (int i=0; i<numStepLevels; i++) {
936 System.arraycopy(steps, 0, steps, 1, steps.length-1);
937 long thisDuration = duration / (numStepLevels-i);
938 duration -= thisDuration;
939 if (thisDuration > STEP_LEVEL_TIME_MASK) {
940 thisDuration = STEP_LEVEL_TIME_MASK;
941 }
942 steps[0] = thisDuration | modeBits;
943 }
944 stepCount += numStepLevels;
945 if (stepCount > steps.length) {
946 stepCount = steps.length;
947 }
948 }
949 mNumStepDurations = stepCount;
950 mLastStepTime = elapsedRealtime;
951 }
952
953 public void readFromParcel(Parcel in) {
954 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -0700955 if (N > mStepDurations.length) {
956 throw new ParcelFormatException("more step durations than available: " + N);
957 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800958 mNumStepDurations = N;
959 for (int i=0; i<N; i++) {
960 mStepDurations[i] = in.readLong();
961 }
962 }
963
964 public void writeToParcel(Parcel out) {
965 final int N = mNumStepDurations;
966 out.writeInt(N);
967 for (int i=0; i<N; i++) {
968 out.writeLong(mStepDurations[i]);
969 }
970 }
971 }
972
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700973 public static final class PackageChange {
974 public String mPackageName;
975 public boolean mUpdate;
976 public int mVersionCode;
977 }
978
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800979 public static final class DailyItem {
980 public long mStartTime;
981 public long mEndTime;
982 public LevelStepTracker mDischargeSteps;
983 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700984 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800985 }
986
987 public abstract DailyItem getDailyItemLocked(int daysAgo);
988
989 public abstract long getCurrentDailyStartTime();
990
991 public abstract long getNextMinDailyDeadline();
992
993 public abstract long getNextMaxDailyDeadline();
994
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800995 public final static class HistoryTag {
996 public String string;
997 public int uid;
998
999 public int poolIdx;
1000
1001 public void setTo(HistoryTag o) {
1002 string = o.string;
1003 uid = o.uid;
1004 poolIdx = o.poolIdx;
1005 }
1006
1007 public void setTo(String _string, int _uid) {
1008 string = _string;
1009 uid = _uid;
1010 poolIdx = -1;
1011 }
1012
1013 public void writeToParcel(Parcel dest, int flags) {
1014 dest.writeString(string);
1015 dest.writeInt(uid);
1016 }
1017
1018 public void readFromParcel(Parcel src) {
1019 string = src.readString();
1020 uid = src.readInt();
1021 poolIdx = -1;
1022 }
1023
1024 @Override
1025 public boolean equals(Object o) {
1026 if (this == o) return true;
1027 if (o == null || getClass() != o.getClass()) return false;
1028
1029 HistoryTag that = (HistoryTag) o;
1030
1031 if (uid != that.uid) return false;
1032 if (!string.equals(that.string)) return false;
1033
1034 return true;
1035 }
1036
1037 @Override
1038 public int hashCode() {
1039 int result = string.hashCode();
1040 result = 31 * result + uid;
1041 return result;
1042 }
1043 }
1044
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001045 /**
1046 * Optional detailed information that can go into a history step. This is typically
1047 * generated each time the battery level changes.
1048 */
1049 public final static class HistoryStepDetails {
1050 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1051 public int userTime;
1052 public int systemTime;
1053
1054 // Top three apps using CPU in the last step, with times in 1/100 second.
1055 public int appCpuUid1;
1056 public int appCpuUTime1;
1057 public int appCpuSTime1;
1058 public int appCpuUid2;
1059 public int appCpuUTime2;
1060 public int appCpuSTime2;
1061 public int appCpuUid3;
1062 public int appCpuUTime3;
1063 public int appCpuSTime3;
1064
1065 // Information from /proc/stat
1066 public int statUserTime;
1067 public int statSystemTime;
1068 public int statIOWaitTime;
1069 public int statIrqTime;
1070 public int statSoftIrqTime;
1071 public int statIdlTime;
1072
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001073 // Platform-level low power state stats
1074 public String statPlatformIdleState;
1075
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001076 public HistoryStepDetails() {
1077 clear();
1078 }
1079
1080 public void clear() {
1081 userTime = systemTime = 0;
1082 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1083 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1084 = appCpuUTime3 = appCpuSTime3 = 0;
1085 }
1086
1087 public void writeToParcel(Parcel out) {
1088 out.writeInt(userTime);
1089 out.writeInt(systemTime);
1090 out.writeInt(appCpuUid1);
1091 out.writeInt(appCpuUTime1);
1092 out.writeInt(appCpuSTime1);
1093 out.writeInt(appCpuUid2);
1094 out.writeInt(appCpuUTime2);
1095 out.writeInt(appCpuSTime2);
1096 out.writeInt(appCpuUid3);
1097 out.writeInt(appCpuUTime3);
1098 out.writeInt(appCpuSTime3);
1099 out.writeInt(statUserTime);
1100 out.writeInt(statSystemTime);
1101 out.writeInt(statIOWaitTime);
1102 out.writeInt(statIrqTime);
1103 out.writeInt(statSoftIrqTime);
1104 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001105 out.writeString(statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001106 }
1107
1108 public void readFromParcel(Parcel in) {
1109 userTime = in.readInt();
1110 systemTime = in.readInt();
1111 appCpuUid1 = in.readInt();
1112 appCpuUTime1 = in.readInt();
1113 appCpuSTime1 = in.readInt();
1114 appCpuUid2 = in.readInt();
1115 appCpuUTime2 = in.readInt();
1116 appCpuSTime2 = in.readInt();
1117 appCpuUid3 = in.readInt();
1118 appCpuUTime3 = in.readInt();
1119 appCpuSTime3 = in.readInt();
1120 statUserTime = in.readInt();
1121 statSystemTime = in.readInt();
1122 statIOWaitTime = in.readInt();
1123 statIrqTime = in.readInt();
1124 statSoftIrqTime = in.readInt();
1125 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001126 statPlatformIdleState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001127 }
1128 }
1129
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001130 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001131 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001132
1133 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001134 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001135
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001136 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001137 public static final byte CMD_NULL = -1;
1138 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001139 public static final byte CMD_CURRENT_TIME = 5;
1140 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001141 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001142 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001143
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001144 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001145
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001146 /**
1147 * Return whether the command code is a delta data update.
1148 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001149 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001150 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001151 }
1152
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001153 public byte batteryLevel;
1154 public byte batteryStatus;
1155 public byte batteryHealth;
1156 public byte batteryPlugType;
1157
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001158 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001159 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001160
1161 public int batteryChargeCoulombs;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001162
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001163 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001164 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001165 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001166 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001167 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1168 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001169 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001170 public static final int STATE_PHONE_STATE_SHIFT = 6;
1171 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001172 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001173 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001174 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001175
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001176 // These states always appear directly in the first int token
1177 // of a delta change; they should be ones that change relatively
1178 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001179 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1180 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001181 public static final int STATE_GPS_ON_FLAG = 1<<29;
1182 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001183 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001184 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001185 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001186 // Do not use, this is used for coulomb delta count.
1187 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001188 // These are on the lower bits used for the command; if they change
1189 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001190 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001191 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001192 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001193 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1194 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1195 // empty slot
1196 // empty slot
1197 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001198
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001199 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001200 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1201
1202 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001203
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001204 public int states;
1205
Dianne Hackborn3251b902014-06-20 14:40:53 -07001206 // Constants from WIFI_SUPPL_STATE_*
1207 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1208 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1209 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1210 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1211 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1212 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1213
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001214 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001215 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1216 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1217 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001218 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001219 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1220 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1221 public static final int STATE2_CHARGING_FLAG = 1<<24;
1222 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1223 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1224 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001225 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001226
1227 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001228 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001229 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1230
1231 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001232
Dianne Hackborn40c87252014-03-19 16:55:40 -07001233 public int states2;
1234
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001235 // The wake lock that was acquired at this point.
1236 public HistoryTag wakelockTag;
1237
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001238 // Kernel wakeup reason at this point.
1239 public HistoryTag wakeReasonTag;
1240
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001241 // Non-null when there is more detailed information at this step.
1242 public HistoryStepDetails stepDetails;
1243
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001244 public static final int EVENT_FLAG_START = 0x8000;
1245 public static final int EVENT_FLAG_FINISH = 0x4000;
1246
1247 // No event in this item.
1248 public static final int EVENT_NONE = 0x0000;
1249 // Event is about a process that is running.
1250 public static final int EVENT_PROC = 0x0001;
1251 // Event is about an application package that is in the foreground.
1252 public static final int EVENT_FOREGROUND = 0x0002;
1253 // Event is about an application package that is at the top of the screen.
1254 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001255 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001256 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001257 // Events for all additional wake locks aquired/release within a wake block.
1258 // These are not generated by default.
1259 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001260 // Event is about an application executing a scheduled job.
1261 public static final int EVENT_JOB = 0x0006;
1262 // Events for users running.
1263 public static final int EVENT_USER_RUNNING = 0x0007;
1264 // Events for foreground user.
1265 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001266 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001267 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001268 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001269 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001270 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001271 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001272 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001273 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001274 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001275 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001276 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001277 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001278 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001279 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001280 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001281 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001282 // Event for a package being on the temporary whitelist.
1283 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001284 // Event for the screen waking up.
1285 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Amith Yamasani67768492015-06-09 12:23:58 -07001286
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001287 // Number of event types.
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001288 public static final int EVENT_COUNT = 0x0013;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001289 // Mask to extract out only the type part of the event.
1290 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001291
1292 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1293 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1294 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1295 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1296 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1297 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001298 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1299 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001300 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1301 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001302 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1303 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1304 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1305 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1306 public static final int EVENT_USER_FOREGROUND_START =
1307 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1308 public static final int EVENT_USER_FOREGROUND_FINISH =
1309 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001310 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1311 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001312 public static final int EVENT_TEMP_WHITELIST_START =
1313 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1314 public static final int EVENT_TEMP_WHITELIST_FINISH =
1315 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001316
1317 // For CMD_EVENT.
1318 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001319 public HistoryTag eventTag;
1320
Dianne Hackborn9a755432014-05-15 17:05:22 -07001321 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001322 public long currentTime;
1323
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001324 // Meta-data when reading.
1325 public int numReadInts;
1326
1327 // Pre-allocated objects.
1328 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001329 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001330 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001331
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001332 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001333 }
1334
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001335 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001336 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001337 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001338 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001339 }
1340
1341 public int describeContents() {
1342 return 0;
1343 }
1344
1345 public void writeToParcel(Parcel dest, int flags) {
1346 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001347 int bat = (((int)cmd)&0xff)
1348 | ((((int)batteryLevel)<<8)&0xff00)
1349 | ((((int)batteryStatus)<<16)&0xf0000)
1350 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001351 | ((((int)batteryPlugType)<<24)&0xf000000)
1352 | (wakelockTag != null ? 0x10000000 : 0)
1353 | (wakeReasonTag != null ? 0x20000000 : 0)
1354 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001355 dest.writeInt(bat);
1356 bat = (((int)batteryTemperature)&0xffff)
1357 | ((((int)batteryVoltage)<<16)&0xffff0000);
1358 dest.writeInt(bat);
Adam Lesinski926969b2016-04-28 17:31:12 -07001359 dest.writeInt(batteryChargeCoulombs);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001360 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001361 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001362 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001363 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001364 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001365 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001366 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001367 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001368 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001369 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001370 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001371 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001372 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001373 dest.writeLong(currentTime);
1374 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001375 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001376
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001377 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001378 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001379 int bat = src.readInt();
1380 cmd = (byte)(bat&0xff);
1381 batteryLevel = (byte)((bat>>8)&0xff);
1382 batteryStatus = (byte)((bat>>16)&0xf);
1383 batteryHealth = (byte)((bat>>20)&0xf);
1384 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001385 int bat2 = src.readInt();
1386 batteryTemperature = (short)(bat2&0xffff);
1387 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinski926969b2016-04-28 17:31:12 -07001388 batteryChargeCoulombs = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001389 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001390 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001391 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001392 wakelockTag = localWakelockTag;
1393 wakelockTag.readFromParcel(src);
1394 } else {
1395 wakelockTag = null;
1396 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001397 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001398 wakeReasonTag = localWakeReasonTag;
1399 wakeReasonTag.readFromParcel(src);
1400 } else {
1401 wakeReasonTag = null;
1402 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001403 if ((bat&0x40000000) != 0) {
1404 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001405 eventTag = localEventTag;
1406 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001407 } else {
1408 eventCode = EVENT_NONE;
1409 eventTag = null;
1410 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001411 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001412 currentTime = src.readLong();
1413 } else {
1414 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001415 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001416 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001417 }
1418
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001419 public void clear() {
1420 time = 0;
1421 cmd = CMD_NULL;
1422 batteryLevel = 0;
1423 batteryStatus = 0;
1424 batteryHealth = 0;
1425 batteryPlugType = 0;
1426 batteryTemperature = 0;
1427 batteryVoltage = 0;
Adam Lesinski926969b2016-04-28 17:31:12 -07001428 batteryChargeCoulombs = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001429 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001430 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001431 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001432 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001433 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001434 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001435 }
1436
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001437 public void setTo(HistoryItem o) {
1438 time = o.time;
1439 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001440 setToCommon(o);
1441 }
1442
1443 public void setTo(long time, byte cmd, HistoryItem o) {
1444 this.time = time;
1445 this.cmd = cmd;
1446 setToCommon(o);
1447 }
1448
1449 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001450 batteryLevel = o.batteryLevel;
1451 batteryStatus = o.batteryStatus;
1452 batteryHealth = o.batteryHealth;
1453 batteryPlugType = o.batteryPlugType;
1454 batteryTemperature = o.batteryTemperature;
1455 batteryVoltage = o.batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001456 batteryChargeCoulombs = o.batteryChargeCoulombs;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001457 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001458 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001459 if (o.wakelockTag != null) {
1460 wakelockTag = localWakelockTag;
1461 wakelockTag.setTo(o.wakelockTag);
1462 } else {
1463 wakelockTag = null;
1464 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001465 if (o.wakeReasonTag != null) {
1466 wakeReasonTag = localWakeReasonTag;
1467 wakeReasonTag.setTo(o.wakeReasonTag);
1468 } else {
1469 wakeReasonTag = null;
1470 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001471 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001472 if (o.eventTag != null) {
1473 eventTag = localEventTag;
1474 eventTag.setTo(o.eventTag);
1475 } else {
1476 eventTag = null;
1477 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001478 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001479 }
1480
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001481 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001482 return batteryLevel == o.batteryLevel
1483 && batteryStatus == o.batteryStatus
1484 && batteryHealth == o.batteryHealth
1485 && batteryPlugType == o.batteryPlugType
1486 && batteryTemperature == o.batteryTemperature
1487 && batteryVoltage == o.batteryVoltage
Adam Lesinski926969b2016-04-28 17:31:12 -07001488 && batteryChargeCoulombs == o.batteryChargeCoulombs
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001489 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001490 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001491 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001492 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001493
1494 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001495 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001496 return false;
1497 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001498 if (wakelockTag != o.wakelockTag) {
1499 if (wakelockTag == null || o.wakelockTag == null) {
1500 return false;
1501 }
1502 if (!wakelockTag.equals(o.wakelockTag)) {
1503 return false;
1504 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001505 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001506 if (wakeReasonTag != o.wakeReasonTag) {
1507 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1508 return false;
1509 }
1510 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1511 return false;
1512 }
1513 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001514 if (eventTag != o.eventTag) {
1515 if (eventTag == null || o.eventTag == null) {
1516 return false;
1517 }
1518 if (!eventTag.equals(o.eventTag)) {
1519 return false;
1520 }
1521 }
1522 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001523 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001524 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001525
1526 public final static class HistoryEventTracker {
1527 private final HashMap<String, SparseIntArray>[] mActiveEvents
1528 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1529
1530 public boolean updateState(int code, String name, int uid, int poolIdx) {
1531 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1532 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1533 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1534 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001535 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001536 mActiveEvents[idx] = active;
1537 }
1538 SparseIntArray uids = active.get(name);
1539 if (uids == null) {
1540 uids = new SparseIntArray();
1541 active.put(name, uids);
1542 }
1543 if (uids.indexOfKey(uid) >= 0) {
1544 // Already set, nothing to do!
1545 return false;
1546 }
1547 uids.put(uid, poolIdx);
1548 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1549 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1550 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1551 if (active == null) {
1552 // not currently active, nothing to do.
1553 return false;
1554 }
1555 SparseIntArray uids = active.get(name);
1556 if (uids == null) {
1557 // not currently active, nothing to do.
1558 return false;
1559 }
1560 idx = uids.indexOfKey(uid);
1561 if (idx < 0) {
1562 // not currently active, nothing to do.
1563 return false;
1564 }
1565 uids.removeAt(idx);
1566 if (uids.size() <= 0) {
1567 active.remove(name);
1568 }
1569 }
1570 return true;
1571 }
1572
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001573 public void removeEvents(int code) {
1574 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1575 mActiveEvents[idx] = null;
1576 }
1577
Dianne Hackborn37de0982014-05-09 09:32:18 -07001578 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1579 return mActiveEvents[code];
1580 }
1581 }
1582
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001583 public static final class BitDescription {
1584 public final int mask;
1585 public final int shift;
1586 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001587 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001588 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001589 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001590
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001591 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001592 this.mask = mask;
1593 this.shift = -1;
1594 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001595 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001596 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001597 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001598 }
1599
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001600 public BitDescription(int mask, int shift, String name, String shortName,
1601 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001602 this.mask = mask;
1603 this.shift = shift;
1604 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001605 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001606 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001607 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001608 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001609 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001610
Dianne Hackbornfc064132014-06-02 12:42:12 -07001611 /**
1612 * Don't allow any more batching in to the current history event. This
1613 * is called when printing partial histories, so to ensure that the next
1614 * history event will go in to a new batch after what was printed in the
1615 * last partial history.
1616 */
1617 public abstract void commitCurrentHistoryBatchLocked();
1618
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001619 public abstract int getHistoryTotalSize();
1620
1621 public abstract int getHistoryUsedSize();
1622
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001623 public abstract boolean startIteratingHistoryLocked();
1624
Dianne Hackborn099bc622014-01-22 13:39:16 -08001625 public abstract int getHistoryStringPoolSize();
1626
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001627 public abstract int getHistoryStringPoolBytes();
1628
1629 public abstract String getHistoryTagPoolString(int index);
1630
1631 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001632
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001633 public abstract boolean getNextHistoryLocked(HistoryItem out);
1634
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001635 public abstract void finishIteratingHistoryLocked();
1636
1637 public abstract boolean startIteratingOldHistoryLocked();
1638
1639 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1640
1641 public abstract void finishIteratingOldHistoryLocked();
1642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001644 * Return the base time offset for the battery history.
1645 */
1646 public abstract long getHistoryBaseTime();
1647
1648 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001649 * Returns the number of times the device has been started.
1650 */
1651 public abstract int getStartCount();
1652
1653 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001654 * 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 -08001655 * running on battery.
1656 *
1657 * {@hide}
1658 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001659 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001661 /**
1662 * Returns the number of times the screen was turned on.
1663 *
1664 * {@hide}
1665 */
1666 public abstract int getScreenOnCount(int which);
1667
Jeff Browne95c3cd2014-05-02 16:59:26 -07001668 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1669
Dianne Hackborn617f8772009-03-31 15:04:46 -07001670 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1671 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1672 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1673 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1674 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1675
1676 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1677 "dark", "dim", "medium", "light", "bright"
1678 };
1679
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001680 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1681 "0", "1", "2", "3", "4"
1682 };
1683
Dianne Hackborn617f8772009-03-31 15:04:46 -07001684 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001685
Dianne Hackborn617f8772009-03-31 15:04:46 -07001686 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001687 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001688 * the given brightness
1689 *
1690 * {@hide}
1691 */
1692 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001693 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001696 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001697 * running on battery.
1698 *
1699 * {@hide}
1700 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001701 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001702
1703 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001704 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001705 *
1706 * {@hide}
1707 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001708 public abstract int getPowerSaveModeEnabledCount(int which);
1709
1710 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001711 * Constant for device idle mode: not active.
1712 */
1713 public static final int DEVICE_IDLE_MODE_OFF = 0;
1714
1715 /**
1716 * Constant for device idle mode: active in lightweight mode.
1717 */
1718 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1719
1720 /**
1721 * Constant for device idle mode: active in full mode.
1722 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001723 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001724
1725 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001726 * Returns the time in microseconds that device has been in idle mode while
1727 * running on battery.
1728 *
1729 * {@hide}
1730 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001731 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001732
1733 /**
1734 * Returns the number of times that the devie has gone in to idle mode.
1735 *
1736 * {@hide}
1737 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001738 public abstract int getDeviceIdleModeCount(int mode, int which);
1739
1740 /**
1741 * Return the longest duration we spent in a particular device idle mode (fully in the
1742 * mode, not in idle maintenance etc).
1743 */
1744 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001745
1746 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001747 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001748 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001749 * counts all of the time that we consider the device to be idle, whether or not
1750 * it is currently in the actual device idle mode.
1751 *
1752 * {@hide}
1753 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001754 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001755
1756 /**
1757 * Returns the number of times that the devie has started idling.
1758 *
1759 * {@hide}
1760 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001761 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001762
1763 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001764 * Returns the number of times that connectivity state changed.
1765 *
1766 * {@hide}
1767 */
1768 public abstract int getNumConnectivityChange(int which);
1769
1770 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001771 * 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 -08001772 * running on battery.
1773 *
1774 * {@hide}
1775 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001776 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001777
1778 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001779 * Returns the number of times a phone call was activated.
1780 *
1781 * {@hide}
1782 */
1783 public abstract int getPhoneOnCount(int which);
1784
1785 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001786 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001787 * the given signal strength.
1788 *
1789 * {@hide}
1790 */
1791 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001792 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001793
Dianne Hackborn617f8772009-03-31 15:04:46 -07001794 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001795 * Returns the time in microseconds that the phone has been trying to
1796 * acquire a signal.
1797 *
1798 * {@hide}
1799 */
1800 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001801 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001802
1803 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001804 * Returns the number of times the phone has entered the given signal strength.
1805 *
1806 * {@hide}
1807 */
1808 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1809
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001810 /**
1811 * Returns the time in microseconds that the mobile network has been active
1812 * (in a high power state).
1813 *
1814 * {@hide}
1815 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001816 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001817
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001818 /**
1819 * Returns the number of times that the mobile network has transitioned to the
1820 * active state.
1821 *
1822 * {@hide}
1823 */
1824 public abstract int getMobileRadioActiveCount(int which);
1825
1826 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001827 * Returns the time in microseconds that is the difference between the mobile radio
1828 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1829 * from the radio.
1830 *
1831 * {@hide}
1832 */
1833 public abstract long getMobileRadioActiveAdjustedTime(int which);
1834
1835 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001836 * Returns the time in microseconds that the mobile network has been active
1837 * (in a high power state) but not being able to blame on an app.
1838 *
1839 * {@hide}
1840 */
1841 public abstract long getMobileRadioActiveUnknownTime(int which);
1842
1843 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001844 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001845 *
1846 * {@hide}
1847 */
1848 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001849
Dianne Hackborn627bba72009-03-24 22:32:56 -07001850 public static final int DATA_CONNECTION_NONE = 0;
1851 public static final int DATA_CONNECTION_GPRS = 1;
1852 public static final int DATA_CONNECTION_EDGE = 2;
1853 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001854 public static final int DATA_CONNECTION_CDMA = 4;
1855 public static final int DATA_CONNECTION_EVDO_0 = 5;
1856 public static final int DATA_CONNECTION_EVDO_A = 6;
1857 public static final int DATA_CONNECTION_1xRTT = 7;
1858 public static final int DATA_CONNECTION_HSDPA = 8;
1859 public static final int DATA_CONNECTION_HSUPA = 9;
1860 public static final int DATA_CONNECTION_HSPA = 10;
1861 public static final int DATA_CONNECTION_IDEN = 11;
1862 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001863 public static final int DATA_CONNECTION_LTE = 13;
1864 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001865 public static final int DATA_CONNECTION_HSPAP = 15;
1866 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001867
Dianne Hackborn627bba72009-03-24 22:32:56 -07001868 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001869 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001870 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001871 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001872 };
1873
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001874 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001875
1876 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001877 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001878 * the given data connection.
1879 *
1880 * {@hide}
1881 */
1882 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001883 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001886 * Returns the number of times the phone has entered the given data
1887 * connection type.
1888 *
1889 * {@hide}
1890 */
1891 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001892
Dianne Hackborn3251b902014-06-20 14:40:53 -07001893 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1894 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1895 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1896 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1897 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1898 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1899 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1900 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1901 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1902 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1903 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1904 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1905 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1906
1907 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1908
1909 static final String[] WIFI_SUPPL_STATE_NAMES = {
1910 "invalid", "disconn", "disabled", "inactive", "scanning",
1911 "authenticating", "associating", "associated", "4-way-handshake",
1912 "group-handshake", "completed", "dormant", "uninit"
1913 };
1914
1915 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1916 "inv", "dsc", "dis", "inact", "scan",
1917 "auth", "ascing", "asced", "4-way",
1918 "group", "compl", "dorm", "uninit"
1919 };
1920
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001921 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1922 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001923 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001924 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1925 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001926 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001927 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1928 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1929 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001930 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001931 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001932 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001933 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001934 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1935 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001936 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1937 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1938 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1939 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1940 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1941 new String[] {"in", "out", "emergency", "off"},
1942 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001943 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1944 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1945 SignalStrength.SIGNAL_STRENGTH_NAMES,
1946 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001947 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1948 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1949 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001950 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001951
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001952 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1953 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001954 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001955 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001956 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001957 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001958 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001959 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
1960 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
1961 new String[] { "off", "light", "full", "???" },
1962 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001963 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
1964 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
1965 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001966 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1967 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1968 new String[] { "0", "1", "2", "3", "4" },
1969 new String[] { "0", "1", "2", "3", "4" }),
1970 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1971 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1972 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07001973 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001974 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001975 };
1976
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001977 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001978 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001979 "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist",
1980 "screenwake",
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001981 };
1982
1983 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001984 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001985 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
1986 "Esw",
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001987 };
1988
Dianne Hackborn617f8772009-03-31 15:04:46 -07001989 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001990 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001991 * running on battery.
1992 *
1993 * {@hide}
1994 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001995 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001996
1997 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001998 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001999 * been in the running state while the device was running on battery.
2000 *
2001 * {@hide}
2002 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002003 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002004
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002005 public static final int WIFI_STATE_OFF = 0;
2006 public static final int WIFI_STATE_OFF_SCANNING = 1;
2007 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2008 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2009 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2010 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2011 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2012 public static final int WIFI_STATE_SOFT_AP = 7;
2013
2014 static final String[] WIFI_STATE_NAMES = {
2015 "off", "scanning", "no_net", "disconn",
2016 "sta", "p2p", "sta_p2p", "soft_ap"
2017 };
2018
2019 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2020
2021 /**
2022 * Returns the time in microseconds that WiFi has been running in the given state.
2023 *
2024 * {@hide}
2025 */
2026 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002027 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002028
2029 /**
2030 * Returns the number of times that WiFi has entered the given state.
2031 *
2032 * {@hide}
2033 */
2034 public abstract int getWifiStateCount(int wifiState, int which);
2035
The Android Open Source Project10592532009-03-18 17:39:46 -07002036 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002037 * Returns the time in microseconds that the wifi supplicant has been
2038 * in a given state.
2039 *
2040 * {@hide}
2041 */
2042 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2043
2044 /**
2045 * Returns the number of times that the wifi supplicant has transitioned
2046 * to a given state.
2047 *
2048 * {@hide}
2049 */
2050 public abstract int getWifiSupplStateCount(int state, int which);
2051
2052 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2053
2054 /**
2055 * Returns the time in microseconds that WIFI has been running with
2056 * the given signal strength.
2057 *
2058 * {@hide}
2059 */
2060 public abstract long getWifiSignalStrengthTime(int strengthBin,
2061 long elapsedRealtimeUs, int which);
2062
2063 /**
2064 * Returns the number of times WIFI has entered the given signal strength.
2065 *
2066 * {@hide}
2067 */
2068 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2069
2070 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002071 * Returns the time in microseconds that the flashlight has been on while the device was
2072 * running on battery.
2073 *
2074 * {@hide}
2075 */
2076 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2077
2078 /**
2079 * Returns the number of times that the flashlight has been turned on while the device was
2080 * running on battery.
2081 *
2082 * {@hide}
2083 */
2084 public abstract long getFlashlightOnCount(int which);
2085
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002086 /**
2087 * Returns the time in microseconds that the camera has been on while the device was
2088 * running on battery.
2089 *
2090 * {@hide}
2091 */
2092 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2093
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002094 /**
2095 * Returns the time in microseconds that bluetooth scans were running while the device was
2096 * on battery.
2097 *
2098 * {@hide}
2099 */
2100 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002101
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002102 public static final int NETWORK_MOBILE_RX_DATA = 0;
2103 public static final int NETWORK_MOBILE_TX_DATA = 1;
2104 public static final int NETWORK_WIFI_RX_DATA = 2;
2105 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002106 public static final int NETWORK_BT_RX_DATA = 4;
2107 public static final int NETWORK_BT_TX_DATA = 5;
2108 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_BT_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002109
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002110 public abstract long getNetworkActivityBytes(int type, int which);
2111 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002112
Adam Lesinskie08af192015-03-25 16:42:59 -07002113 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002114 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002115 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002116 * actual power data.
2117 */
2118 public abstract boolean hasWifiActivityReporting();
2119
2120 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002121 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2122 * in various radio controller states, such as transmit, receive, and idle.
2123 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002124 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002125 public abstract ControllerActivityCounter getWifiControllerActivity();
2126
2127 /**
2128 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2129 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2130 * actual power data.
2131 */
2132 public abstract boolean hasBluetoothActivityReporting();
2133
2134 /**
2135 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2136 * in various radio controller states, such as transmit, receive, and idle.
2137 * @return non-null {@link ControllerActivityCounter}
2138 */
2139 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2140
2141 /**
2142 * Returns true if the BatteryStats object has detailed modem power reports.
2143 * When true, calling {@link #getModemControllerActivity()} will yield the
2144 * actual power data.
2145 */
2146 public abstract boolean hasModemActivityReporting();
2147
2148 /**
2149 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2150 * in various radio controller states, such as transmit, receive, and idle.
2151 * @return non-null {@link ControllerActivityCounter}
2152 */
2153 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002154
The Android Open Source Project10592532009-03-18 17:39:46 -07002155 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002156 * Return the wall clock time when battery stats data collection started.
2157 */
2158 public abstract long getStartClockTime();
2159
2160 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002161 * Return platform version tag that we were running in when the battery stats started.
2162 */
2163 public abstract String getStartPlatformVersion();
2164
2165 /**
2166 * Return platform version tag that we were running in when the battery stats ended.
2167 */
2168 public abstract String getEndPlatformVersion();
2169
2170 /**
2171 * Return the internal version code of the parcelled format.
2172 */
2173 public abstract int getParcelVersion();
2174
2175 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 * Return whether we are currently running on battery.
2177 */
2178 public abstract boolean getIsOnBattery();
2179
2180 /**
2181 * Returns a SparseArray containing the statistics for each uid.
2182 */
2183 public abstract SparseArray<? extends Uid> getUidStats();
2184
2185 /**
2186 * Returns the current battery uptime in microseconds.
2187 *
2188 * @param curTime the amount of elapsed realtime in microseconds.
2189 */
2190 public abstract long getBatteryUptime(long curTime);
2191
2192 /**
2193 * Returns the current battery realtime in microseconds.
2194 *
2195 * @param curTime the amount of elapsed realtime in microseconds.
2196 */
2197 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07002198
2199 /**
Evan Millar633a1742009-04-02 16:36:33 -07002200 * Returns the battery percentage level at the last time the device was unplugged from power, or
2201 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002202 */
Evan Millar633a1742009-04-02 16:36:33 -07002203 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07002204
2205 /**
Evan Millar633a1742009-04-02 16:36:33 -07002206 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2207 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002208 */
Evan Millar633a1742009-04-02 16:36:33 -07002209 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210
2211 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002212 * Get the amount the battery has discharged since the stats were
2213 * last reset after charging, as a lower-end approximation.
2214 */
2215 public abstract int getLowDischargeAmountSinceCharge();
2216
2217 /**
2218 * Get the amount the battery has discharged since the stats were
2219 * last reset after charging, as an upper-end approximation.
2220 */
2221 public abstract int getHighDischargeAmountSinceCharge();
2222
2223 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002224 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2225 */
2226 public abstract int getDischargeAmount(int which);
2227
2228 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002229 * Get the amount the battery has discharged while the screen was on,
2230 * since the last time power was unplugged.
2231 */
2232 public abstract int getDischargeAmountScreenOn();
2233
2234 /**
2235 * Get the amount the battery has discharged while the screen was on,
2236 * since the last time the device was charged.
2237 */
2238 public abstract int getDischargeAmountScreenOnSinceCharge();
2239
2240 /**
2241 * Get the amount the battery has discharged while the screen was off,
2242 * since the last time power was unplugged.
2243 */
2244 public abstract int getDischargeAmountScreenOff();
2245
2246 /**
2247 * Get the amount the battery has discharged while the screen was off,
2248 * since the last time the device was charged.
2249 */
2250 public abstract int getDischargeAmountScreenOffSinceCharge();
2251
2252 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 * Returns the total, last, or current battery uptime in microseconds.
2254 *
2255 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002256 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 */
2258 public abstract long computeBatteryUptime(long curTime, int which);
2259
2260 /**
2261 * Returns the total, last, or current battery realtime in microseconds.
2262 *
2263 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002264 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 */
2266 public abstract long computeBatteryRealtime(long curTime, int which);
2267
2268 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002269 * Returns the total, last, or current battery screen off uptime in microseconds.
2270 *
2271 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002272 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002273 */
2274 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2275
2276 /**
2277 * Returns the total, last, or current battery screen off realtime in microseconds.
2278 *
2279 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002280 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002281 */
2282 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2283
2284 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 * Returns the total, last, or current uptime in microseconds.
2286 *
2287 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002288 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289 */
2290 public abstract long computeUptime(long curTime, int which);
2291
2292 /**
2293 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002294 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002296 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 */
2298 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002299
2300 /**
2301 * Compute an approximation for how much run time (in microseconds) is remaining on
2302 * the battery. Returns -1 if no time can be computed: either there is not
2303 * enough current data to make a decision, or the battery is currently
2304 * charging.
2305 *
2306 * @param curTime The current elepsed realtime in microseconds.
2307 */
2308 public abstract long computeBatteryTimeRemaining(long curTime);
2309
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002310 // The part of a step duration that is the actual time.
2311 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2312
2313 // Bits in a step duration that are the new battery level we are at.
2314 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002315 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002316
2317 // Bits in a step duration that are the initial mode we were in at that step.
2318 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002319 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002320
2321 // Bits in a step duration that indicate which modes changed during that step.
2322 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002323 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002324
2325 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2326 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2327
2328 // Step duration mode: power save is on.
2329 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2330
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002331 // Step duration mode: device is currently in idle mode.
2332 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2333
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002334 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2335 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002336 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2337 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002338 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2339 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2340 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2341 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2342 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002343 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2344 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002345 };
2346 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2347 (Display.STATE_OFF-1),
2348 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002349 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002350 (Display.STATE_ON-1),
2351 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2352 (Display.STATE_DOZE-1),
2353 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2354 (Display.STATE_DOZE_SUSPEND-1),
2355 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002356 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002357 };
2358 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2359 "screen off",
2360 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002361 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002362 "screen on",
2363 "screen on power save",
2364 "screen doze",
2365 "screen doze power save",
2366 "screen doze-suspend",
2367 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002368 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002369 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002370
2371 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002372 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002373 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002374 public abstract LevelStepTracker getDischargeLevelStepTracker();
2375
2376 /**
2377 * Return the array of daily discharge step durations.
2378 */
2379 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002380
2381 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002382 * Compute an approximation for how much time (in microseconds) remains until the battery
2383 * is fully charged. Returns -1 if no time can be computed: either there is not
2384 * enough current data to make a decision, or the battery is currently
2385 * discharging.
2386 *
2387 * @param curTime The current elepsed realtime in microseconds.
2388 */
2389 public abstract long computeChargeTimeRemaining(long curTime);
2390
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002391 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002392 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002393 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002394 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002395
2396 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002397 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002398 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002399 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002400
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002401 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2402
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002403 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002404
Evan Millarc64edde2009-04-18 12:26:32 -07002405 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002407 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2408
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002409 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002410 long days = seconds / (60 * 60 * 24);
2411 if (days != 0) {
2412 out.append(days);
2413 out.append("d ");
2414 }
2415 long used = days * 60 * 60 * 24;
2416
2417 long hours = (seconds - used) / (60 * 60);
2418 if (hours != 0 || used != 0) {
2419 out.append(hours);
2420 out.append("h ");
2421 }
2422 used += hours * 60 * 60;
2423
2424 long mins = (seconds-used) / 60;
2425 if (mins != 0 || used != 0) {
2426 out.append(mins);
2427 out.append("m ");
2428 }
2429 used += mins * 60;
2430
2431 if (seconds != 0 || used != 0) {
2432 out.append(seconds-used);
2433 out.append("s ");
2434 }
2435 }
2436
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002437 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002439 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 sb.append(time - (sec * 1000));
2441 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 }
2443
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002444 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002445 long sec = time / 1000;
2446 formatTimeRaw(sb, sec);
2447 sb.append(time - (sec * 1000));
2448 sb.append("ms");
2449 }
2450
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002451 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002453 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002454 }
2455 float perc = ((float)num) / ((float)den) * 100;
2456 mFormatBuilder.setLength(0);
2457 mFormatter.format("%.1f%%", perc);
2458 return mFormatBuilder.toString();
2459 }
2460
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002461 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002462 mFormatBuilder.setLength(0);
2463
2464 if (bytes < BYTES_PER_KB) {
2465 return bytes + "B";
2466 } else if (bytes < BYTES_PER_MB) {
2467 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2468 return mFormatBuilder.toString();
2469 } else if (bytes < BYTES_PER_GB){
2470 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2471 return mFormatBuilder.toString();
2472 } else {
2473 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2474 return mFormatBuilder.toString();
2475 }
2476 }
2477
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002478 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002479 if (timer != null) {
2480 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002481 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002482 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2483 return totalTimeMillis;
2484 }
2485 return 0;
2486 }
2487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 /**
2489 *
2490 * @param sb a StringBuilder object.
2491 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002492 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002493 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002494 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 * @param linePrefix a String to be prepended to each line of output.
2496 * @return the line prefix
2497 */
2498 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002499 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002502 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002503
Evan Millarc64edde2009-04-18 12:26:32 -07002504 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 if (totalTimeMillis != 0) {
2506 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002507 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002508 if (name != null) {
2509 sb.append(name);
2510 sb.append(' ');
2511 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 sb.append('(');
2513 sb.append(count);
2514 sb.append(" times)");
2515 return ", ";
2516 }
2517 }
2518 return linePrefix;
2519 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002520
2521 /**
2522 *
2523 * @param pw a PrintWriter object to print to.
2524 * @param sb a StringBuilder object.
2525 * @param timer a Timer object contining the wakelock times.
2526 * @param rawRealtime the current on-battery time in microseconds.
2527 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2528 * @param prefix a String to be prepended to each line of output.
2529 * @param type the name of the timer.
2530 */
2531 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
2532 long rawRealtime, int which, String prefix, String type) {
2533 if (timer != null) {
2534 // Convert from microseconds to milliseconds with rounding
2535 final long totalTime = (timer.getTotalTimeLocked(
2536 rawRealtime, which) + 500) / 1000;
2537 final int count = timer.getCountLocked(which);
2538 if (totalTime != 0) {
2539 sb.setLength(0);
2540 sb.append(prefix);
2541 sb.append(" ");
2542 sb.append(type);
2543 sb.append(": ");
2544 formatTimeMs(sb, totalTime);
2545 sb.append("realtime (");
2546 sb.append(count);
2547 sb.append(" times)");
2548 pw.println(sb.toString());
2549 return true;
2550 }
2551 }
2552 return false;
2553 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554
2555 /**
2556 * Checkin version of wakelock printer. Prints simple comma-separated list.
2557 *
2558 * @param sb a StringBuilder object.
2559 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002560 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002562 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563 * @param linePrefix a String to be prepended to each line of output.
2564 * @return the line prefix
2565 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002566 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2567 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 long totalTimeMicros = 0;
2569 int count = 0;
2570 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002571 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002572 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 }
2574 sb.append(linePrefix);
2575 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2576 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002577 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002578 sb.append(count);
2579 return ",";
2580 }
2581
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002582 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2583 String type) {
2584 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2585 pw.print(',');
2586 pw.print(uid);
2587 pw.print(',');
2588 pw.print(category);
2589 pw.print(',');
2590 pw.print(type);
2591 }
2592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 /**
2594 * Dump a comma-separated line of values for terse checkin mode.
2595 *
2596 * @param pw the PageWriter to dump log to
2597 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2598 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2599 * @param args type-dependent data arguments
2600 */
2601 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2602 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002603 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002604 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002605 pw.print(',');
2606 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002608 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002609 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002610
2611 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002612 * Dump a given timer stat for terse checkin mode.
2613 *
2614 * @param pw the PageWriter to dump log to
2615 * @param uid the UID to log
2616 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2617 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2618 * @param timer a {@link Timer} to dump stats for
2619 * @param rawRealtime the current elapsed realtime of the system in microseconds
2620 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2621 */
2622 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2623 Timer timer, long rawRealtime, int which) {
2624 if (timer != null) {
2625 // Convert from microseconds to milliseconds with rounding
2626 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2627 / 1000;
2628 final int count = timer.getCountLocked(which);
2629 if (totalTime != 0) {
2630 dumpLine(pw, uid, category, type, totalTime, count);
2631 }
2632 }
2633 }
2634
2635 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002636 * Checks if the ControllerActivityCounter has any data worth dumping.
2637 */
2638 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2639 if (counter == null) {
2640 return false;
2641 }
2642
2643 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2644 || counter.getRxTimeCounter().getCountLocked(which) != 0
2645 || counter.getPowerCounter().getCountLocked(which) != 0) {
2646 return true;
2647 }
2648
2649 for (LongCounter c : counter.getTxTimeCounters()) {
2650 if (c.getCountLocked(which) != 0) {
2651 return true;
2652 }
2653 }
2654 return false;
2655 }
2656
2657 /**
2658 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2659 * The order of the arguments in the final check in line is:
2660 *
2661 * idle, rx, power, tx...
2662 *
2663 * where tx... is one or more transmit level times.
2664 */
2665 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2666 String type,
2667 ControllerActivityCounter counter,
2668 int which) {
2669 if (!controllerActivityHasData(counter, which)) {
2670 return;
2671 }
2672
2673 dumpLineHeader(pw, uid, category, type);
2674 pw.print(",");
2675 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2676 pw.print(",");
2677 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2678 pw.print(",");
2679 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2680 for (LongCounter c : counter.getTxTimeCounters()) {
2681 pw.print(",");
2682 pw.print(c.getCountLocked(which));
2683 }
2684 pw.println();
2685 }
2686
2687 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2688 String prefix, String controllerName,
2689 ControllerActivityCounter counter,
2690 int which) {
2691 if (controllerActivityHasData(counter, which)) {
2692 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2693 }
2694 }
2695
2696 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2697 String controllerName,
2698 ControllerActivityCounter counter, int which) {
2699 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2700 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2701 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2702 long totalTxTimeMs = 0;
2703 for (LongCounter txState : counter.getTxTimeCounters()) {
2704 totalTxTimeMs += txState.getCountLocked(which);
2705 }
2706
2707 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2708
2709 sb.setLength(0);
2710 sb.append(prefix);
2711 sb.append(" ");
2712 sb.append(controllerName);
2713 sb.append(" Idle time: ");
2714 formatTimeMs(sb, idleTimeMs);
2715 sb.append("(");
2716 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2717 sb.append(")");
2718 pw.println(sb.toString());
2719
2720 sb.setLength(0);
2721 sb.append(prefix);
2722 sb.append(" ");
2723 sb.append(controllerName);
2724 sb.append(" Rx time: ");
2725 formatTimeMs(sb, rxTimeMs);
2726 sb.append("(");
2727 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
2728 sb.append(")");
2729 pw.println(sb.toString());
2730
2731 sb.setLength(0);
2732 sb.append(prefix);
2733 sb.append(" ");
2734 sb.append(controllerName);
2735 sb.append(" Tx time: ");
2736 formatTimeMs(sb, totalTxTimeMs);
2737 sb.append("(");
2738 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
2739 sb.append(")");
2740 pw.println(sb.toString());
2741
2742 final int numTxLvls = counter.getTxTimeCounters().length;
2743 if (numTxLvls > 1) {
2744 for (int lvl = 0; lvl < numTxLvls; lvl++) {
2745 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
2746 sb.setLength(0);
2747 sb.append(prefix);
2748 sb.append(" [");
2749 sb.append(lvl);
2750 sb.append("] ");
2751 formatTimeMs(sb, txLvlTimeMs);
2752 sb.append("(");
2753 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
2754 sb.append(")");
2755 pw.println(sb.toString());
2756 }
2757 }
2758
2759 sb.setLength(0);
2760 sb.append(prefix);
2761 sb.append(" ");
2762 sb.append(controllerName);
2763 sb.append(" Power drain: ").append(
2764 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
2765 sb.append("mAh");
2766 pw.println(sb.toString());
2767 }
2768
2769 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07002770 * Temporary for settings.
2771 */
2772 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2773 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2774 }
2775
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 /**
2777 * Checkin server version of dump to produce more compact, computer-readable log.
2778 *
2779 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002780 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002781 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2782 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2784 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2785 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2787 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002788 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2789 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2790 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002791 final long totalRealtime = computeRealtime(rawRealtime, which);
2792 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002793 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002794 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002795 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002796 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
2797 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002798 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002799 rawRealtime, which);
2800 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
2801 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002802 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002803 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002804 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002805 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002806
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002807 final StringBuilder sb = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002809 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07002810 final int NU = uidStats.size();
2811
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002812 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 // Dump "battery" stat
2815 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002816 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002817 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002818 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002819 getStartClockTime(),
2820 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002822 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002823 long fullWakeLockTimeTotal = 0;
2824 long partialWakeLockTimeTotal = 0;
2825
2826 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002827 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002828
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002829 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
2830 = u.getWakelockStats();
2831 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2832 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07002833
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002834 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2835 if (fullWakeTimer != null) {
2836 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2837 which);
2838 }
2839
2840 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2841 if (partialWakeTimer != null) {
2842 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
2843 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002844 }
2845 }
2846 }
Adam Lesinskie283d332015-04-16 12:29:25 -07002847
2848 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002849 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2850 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2851 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2852 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2853 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2854 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2855 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2856 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002857 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
2858 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002859 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2860 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002861 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
2862 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002863
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002864 // Dump Modem controller stats
2865 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
2866 getModemControllerActivity(), which);
2867
Adam Lesinskie283d332015-04-16 12:29:25 -07002868 // Dump Wifi controller stats
2869 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2870 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002871 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08002872 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002873
2874 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
2875 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002876
2877 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002878 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
2879 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002880
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 // Dump misc stats
2882 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07002883 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002884 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07002885 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002886 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002887 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002888 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
2889 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07002890 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002891 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
2892 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
2893 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
2894 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002895 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002896
2897 // Dump screen brightness stats
2898 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2899 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002900 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002901 }
2902 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002903
Dianne Hackborn627bba72009-03-24 22:32:56 -07002904 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002905 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2906 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002907 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002908 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002909 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002910 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002911 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002912 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002913 args[i] = getPhoneSignalStrengthCount(i, which);
2914 }
2915 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002916
Dianne Hackborn627bba72009-03-24 22:32:56 -07002917 // Dump network type stats
2918 args = new Object[NUM_DATA_CONNECTION_TYPES];
2919 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002920 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002921 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002922 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2923 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2924 args[i] = getPhoneDataConnectionCount(i, which);
2925 }
2926 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002927
2928 // Dump wifi state stats
2929 args = new Object[NUM_WIFI_STATES];
2930 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002931 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002932 }
2933 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2934 for (int i=0; i<NUM_WIFI_STATES; i++) {
2935 args[i] = getWifiStateCount(i, which);
2936 }
2937 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2938
Dianne Hackborn3251b902014-06-20 14:40:53 -07002939 // Dump wifi suppl state stats
2940 args = new Object[NUM_WIFI_SUPPL_STATES];
2941 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2942 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2943 }
2944 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2945 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2946 args[i] = getWifiSupplStateCount(i, which);
2947 }
2948 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
2949
2950 // Dump wifi signal strength stats
2951 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
2952 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2953 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
2954 }
2955 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
2956 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2957 args[i] = getWifiSignalStrengthCount(i, which);
2958 }
2959 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
2960
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002961 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002962 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07002963 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002964 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002966 if (which == STATS_SINCE_UNPLUGGED) {
2967 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2968 getDischargeStartLevel()-getDischargeCurrentLevel(),
2969 getDischargeStartLevel()-getDischargeCurrentLevel(),
2970 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
2971 } else {
2972 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2973 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002974 getDischargeAmountScreenOnSinceCharge(),
2975 getDischargeAmountScreenOffSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002976 }
2977
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002978 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002979 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002980 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002981 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002982 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002983 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002984 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002985 sb.toString());
2986 }
Evan Millarc64edde2009-04-18 12:26:32 -07002987 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002988 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002989 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002990 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
2991 // Not doing the regular wake lock formatting to remain compatible
2992 // with the old checkin format.
2993 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
2994 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002995 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002996 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002997 }
2998 }
Evan Millarc64edde2009-04-18 12:26:32 -07002999 }
3000
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003001 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003002 helper.create(this);
3003 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003004 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003005 if (sippers != null && sippers.size() > 0) {
3006 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3007 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003008 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003009 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3010 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3011 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003012 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003013 int uid = 0;
3014 String label;
3015 switch (bs.drainType) {
3016 case IDLE:
3017 label="idle";
3018 break;
3019 case CELL:
3020 label="cell";
3021 break;
3022 case PHONE:
3023 label="phone";
3024 break;
3025 case WIFI:
3026 label="wifi";
3027 break;
3028 case BLUETOOTH:
3029 label="blue";
3030 break;
3031 case SCREEN:
3032 label="scrn";
3033 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003034 case FLASHLIGHT:
3035 label="flashlight";
3036 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003037 case APP:
3038 uid = bs.uidObj.getUid();
3039 label = "uid";
3040 break;
3041 case USER:
3042 uid = UserHandle.getUid(bs.userId, 0);
3043 label = "user";
3044 break;
3045 case UNACCOUNTED:
3046 label = "unacc";
3047 break;
3048 case OVERCOUNTED:
3049 label = "over";
3050 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003051 case CAMERA:
3052 label = "camera";
3053 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003054 default:
3055 label = "???";
3056 }
3057 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07003058 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003059 }
3060 }
3061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003062 for (int iu = 0; iu < NU; iu++) {
3063 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003064 if (reqUid >= 0 && uid != reqUid) {
3065 continue;
3066 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003067 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003069 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003070 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3071 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3072 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3073 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3074 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3075 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3076 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3077 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
3078 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3079 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003080 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3081 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003082 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3083 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003084 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
3085 || btBytesRx > 0 || btBytesTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003086 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3087 wifiBytesRx, wifiBytesTx,
3088 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003089 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003090 mobileActiveTime, mobileActiveCount,
3091 btBytesRx, btBytesTx);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003092 }
3093
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003094 // Dump modem controller data, per UID.
3095 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3096 u.getModemControllerActivity(), which);
3097
3098 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003099 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3100 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3101 final int wifiScanCount = u.getWifiScanCount(which);
3102 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003103 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003104 || uidWifiRunningTime != 0) {
3105 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3106 uidWifiRunningTime, wifiScanCount,
Kweku Adams5b2747e2016-04-25 10:44:05 -07003107 /* legacy fields follow, keep at 0 */ 0, 0, 0);
The Android Open Source Project10592532009-03-18 17:39:46 -07003108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003110 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3111 u.getWifiControllerActivity(), which);
3112
Adam Lesinskiba9d8932016-04-12 12:06:03 -07003113 dumpTimer(pw, uid, category, BLUETOOTH_MISC_DATA, u.getBluetoothScanTimer(),
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003114 rawRealtime, which);
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003115
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003116 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3117 u.getBluetoothControllerActivity(), which);
3118
Dianne Hackborn617f8772009-03-31 15:04:46 -07003119 if (u.hasUserActivity()) {
3120 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3121 boolean hasData = false;
3122 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3123 int val = u.getUserActivityCount(i, which);
3124 args[i] = val;
3125 if (val != 0) hasData = true;
3126 }
3127 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003128 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003129 }
3130 }
3131
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003132 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3133 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3134 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3135 String linePrefix = "";
3136 sb.setLength(0);
3137 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3138 rawRealtime, "f", which, linePrefix);
3139 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
3140 rawRealtime, "p", which, linePrefix);
3141 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3142 rawRealtime, "w", which, linePrefix);
3143
3144 // Only log if we had at lease one wakelock...
3145 if (sb.length() > 0) {
3146 String name = wakelocks.keyAt(iw);
3147 if (name.indexOf(',') >= 0) {
3148 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003149 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003150 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 }
3152 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003153
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003154 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3155 for (int isy=syncs.size()-1; isy>=0; isy--) {
3156 final Timer timer = syncs.valueAt(isy);
3157 // Convert from microseconds to milliseconds with rounding
3158 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3159 final int count = timer.getCountLocked(which);
3160 if (totalTime != 0) {
3161 dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003162 }
3163 }
3164
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003165 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3166 for (int ij=jobs.size()-1; ij>=0; ij--) {
3167 final Timer timer = jobs.valueAt(ij);
3168 // Convert from microseconds to milliseconds with rounding
3169 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3170 final int count = timer.getCountLocked(which);
3171 if (totalTime != 0) {
3172 dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003173 }
3174 }
3175
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003176 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3177 rawRealtime, which);
3178 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3179 rawRealtime, which);
3180 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3181 rawRealtime, which);
3182 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3183 rawRealtime, which);
3184
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003185 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3186 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003187 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003188 final Uid.Sensor se = sensors.valueAt(ise);
3189 final int sensorNumber = sensors.keyAt(ise);
3190 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003191 if (timer != null) {
3192 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003193 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3194 / 1000;
3195 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003196 if (totalTime != 0) {
3197 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
3198 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 }
3200 }
3201
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003202 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3203 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003204
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003205 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3206 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003207
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003208 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003209 long totalStateTime = 0;
3210 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003211 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3212 totalStateTime += time;
3213 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003214 }
3215 if (totalStateTime > 0) {
3216 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3217 }
3218
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003219 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3220 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
3221 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
3222 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
3223 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
3224 powerCpuMaUs / 1000);
3225 }
3226
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003227 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3228 = u.getProcessStats();
3229 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3230 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003231
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003232 final long userMillis = ps.getUserTime(which);
3233 final long systemMillis = ps.getSystemTime(which);
3234 final long foregroundMillis = ps.getForegroundTime(which);
3235 final int starts = ps.getStarts(which);
3236 final int numCrashes = ps.getNumCrashes(which);
3237 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003238
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003239 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3240 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
3241 dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis,
3242 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003243 }
3244 }
3245
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003246 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3247 = u.getPackageStats();
3248 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3249 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3250 int wakeups = 0;
3251 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3252 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
3253 wakeups += alarms.valueAt(iwa).getCountLocked(which);
3254 }
3255 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3256 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3257 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3258 final long startTime = ss.getStartTime(batteryUptime, which);
3259 final int starts = ss.getStarts(which);
3260 final int launches = ss.getLaunches(which);
3261 if (startTime != 0 || starts != 0 || launches != 0) {
3262 dumpLine(pw, uid, category, APK_DATA,
3263 wakeups, // wakeup alarms
3264 packageStats.keyAt(ipkg), // Apk
3265 serviceStats.keyAt(isvc), // service
3266 startTime / 1000, // time spent started, in ms
3267 starts,
3268 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003269 }
3270 }
3271 }
3272 }
3273 }
3274
Dianne Hackborn81038902012-11-26 17:04:09 -08003275 static final class TimerEntry {
3276 final String mName;
3277 final int mId;
3278 final BatteryStats.Timer mTimer;
3279 final long mTime;
3280 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3281 mName = name;
3282 mId = id;
3283 mTimer = timer;
3284 mTime = time;
3285 }
3286 }
3287
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003288 private void printmAh(PrintWriter printer, double power) {
3289 printer.print(BatteryStatsHelper.makemAh(power));
3290 }
3291
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003292 private void printmAh(StringBuilder sb, double power) {
3293 sb.append(BatteryStatsHelper.makemAh(power));
3294 }
3295
Dianne Hackbornd953c532014-08-16 18:17:38 -07003296 /**
3297 * Temporary for settings.
3298 */
3299 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3300 int reqUid) {
3301 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3302 }
3303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003305 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003306 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3308 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3309 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003310
3311 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3312 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3313 final long totalRealtime = computeRealtime(rawRealtime, which);
3314 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003315 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3316 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3317 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003318 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3319 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003320
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003321 final StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07003322
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003323 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003324 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003326 sb.setLength(0);
3327 sb.append(prefix);
3328 sb.append(" Time on battery: ");
3329 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3330 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3331 sb.append(") realtime, ");
3332 formatTimeMs(sb, whichBatteryUptime / 1000);
3333 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3334 sb.append(") uptime");
3335 pw.println(sb.toString());
3336 sb.setLength(0);
3337 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003338 sb.append(" Time on battery screen off: ");
3339 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3340 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3341 sb.append(") realtime, ");
3342 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3343 sb.append("(");
3344 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3345 sb.append(") uptime");
3346 pw.println(sb.toString());
3347 sb.setLength(0);
3348 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003349 sb.append(" Total run time: ");
3350 formatTimeMs(sb, totalRealtime / 1000);
3351 sb.append("realtime, ");
3352 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003353 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003354 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003355 if (batteryTimeRemaining >= 0) {
3356 sb.setLength(0);
3357 sb.append(prefix);
3358 sb.append(" Battery time remaining: ");
3359 formatTimeMs(sb, batteryTimeRemaining / 1000);
3360 pw.println(sb.toString());
3361 }
3362 if (chargeTimeRemaining >= 0) {
3363 sb.setLength(0);
3364 sb.append(prefix);
3365 sb.append(" Charge time remaining: ");
3366 formatTimeMs(sb, chargeTimeRemaining / 1000);
3367 pw.println(sb.toString());
3368 }
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003369 pw.print(" Start clock time: ");
3370 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3371
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003372 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003373 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003374 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003375 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3376 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003377 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003378 rawRealtime, which);
3379 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3380 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003381 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003382 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003383 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3384 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3385 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003386 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003387 sb.append(prefix);
3388 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3389 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003390 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003391 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3392 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003393 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003394 pw.println(sb.toString());
3395 sb.setLength(0);
3396 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003397 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003398 boolean didOne = false;
3399 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003400 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003401 if (time == 0) {
3402 continue;
3403 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003404 sb.append("\n ");
3405 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003406 didOne = true;
3407 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3408 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003409 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003410 sb.append("(");
3411 sb.append(formatRatioLocked(time, screenOnTime));
3412 sb.append(")");
3413 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003414 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003415 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003416 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003417 sb.setLength(0);
3418 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003419 sb.append(" Power save mode enabled: ");
3420 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003421 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003422 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003423 sb.append(")");
3424 pw.println(sb.toString());
3425 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003426 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003427 sb.setLength(0);
3428 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003429 sb.append(" Device light idling: ");
3430 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003431 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003432 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3433 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003434 sb.append("x");
3435 pw.println(sb.toString());
3436 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003437 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003438 sb.setLength(0);
3439 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003440 sb.append(" Idle mode light time: ");
3441 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003442 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003443 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3444 sb.append(") ");
3445 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003446 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003447 sb.append(" -- longest ");
3448 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3449 pw.println(sb.toString());
3450 }
3451 if (deviceIdlingTime != 0) {
3452 sb.setLength(0);
3453 sb.append(prefix);
3454 sb.append(" Device full idling: ");
3455 formatTimeMs(sb, deviceIdlingTime / 1000);
3456 sb.append("(");
3457 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003458 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003459 sb.append("x");
3460 pw.println(sb.toString());
3461 }
3462 if (deviceIdleModeFullTime != 0) {
3463 sb.setLength(0);
3464 sb.append(prefix);
3465 sb.append(" Idle mode full time: ");
3466 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3467 sb.append("(");
3468 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3469 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003470 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003471 sb.append("x");
3472 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003473 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003474 pw.println(sb.toString());
3475 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003476 if (phoneOnTime != 0) {
3477 sb.setLength(0);
3478 sb.append(prefix);
3479 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3480 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003481 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003482 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003483 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003484 if (connChanges != 0) {
3485 pw.print(prefix);
3486 pw.print(" Connectivity changes: "); pw.println(connChanges);
3487 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003488
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003489 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003490 long fullWakeLockTimeTotalMicros = 0;
3491 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003492
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003493 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003494
Evan Millar22ac0432009-03-31 11:33:18 -07003495 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003496 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003497
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003498 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3499 = u.getWakelockStats();
3500 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3501 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003502
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003503 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3504 if (fullWakeTimer != null) {
3505 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3506 rawRealtime, which);
3507 }
3508
3509 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3510 if (partialWakeTimer != null) {
3511 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3512 rawRealtime, which);
3513 if (totalTimeMicros > 0) {
3514 if (reqUid < 0) {
3515 // Only show the ordered list of all wake
3516 // locks if the caller is not asking for data
3517 // about a specific uid.
3518 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3519 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003520 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003521 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003522 }
3523 }
3524 }
3525 }
3526
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003527 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3528 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3529 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3530 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3531 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3532 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3533 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3534 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08003535 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3536 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003537
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003538 if (fullWakeLockTimeTotalMicros != 0) {
3539 sb.setLength(0);
3540 sb.append(prefix);
3541 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3542 (fullWakeLockTimeTotalMicros + 500) / 1000);
3543 pw.println(sb.toString());
3544 }
3545
3546 if (partialWakeLockTimeTotalMicros != 0) {
3547 sb.setLength(0);
3548 sb.append(prefix);
3549 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3550 (partialWakeLockTimeTotalMicros + 500) / 1000);
3551 pw.println(sb.toString());
3552 }
3553
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003554 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003555 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3556 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3557 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3558 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003559 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003560 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003561 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003562 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003563 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003564 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003565 if (time == 0) {
3566 continue;
3567 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003568 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003569 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003570 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003571 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003572 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003573 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003574 sb.append("(");
3575 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003576 sb.append(") ");
3577 sb.append(getPhoneSignalStrengthCount(i, which));
3578 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003579 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003580 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003581 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003582
3583 sb.setLength(0);
3584 sb.append(prefix);
3585 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003586 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003587 pw.println(sb.toString());
3588
Dianne Hackborn627bba72009-03-24 22:32:56 -07003589 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003590 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003591 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003592 didOne = false;
3593 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003594 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003595 if (time == 0) {
3596 continue;
3597 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003598 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003599 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003600 didOne = true;
3601 sb.append(DATA_CONNECTION_NAMES[i]);
3602 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003603 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003604 sb.append("(");
3605 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003606 sb.append(") ");
3607 sb.append(getPhoneDataConnectionCount(i, which));
3608 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003609 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003610 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003611 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003612
3613 sb.setLength(0);
3614 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003615 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003616 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003617 formatTimeMs(sb, mobileActiveTime / 1000);
3618 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3619 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3620 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003621 pw.println(sb.toString());
3622
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003623 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3624 if (mobileActiveUnknownTime != 0) {
3625 sb.setLength(0);
3626 sb.append(prefix);
3627 sb.append(" Mobile radio active unknown time: ");
3628 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3629 sb.append("(");
3630 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3631 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3632 sb.append("x");
3633 pw.println(sb.toString());
3634 }
3635
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003636 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3637 if (mobileActiveAdjustedTime != 0) {
3638 sb.setLength(0);
3639 sb.append(prefix);
3640 sb.append(" Mobile radio active adjusted time: ");
3641 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3642 sb.append("(");
3643 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3644 sb.append(")");
3645 pw.println(sb.toString());
3646 }
3647
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003648 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
3649
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003650 pw.print(prefix);
3651 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3652 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3653 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3654 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003655 sb.setLength(0);
3656 sb.append(prefix);
3657 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3658 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3659 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3660 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003661 sb.append(")");
3662 pw.println(sb.toString());
3663
3664 sb.setLength(0);
3665 sb.append(prefix);
3666 sb.append(" Wifi states:");
3667 didOne = false;
3668 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003669 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003670 if (time == 0) {
3671 continue;
3672 }
3673 sb.append("\n ");
3674 didOne = true;
3675 sb.append(WIFI_STATE_NAMES[i]);
3676 sb.append(" ");
3677 formatTimeMs(sb, time/1000);
3678 sb.append("(");
3679 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3680 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003681 sb.append(getWifiStateCount(i, which));
3682 sb.append("x");
3683 }
3684 if (!didOne) sb.append(" (no activity)");
3685 pw.println(sb.toString());
3686
3687 sb.setLength(0);
3688 sb.append(prefix);
3689 sb.append(" Wifi supplicant states:");
3690 didOne = false;
3691 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3692 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3693 if (time == 0) {
3694 continue;
3695 }
3696 sb.append("\n ");
3697 didOne = true;
3698 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3699 sb.append(" ");
3700 formatTimeMs(sb, time/1000);
3701 sb.append("(");
3702 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3703 sb.append(") ");
3704 sb.append(getWifiSupplStateCount(i, which));
3705 sb.append("x");
3706 }
3707 if (!didOne) sb.append(" (no activity)");
3708 pw.println(sb.toString());
3709
3710 sb.setLength(0);
3711 sb.append(prefix);
3712 sb.append(" Wifi signal levels:");
3713 didOne = false;
3714 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3715 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3716 if (time == 0) {
3717 continue;
3718 }
3719 sb.append("\n ");
3720 sb.append(prefix);
3721 didOne = true;
3722 sb.append("level(");
3723 sb.append(i);
3724 sb.append(") ");
3725 formatTimeMs(sb, time/1000);
3726 sb.append("(");
3727 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3728 sb.append(") ");
3729 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003730 sb.append("x");
3731 }
3732 if (!didOne) sb.append(" (no activity)");
3733 pw.println(sb.toString());
3734
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003735 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07003736
Adam Lesinski50e47602015-12-04 17:04:54 -08003737 pw.print(prefix);
3738 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
3739 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
3740
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003741 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
3742 sb.setLength(0);
3743 sb.append(prefix);
3744 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
3745 pw.println(sb.toString());
3746
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003747 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
3748 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003749
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003750 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003751
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003752 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003753 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003754 pw.print(prefix); pw.println(" Device is currently unplugged");
3755 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3756 pw.println(getDischargeStartLevel());
3757 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3758 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003759 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003760 pw.print(prefix); pw.println(" Device is currently plugged into power");
3761 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3762 pw.println(getDischargeStartLevel());
3763 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3764 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003765 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003766 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3767 pw.println(getDischargeAmountScreenOn());
3768 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3769 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003770 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003771 } else {
3772 pw.print(prefix); pw.println(" Device battery use since last full charge");
3773 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3774 pw.println(getLowDischargeAmountSinceCharge());
3775 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3776 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003777 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3778 pw.println(getDischargeAmountScreenOnSinceCharge());
3779 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3780 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003781 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003782 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003783
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003784 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003785 helper.create(this);
3786 helper.refreshStats(which, UserHandle.USER_ALL);
3787 List<BatterySipper> sippers = helper.getUsageList();
3788 if (sippers != null && sippers.size() > 0) {
3789 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3790 pw.print(prefix); pw.print(" Capacity: ");
3791 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003792 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003793 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3794 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3795 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3796 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003797 pw.println();
3798 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003799 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003800 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003801 switch (bs.drainType) {
3802 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003803 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003804 break;
3805 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003806 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003807 break;
3808 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003809 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003810 break;
3811 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003812 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003813 break;
3814 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003815 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003816 break;
3817 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003818 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003819 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003820 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003821 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003822 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003823 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003824 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003825 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003826 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003827 break;
3828 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003829 pw.print(" User "); pw.print(bs.userId);
3830 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003831 break;
3832 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003833 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003834 break;
3835 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003836 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003837 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003838 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003839 pw.print(" Camera: ");
3840 break;
3841 default:
3842 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003843 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003844 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003845 printmAh(pw, bs.totalPowerMah);
3846
Adam Lesinski57123002015-06-12 16:12:07 -07003847 if (bs.usagePowerMah != bs.totalPowerMah) {
3848 // If the usage (generic power) isn't the whole amount, we list out
3849 // what components are involved in the calculation.
3850
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003851 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07003852 if (bs.usagePowerMah != 0) {
3853 pw.print(" usage=");
3854 printmAh(pw, bs.usagePowerMah);
3855 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003856 if (bs.cpuPowerMah != 0) {
3857 pw.print(" cpu=");
3858 printmAh(pw, bs.cpuPowerMah);
3859 }
3860 if (bs.wakeLockPowerMah != 0) {
3861 pw.print(" wake=");
3862 printmAh(pw, bs.wakeLockPowerMah);
3863 }
3864 if (bs.mobileRadioPowerMah != 0) {
3865 pw.print(" radio=");
3866 printmAh(pw, bs.mobileRadioPowerMah);
3867 }
3868 if (bs.wifiPowerMah != 0) {
3869 pw.print(" wifi=");
3870 printmAh(pw, bs.wifiPowerMah);
3871 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003872 if (bs.bluetoothPowerMah != 0) {
3873 pw.print(" bt=");
3874 printmAh(pw, bs.bluetoothPowerMah);
3875 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003876 if (bs.gpsPowerMah != 0) {
3877 pw.print(" gps=");
3878 printmAh(pw, bs.gpsPowerMah);
3879 }
3880 if (bs.sensorPowerMah != 0) {
3881 pw.print(" sensor=");
3882 printmAh(pw, bs.sensorPowerMah);
3883 }
3884 if (bs.cameraPowerMah != 0) {
3885 pw.print(" camera=");
3886 printmAh(pw, bs.cameraPowerMah);
3887 }
3888 if (bs.flashlightPowerMah != 0) {
3889 pw.print(" flash=");
3890 printmAh(pw, bs.flashlightPowerMah);
3891 }
3892 pw.print(" )");
3893 }
3894 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003895 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08003896 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003897 }
3898
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003899 sippers = helper.getMobilemsppList();
3900 if (sippers != null && sippers.size() > 0) {
3901 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003902 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003903 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003904 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003905 sb.setLength(0);
3906 sb.append(prefix); sb.append(" Uid ");
3907 UserHandle.formatUid(sb, bs.uidObj.getUid());
3908 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
3909 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
3910 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003911 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003912 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003913 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003914 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003915 sb.setLength(0);
3916 sb.append(prefix);
3917 sb.append(" TOTAL TIME: ");
3918 formatTimeMs(sb, totalTime);
3919 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
3920 sb.append(")");
3921 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003922 pw.println();
3923 }
3924
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003925 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
3926 @Override
3927 public int compare(TimerEntry lhs, TimerEntry rhs) {
3928 long lhsTime = lhs.mTime;
3929 long rhsTime = rhs.mTime;
3930 if (lhsTime < rhsTime) {
3931 return 1;
3932 }
3933 if (lhsTime > rhsTime) {
3934 return -1;
3935 }
3936 return 0;
3937 }
3938 };
3939
3940 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003941 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
3942 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003943 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003944 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
3945 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
3946 : kernelWakelocks.entrySet()) {
3947 final BatteryStats.Timer timer = ent.getValue();
3948 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003949 if (totalTimeMillis > 0) {
3950 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
3951 }
3952 }
3953 if (ktimers.size() > 0) {
3954 Collections.sort(ktimers, timerComparator);
3955 pw.print(prefix); pw.println(" All kernel wake locks:");
3956 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003957 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003958 String linePrefix = ": ";
3959 sb.setLength(0);
3960 sb.append(prefix);
3961 sb.append(" Kernel Wake lock ");
3962 sb.append(timer.mName);
3963 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
3964 which, linePrefix);
3965 if (!linePrefix.equals(": ")) {
3966 sb.append(" realtime");
3967 // Only print out wake locks that were held
3968 pw.println(sb.toString());
3969 }
3970 }
3971 pw.println();
3972 }
3973 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003974
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003975 if (timers.size() > 0) {
3976 Collections.sort(timers, timerComparator);
3977 pw.print(prefix); pw.println(" All partial wake locks:");
3978 for (int i=0; i<timers.size(); i++) {
3979 TimerEntry timer = timers.get(i);
3980 sb.setLength(0);
3981 sb.append(" Wake lock ");
3982 UserHandle.formatUid(sb, timer.mId);
3983 sb.append(" ");
3984 sb.append(timer.mName);
3985 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3986 sb.append(" realtime");
3987 pw.println(sb.toString());
3988 }
3989 timers.clear();
3990 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08003991 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003992
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003993 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003994 if (wakeupReasons.size() > 0) {
3995 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003996 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003997 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003998 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003999 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4000 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004001 }
4002 Collections.sort(reasons, timerComparator);
4003 for (int i=0; i<reasons.size(); i++) {
4004 TimerEntry timer = reasons.get(i);
4005 String linePrefix = ": ";
4006 sb.setLength(0);
4007 sb.append(prefix);
4008 sb.append(" Wakeup reason ");
4009 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004010 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4011 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004012 pw.println(sb.toString());
4013 }
4014 pw.println();
4015 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004016 }
Evan Millar22ac0432009-03-31 11:33:18 -07004017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004018 for (int iu=0; iu<NU; iu++) {
4019 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004020 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004021 continue;
4022 }
4023
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004024 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004025
4026 pw.print(prefix);
4027 pw.print(" ");
4028 UserHandle.formatUid(pw, uid);
4029 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004030 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004031
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004032 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4033 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4034 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4035 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004036 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4037 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4038
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004039 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4040 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004041 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4042 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004043
4044 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4045 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4046
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004047 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4048 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4049 final int wifiScanCount = u.getWifiScanCount(which);
4050 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004051
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004052 if (mobileRxBytes > 0 || mobileTxBytes > 0
4053 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004054 pw.print(prefix); pw.print(" Mobile network: ");
4055 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004056 pw.print(formatBytesLocked(mobileTxBytes));
4057 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4058 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004059 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004060 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4061 sb.setLength(0);
4062 sb.append(prefix); sb.append(" Mobile radio active: ");
4063 formatTimeMs(sb, uidMobileActiveTime / 1000);
4064 sb.append("(");
4065 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4066 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4067 long packets = mobileRxPackets + mobileTxPackets;
4068 if (packets == 0) {
4069 packets = 1;
4070 }
4071 sb.append(" @ ");
4072 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4073 sb.append(" mspp");
4074 pw.println(sb.toString());
4075 }
4076
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004077 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4078 u.getModemControllerActivity(), which);
4079
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004080 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004081 pw.print(prefix); pw.print(" Wi-Fi network: ");
4082 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004083 pw.print(formatBytesLocked(wifiTxBytes));
4084 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4085 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004086 }
4087
Dianne Hackborn62793e42015-03-09 11:15:41 -07004088 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004089 || uidWifiRunningTime != 0) {
4090 sb.setLength(0);
4091 sb.append(prefix); sb.append(" Wifi Running: ");
4092 formatTimeMs(sb, uidWifiRunningTime / 1000);
4093 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4094 whichBatteryRealtime)); sb.append(")\n");
4095 sb.append(prefix); sb.append(" Full Wifi Lock: ");
4096 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4097 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4098 whichBatteryRealtime)); sb.append(")\n");
4099 sb.append(prefix); sb.append(" Wifi Scan: ");
4100 formatTimeMs(sb, wifiScanTime / 1000);
4101 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004102 whichBatteryRealtime)); sb.append(") ");
4103 sb.append(wifiScanCount);
4104 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004105 pw.println(sb.toString());
4106 }
4107
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004108 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4109 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004110
Adam Lesinski50e47602015-12-04 17:04:54 -08004111 if (btRxBytes > 0 || btTxBytes > 0) {
4112 pw.print(prefix); pw.print(" Bluetooth network: ");
4113 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4114 pw.print(formatBytesLocked(btTxBytes));
4115 pw.println(" sent");
4116 }
4117
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004118 uidActivity |= printTimer(pw, sb, u.getBluetoothScanTimer(), rawRealtime, which, prefix,
4119 "Bluetooth Scan");
4120
Dianne Hackborn617f8772009-03-31 15:04:46 -07004121 if (u.hasUserActivity()) {
4122 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004123 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004124 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004125 if (val != 0) {
4126 if (!hasData) {
4127 sb.setLength(0);
4128 sb.append(" User activity: ");
4129 hasData = true;
4130 } else {
4131 sb.append(", ");
4132 }
4133 sb.append(val);
4134 sb.append(" ");
4135 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4136 }
4137 }
4138 if (hasData) {
4139 pw.println(sb.toString());
4140 }
4141 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004142
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004143 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4144 = u.getWakelockStats();
4145 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004146 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004147 int countWakelock = 0;
4148 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4149 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4150 String linePrefix = ": ";
4151 sb.setLength(0);
4152 sb.append(prefix);
4153 sb.append(" Wake lock ");
4154 sb.append(wakelocks.keyAt(iw));
4155 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4156 "full", which, linePrefix);
4157 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
4158 "partial", which, linePrefix);
4159 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4160 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004161 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4162 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004163 sb.append(" realtime");
4164 pw.println(sb.toString());
4165 uidActivity = true;
4166 countWakelock++;
4167
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004168 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4169 rawRealtime, which);
4170 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4171 rawRealtime, which);
4172 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4173 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004174 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004175 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004176 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004177 if (countWakelock > 1) {
4178 if (totalFullWakelock != 0 || totalPartialWakelock != 0
4179 || totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004180 sb.setLength(0);
4181 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004182 sb.append(" TOTAL wake: ");
4183 boolean needComma = false;
4184 if (totalFullWakelock != 0) {
4185 needComma = true;
4186 formatTimeMs(sb, totalFullWakelock);
4187 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004188 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004189 if (totalPartialWakelock != 0) {
4190 if (needComma) {
4191 sb.append(", ");
4192 }
4193 needComma = true;
4194 formatTimeMs(sb, totalPartialWakelock);
4195 sb.append("partial");
4196 }
4197 if (totalWindowWakelock != 0) {
4198 if (needComma) {
4199 sb.append(", ");
4200 }
4201 needComma = true;
4202 formatTimeMs(sb, totalWindowWakelock);
4203 sb.append("window");
4204 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004205 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004206 if (needComma) {
4207 sb.append(",");
4208 }
4209 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004210 formatTimeMs(sb, totalDrawWakelock);
4211 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004212 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004213 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004214 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004215 }
4216 }
4217
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004218 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4219 for (int isy=syncs.size()-1; isy>=0; isy--) {
4220 final Timer timer = syncs.valueAt(isy);
4221 // Convert from microseconds to milliseconds with rounding
4222 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4223 final int count = timer.getCountLocked(which);
4224 sb.setLength(0);
4225 sb.append(prefix);
4226 sb.append(" Sync ");
4227 sb.append(syncs.keyAt(isy));
4228 sb.append(": ");
4229 if (totalTime != 0) {
4230 formatTimeMs(sb, totalTime);
4231 sb.append("realtime (");
4232 sb.append(count);
4233 sb.append(" times)");
4234 } else {
4235 sb.append("(not used)");
4236 }
4237 pw.println(sb.toString());
4238 uidActivity = true;
4239 }
4240
4241 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4242 for (int ij=jobs.size()-1; ij>=0; ij--) {
4243 final Timer timer = jobs.valueAt(ij);
4244 // Convert from microseconds to milliseconds with rounding
4245 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4246 final int count = timer.getCountLocked(which);
4247 sb.setLength(0);
4248 sb.append(prefix);
4249 sb.append(" Job ");
4250 sb.append(jobs.keyAt(ij));
4251 sb.append(": ");
4252 if (totalTime != 0) {
4253 formatTimeMs(sb, totalTime);
4254 sb.append("realtime (");
4255 sb.append(count);
4256 sb.append(" times)");
4257 } else {
4258 sb.append("(not used)");
4259 }
4260 pw.println(sb.toString());
4261 uidActivity = true;
4262 }
4263
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004264 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
4265 prefix, "Flashlight");
4266 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
4267 prefix, "Camera");
4268 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
4269 prefix, "Video");
4270 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
4271 prefix, "Audio");
4272
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004273 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4274 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004275 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004276 final Uid.Sensor se = sensors.valueAt(ise);
4277 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004278 sb.setLength(0);
4279 sb.append(prefix);
4280 sb.append(" Sensor ");
4281 int handle = se.getHandle();
4282 if (handle == Uid.Sensor.GPS) {
4283 sb.append("GPS");
4284 } else {
4285 sb.append(handle);
4286 }
4287 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004288
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004289 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004290 if (timer != null) {
4291 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004292 final long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn61659e52014-07-09 16:13:01 -07004293 rawRealtime, which) + 500) / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004294 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004295 //timer.logState();
4296 if (totalTime != 0) {
4297 formatTimeMs(sb, totalTime);
4298 sb.append("realtime (");
4299 sb.append(count);
4300 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301 } else {
4302 sb.append("(not used)");
4303 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004304 } else {
4305 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004307
4308 pw.println(sb.toString());
4309 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 }
4311
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004312 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4313 "Vibrator");
4314 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4315 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004316
Dianne Hackborn61659e52014-07-09 16:13:01 -07004317 long totalStateTime = 0;
4318 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4319 long time = u.getProcessStateTime(ips, rawRealtime, which);
4320 if (time > 0) {
4321 totalStateTime += time;
4322 sb.setLength(0);
4323 sb.append(prefix);
4324 sb.append(" ");
4325 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4326 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08004327 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004328 pw.println(sb.toString());
4329 uidActivity = true;
4330 }
4331 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08004332 if (totalStateTime > 0) {
4333 sb.setLength(0);
4334 sb.append(prefix);
4335 sb.append(" Total running: ");
4336 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4337 pw.println(sb.toString());
4338 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004339
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004340 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4341 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004342 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
4343 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004344 sb.setLength(0);
4345 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004346 sb.append(" Total cpu time: u=");
4347 formatTimeMs(sb, userCpuTimeUs / 1000);
4348 sb.append("s=");
4349 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004350 sb.append("p=");
4351 printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0));
4352 sb.append("mAh");
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004353 pw.println(sb.toString());
4354 }
4355
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004356 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4357 = u.getProcessStats();
4358 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4359 final Uid.Proc ps = processStats.valueAt(ipr);
4360 long userTime;
4361 long systemTime;
4362 long foregroundTime;
4363 int starts;
4364 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004366 userTime = ps.getUserTime(which);
4367 systemTime = ps.getSystemTime(which);
4368 foregroundTime = ps.getForegroundTime(which);
4369 starts = ps.getStarts(which);
4370 final int numCrashes = ps.getNumCrashes(which);
4371 final int numAnrs = ps.getNumAnrs(which);
4372 numExcessive = which == STATS_SINCE_CHARGED
4373 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004374
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004375 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
4376 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
4377 sb.setLength(0);
4378 sb.append(prefix); sb.append(" Proc ");
4379 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
4380 sb.append(prefix); sb.append(" CPU: ");
4381 formatTimeMs(sb, userTime); sb.append("usr + ");
4382 formatTimeMs(sb, systemTime); sb.append("krn ; ");
4383 formatTimeMs(sb, foregroundTime); sb.append("fg");
4384 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
4385 sb.append("\n"); sb.append(prefix); sb.append(" ");
4386 boolean hasOne = false;
4387 if (starts != 0) {
4388 hasOne = true;
4389 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07004390 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004391 if (numCrashes != 0) {
4392 if (hasOne) {
4393 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004394 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004395 hasOne = true;
4396 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004397 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004398 if (numAnrs != 0) {
4399 if (hasOne) {
4400 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004401 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004402 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004403 }
4404 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004405 pw.println(sb.toString());
4406 for (int e=0; e<numExcessive; e++) {
4407 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
4408 if (ew != null) {
4409 pw.print(prefix); pw.print(" * Killed for ");
4410 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
4411 pw.print("wake lock");
4412 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
4413 pw.print("cpu");
4414 } else {
4415 pw.print("unknown");
4416 }
4417 pw.print(" use: ");
4418 TimeUtils.formatDuration(ew.usedTime, pw);
4419 pw.print(" over ");
4420 TimeUtils.formatDuration(ew.overTime, pw);
4421 if (ew.overTime != 0) {
4422 pw.print(" (");
4423 pw.print((ew.usedTime*100)/ew.overTime);
4424 pw.println("%)");
4425 }
4426 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004427 }
4428 uidActivity = true;
4429 }
4430 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004431
4432 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4433 = u.getPackageStats();
4434 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4435 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
4436 pw.println(":");
4437 boolean apkActivity = false;
4438 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4439 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4440 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
4441 pw.print(prefix); pw.print(" Wakeup alarm ");
4442 pw.print(alarms.keyAt(iwa)); pw.print(": ");
4443 pw.print(alarms.valueAt(iwa).getCountLocked(which));
4444 pw.println(" times");
4445 apkActivity = true;
4446 }
4447 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4448 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4449 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4450 final long startTime = ss.getStartTime(batteryUptime, which);
4451 final int starts = ss.getStarts(which);
4452 final int launches = ss.getLaunches(which);
4453 if (startTime != 0 || starts != 0 || launches != 0) {
4454 sb.setLength(0);
4455 sb.append(prefix); sb.append(" Service ");
4456 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
4457 sb.append(prefix); sb.append(" Created for: ");
4458 formatTimeMs(sb, startTime / 1000);
4459 sb.append("uptime\n");
4460 sb.append(prefix); sb.append(" Starts: ");
4461 sb.append(starts);
4462 sb.append(", launches: "); sb.append(launches);
4463 pw.println(sb.toString());
4464 apkActivity = true;
4465 }
4466 }
4467 if (!apkActivity) {
4468 pw.print(prefix); pw.println(" (nothing executed)");
4469 }
4470 uidActivity = true;
4471 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004472 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004473 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004474 }
4475 }
4476 }
4477
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004478 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004479 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004480 int diff = oldval ^ newval;
4481 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004482 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004483 for (int i=0; i<descriptions.length; i++) {
4484 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004485 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004486 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004487 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004488 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004489 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004490 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
4491 didWake = true;
4492 pw.print("=");
4493 if (longNames) {
4494 UserHandle.formatUid(pw, wakelockTag.uid);
4495 pw.print(":\"");
4496 pw.print(wakelockTag.string);
4497 pw.print("\"");
4498 } else {
4499 pw.print(wakelockTag.poolIdx);
4500 }
4501 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004502 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004503 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004504 pw.print("=");
4505 int val = (newval&bd.mask)>>bd.shift;
4506 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004507 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004508 } else {
4509 pw.print(val);
4510 }
4511 }
4512 }
4513 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004514 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07004515 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004516 if (longNames) {
4517 UserHandle.formatUid(pw, wakelockTag.uid);
4518 pw.print(":\"");
4519 pw.print(wakelockTag.string);
4520 pw.print("\"");
4521 } else {
4522 pw.print(wakelockTag.poolIdx);
4523 }
4524 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004525 }
4526
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004527 public void prepareForDumpLocked() {
4528 }
4529
4530 public static class HistoryPrinter {
4531 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004532 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004533 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004534 int oldStatus = -1;
4535 int oldHealth = -1;
4536 int oldPlug = -1;
4537 int oldTemp = -1;
4538 int oldVolt = -1;
Adam Lesinski926969b2016-04-28 17:31:12 -07004539 int oldCharge = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004540 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004541
Dianne Hackborn3251b902014-06-20 14:40:53 -07004542 void reset() {
4543 oldState = oldState2 = 0;
4544 oldLevel = -1;
4545 oldStatus = -1;
4546 oldHealth = -1;
4547 oldPlug = -1;
4548 oldTemp = -1;
4549 oldVolt = -1;
Adam Lesinski926969b2016-04-28 17:31:12 -07004550 oldCharge = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07004551 }
4552
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004553 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004554 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004555 if (!checkin) {
4556 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004557 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004558 pw.print(" (");
4559 pw.print(rec.numReadInts);
4560 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004561 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004562 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4563 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004564 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004565 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004566 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004567 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004568 }
4569 lastTime = rec.time;
4570 }
4571 if (rec.cmd == HistoryItem.CMD_START) {
4572 if (checkin) {
4573 pw.print(":");
4574 }
4575 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004576 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004577 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4578 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004579 if (checkin) {
4580 pw.print(":");
4581 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004582 if (rec.cmd == HistoryItem.CMD_RESET) {
4583 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004584 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004585 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004586 pw.print("TIME:");
4587 if (checkin) {
4588 pw.println(rec.currentTime);
4589 } else {
4590 pw.print(" ");
4591 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4592 rec.currentTime).toString());
4593 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004594 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4595 if (checkin) {
4596 pw.print(":");
4597 }
4598 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004599 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4600 if (checkin) {
4601 pw.print(":");
4602 }
4603 pw.println("*OVERFLOW*");
4604 } else {
4605 if (!checkin) {
4606 if (rec.batteryLevel < 10) pw.print("00");
4607 else if (rec.batteryLevel < 100) pw.print("0");
4608 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004609 if (verbose) {
4610 pw.print(" ");
4611 if (rec.states < 0) ;
4612 else if (rec.states < 0x10) pw.print("0000000");
4613 else if (rec.states < 0x100) pw.print("000000");
4614 else if (rec.states < 0x1000) pw.print("00000");
4615 else if (rec.states < 0x10000) pw.print("0000");
4616 else if (rec.states < 0x100000) pw.print("000");
4617 else if (rec.states < 0x1000000) pw.print("00");
4618 else if (rec.states < 0x10000000) pw.print("0");
4619 pw.print(Integer.toHexString(rec.states));
4620 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004621 } else {
4622 if (oldLevel != rec.batteryLevel) {
4623 oldLevel = rec.batteryLevel;
4624 pw.print(",Bl="); pw.print(rec.batteryLevel);
4625 }
4626 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004627 if (oldStatus != rec.batteryStatus) {
4628 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004629 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004630 switch (oldStatus) {
4631 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004632 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004633 break;
4634 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004635 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004636 break;
4637 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004638 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004639 break;
4640 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004641 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004642 break;
4643 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004644 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004645 break;
4646 default:
4647 pw.print(oldStatus);
4648 break;
4649 }
4650 }
4651 if (oldHealth != rec.batteryHealth) {
4652 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004653 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004654 switch (oldHealth) {
4655 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004656 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004657 break;
4658 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004659 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004660 break;
4661 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004662 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004663 break;
4664 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004665 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004666 break;
4667 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004668 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004669 break;
4670 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004671 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004672 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004673 case BatteryManager.BATTERY_HEALTH_COLD:
4674 pw.print(checkin ? "c" : "cold");
4675 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004676 default:
4677 pw.print(oldHealth);
4678 break;
4679 }
4680 }
4681 if (oldPlug != rec.batteryPlugType) {
4682 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004683 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004684 switch (oldPlug) {
4685 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004686 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004687 break;
4688 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004689 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004690 break;
4691 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004692 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004693 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004694 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004695 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004696 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004697 default:
4698 pw.print(oldPlug);
4699 break;
4700 }
4701 }
4702 if (oldTemp != rec.batteryTemperature) {
4703 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004704 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004705 pw.print(oldTemp);
4706 }
4707 if (oldVolt != rec.batteryVoltage) {
4708 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004709 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004710 pw.print(oldVolt);
4711 }
Adam Lesinski926969b2016-04-28 17:31:12 -07004712 if (oldCharge != rec.batteryChargeCoulombs) {
4713 oldCharge = rec.batteryChargeCoulombs;
4714 pw.print(checkin ? ",Bcc=" : " charge=");
4715 pw.print(oldCharge);
4716 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004717 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004718 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004719 printBitDescriptions(pw, oldState2, rec.states2, null,
4720 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004721 if (rec.wakeReasonTag != null) {
4722 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004723 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004724 pw.print(rec.wakeReasonTag.poolIdx);
4725 } else {
4726 pw.print(" wake_reason=");
4727 pw.print(rec.wakeReasonTag.uid);
4728 pw.print(":\"");
4729 pw.print(rec.wakeReasonTag.string);
4730 pw.print("\"");
4731 }
4732 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004733 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004734 pw.print(checkin ? "," : " ");
4735 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4736 pw.print("+");
4737 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4738 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004739 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004740 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4741 : HISTORY_EVENT_NAMES;
4742 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4743 | HistoryItem.EVENT_FLAG_FINISH);
4744 if (idx >= 0 && idx < eventNames.length) {
4745 pw.print(eventNames[idx]);
4746 } else {
4747 pw.print(checkin ? "Ev" : "event");
4748 pw.print(idx);
4749 }
4750 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004751 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004752 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004753 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004754 UserHandle.formatUid(pw, rec.eventTag.uid);
4755 pw.print(":\"");
4756 pw.print(rec.eventTag.string);
4757 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004758 }
4759 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004760 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004761 if (rec.stepDetails != null) {
4762 if (!checkin) {
4763 pw.print(" Details: cpu=");
4764 pw.print(rec.stepDetails.userTime);
4765 pw.print("u+");
4766 pw.print(rec.stepDetails.systemTime);
4767 pw.print("s");
4768 if (rec.stepDetails.appCpuUid1 >= 0) {
4769 pw.print(" (");
4770 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4771 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4772 if (rec.stepDetails.appCpuUid2 >= 0) {
4773 pw.print(", ");
4774 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4775 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4776 }
4777 if (rec.stepDetails.appCpuUid3 >= 0) {
4778 pw.print(", ");
4779 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4780 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4781 }
4782 pw.print(')');
4783 }
4784 pw.println();
4785 pw.print(" /proc/stat=");
4786 pw.print(rec.stepDetails.statUserTime);
4787 pw.print(" usr, ");
4788 pw.print(rec.stepDetails.statSystemTime);
4789 pw.print(" sys, ");
4790 pw.print(rec.stepDetails.statIOWaitTime);
4791 pw.print(" io, ");
4792 pw.print(rec.stepDetails.statIrqTime);
4793 pw.print(" irq, ");
4794 pw.print(rec.stepDetails.statSoftIrqTime);
4795 pw.print(" sirq, ");
4796 pw.print(rec.stepDetails.statIdlTime);
4797 pw.print(" idle");
4798 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4799 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4800 + rec.stepDetails.statSoftIrqTime;
4801 int total = totalRun + rec.stepDetails.statIdlTime;
4802 if (total > 0) {
4803 pw.print(" (");
4804 float perc = ((float)totalRun) / ((float)total) * 100;
4805 pw.print(String.format("%.1f%%", perc));
4806 pw.print(" of ");
4807 StringBuilder sb = new StringBuilder(64);
4808 formatTimeMsNoSpace(sb, total*10);
4809 pw.print(sb);
4810 pw.print(")");
4811 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07004812 pw.print(", PlatformIdleStat ");
4813 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004814 pw.println();
4815 } else {
4816 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4817 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4818 pw.print(rec.stepDetails.userTime);
4819 pw.print(":");
4820 pw.print(rec.stepDetails.systemTime);
4821 if (rec.stepDetails.appCpuUid1 >= 0) {
4822 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4823 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4824 if (rec.stepDetails.appCpuUid2 >= 0) {
4825 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4826 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4827 }
4828 if (rec.stepDetails.appCpuUid3 >= 0) {
4829 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4830 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4831 }
4832 }
4833 pw.println();
4834 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4835 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4836 pw.print(rec.stepDetails.statUserTime);
4837 pw.print(',');
4838 pw.print(rec.stepDetails.statSystemTime);
4839 pw.print(',');
4840 pw.print(rec.stepDetails.statIOWaitTime);
4841 pw.print(',');
4842 pw.print(rec.stepDetails.statIrqTime);
4843 pw.print(',');
4844 pw.print(rec.stepDetails.statSoftIrqTime);
4845 pw.print(',');
4846 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07004847 pw.print(',');
4848 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004849 pw.println();
4850 }
4851 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004852 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004853 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004854 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004855 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004856
4857 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4858 UserHandle.formatUid(pw, uid);
4859 pw.print("=");
4860 pw.print(utime);
4861 pw.print("u+");
4862 pw.print(stime);
4863 pw.print("s");
4864 }
4865
4866 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
4867 pw.print('/');
4868 pw.print(uid);
4869 pw.print(":");
4870 pw.print(utime);
4871 pw.print(":");
4872 pw.print(stime);
4873 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004874 }
4875
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004876 private void printSizeValue(PrintWriter pw, long size) {
4877 float result = size;
4878 String suffix = "";
4879 if (result >= 10*1024) {
4880 suffix = "KB";
4881 result = result / 1024;
4882 }
4883 if (result >= 10*1024) {
4884 suffix = "MB";
4885 result = result / 1024;
4886 }
4887 if (result >= 10*1024) {
4888 suffix = "GB";
4889 result = result / 1024;
4890 }
4891 if (result >= 10*1024) {
4892 suffix = "TB";
4893 result = result / 1024;
4894 }
4895 if (result >= 10*1024) {
4896 suffix = "PB";
4897 result = result / 1024;
4898 }
4899 pw.print((int)result);
4900 pw.print(suffix);
4901 }
4902
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004903 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
4904 String label3, long estimatedTime) {
4905 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004906 return false;
4907 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004908 pw.print(label1);
4909 pw.print(label2);
4910 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004911 StringBuilder sb = new StringBuilder(64);
4912 formatTimeMs(sb, estimatedTime);
4913 pw.print(sb);
4914 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004915 return true;
4916 }
4917
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004918 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
4919 LevelStepTracker steps, boolean checkin) {
4920 if (steps == null) {
4921 return false;
4922 }
4923 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004924 if (count <= 0) {
4925 return false;
4926 }
4927 if (!checkin) {
4928 pw.println(header);
4929 }
Kweku Adams030980a2015-04-01 16:07:48 -07004930 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004931 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004932 long duration = steps.getDurationAt(i);
4933 int level = steps.getLevelAt(i);
4934 long initMode = steps.getInitModeAt(i);
4935 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004936 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004937 lineArgs[0] = Long.toString(duration);
4938 lineArgs[1] = Integer.toString(level);
4939 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4940 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4941 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
4942 case Display.STATE_ON: lineArgs[2] = "s+"; break;
4943 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
4944 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07004945 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004946 }
4947 } else {
4948 lineArgs[2] = "";
4949 }
4950 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4951 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
4952 } else {
4953 lineArgs[3] = "";
4954 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004955 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07004956 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004957 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07004958 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004959 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004960 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
4961 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004962 pw.print(prefix);
4963 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004964 TimeUtils.formatDuration(duration, pw);
4965 pw.print(" to "); pw.print(level);
4966 boolean haveModes = false;
4967 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4968 pw.print(" (");
4969 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4970 case Display.STATE_OFF: pw.print("screen-off"); break;
4971 case Display.STATE_ON: pw.print("screen-on"); break;
4972 case Display.STATE_DOZE: pw.print("screen-doze"); break;
4973 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07004974 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004975 }
4976 haveModes = true;
4977 }
4978 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4979 pw.print(haveModes ? ", " : " (");
4980 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
4981 ? "power-save-on" : "power-save-off");
4982 haveModes = true;
4983 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004984 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
4985 pw.print(haveModes ? ", " : " (");
4986 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
4987 ? "device-idle-on" : "device-idle-off");
4988 haveModes = true;
4989 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004990 if (haveModes) {
4991 pw.print(")");
4992 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004993 pw.println();
4994 }
4995 }
4996 return true;
4997 }
4998
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004999 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005000 public static final int DUMP_DAILY_ONLY = 1<<2;
5001 public static final int DUMP_HISTORY_ONLY = 1<<3;
5002 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5003 public static final int DUMP_VERBOSE = 1<<5;
5004 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005005
Dianne Hackborn37de0982014-05-09 09:32:18 -07005006 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5007 final HistoryPrinter hprinter = new HistoryPrinter();
5008 final HistoryItem rec = new HistoryItem();
5009 long lastTime = -1;
5010 long baseTime = -1;
5011 boolean printed = false;
5012 HistoryEventTracker tracker = null;
5013 while (getNextHistoryLocked(rec)) {
5014 lastTime = rec.time;
5015 if (baseTime < 0) {
5016 baseTime = lastTime;
5017 }
5018 if (rec.time >= histStart) {
5019 if (histStart >= 0 && !printed) {
5020 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005021 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005022 || rec.cmd == HistoryItem.CMD_START
5023 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005024 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005025 hprinter.printNextItem(pw, rec, baseTime, checkin,
5026 (flags&DUMP_VERBOSE) != 0);
5027 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005028 } else if (rec.currentTime != 0) {
5029 printed = true;
5030 byte cmd = rec.cmd;
5031 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005032 hprinter.printNextItem(pw, rec, baseTime, checkin,
5033 (flags&DUMP_VERBOSE) != 0);
5034 rec.cmd = cmd;
5035 }
5036 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005037 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5038 hprinter.printNextItem(pw, rec, baseTime, checkin,
5039 (flags&DUMP_VERBOSE) != 0);
5040 rec.cmd = HistoryItem.CMD_UPDATE;
5041 }
5042 int oldEventCode = rec.eventCode;
5043 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005044 rec.eventTag = new HistoryTag();
5045 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5046 HashMap<String, SparseIntArray> active
5047 = tracker.getStateForEvent(i);
5048 if (active == null) {
5049 continue;
5050 }
5051 for (HashMap.Entry<String, SparseIntArray> ent
5052 : active.entrySet()) {
5053 SparseIntArray uids = ent.getValue();
5054 for (int j=0; j<uids.size(); j++) {
5055 rec.eventCode = i;
5056 rec.eventTag.string = ent.getKey();
5057 rec.eventTag.uid = uids.keyAt(j);
5058 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005059 hprinter.printNextItem(pw, rec, baseTime, checkin,
5060 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005061 rec.wakeReasonTag = null;
5062 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005063 }
5064 }
5065 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005066 rec.eventCode = oldEventCode;
5067 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005068 tracker = null;
5069 }
5070 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005071 hprinter.printNextItem(pw, rec, baseTime, checkin,
5072 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005073 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5074 // This is an attempt to aggregate the previous state and generate
5075 // fake events to reflect that state at the point where we start
5076 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005077 if (tracker == null) {
5078 tracker = new HistoryEventTracker();
5079 }
5080 tracker.updateState(rec.eventCode, rec.eventTag.string,
5081 rec.eventTag.uid, rec.eventTag.poolIdx);
5082 }
5083 }
5084 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005085 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005086 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5087 }
5088 }
5089
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005090 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5091 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5092 if (steps == null) {
5093 return;
5094 }
5095 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5096 if (timeRemaining >= 0) {
5097 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5098 tmpSb.setLength(0);
5099 formatTimeMs(tmpSb, timeRemaining);
5100 pw.print(tmpSb);
5101 pw.print(" (from "); pw.print(tmpOutInt[0]);
5102 pw.println(" steps)");
5103 }
5104 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5105 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5106 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5107 if (estimatedTime > 0) {
5108 pw.print(prefix); pw.print(label); pw.print(" ");
5109 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5110 pw.print(" time: ");
5111 tmpSb.setLength(0);
5112 formatTimeMs(tmpSb, estimatedTime);
5113 pw.print(tmpSb);
5114 pw.print(" (from "); pw.print(tmpOutInt[0]);
5115 pw.println(" steps)");
5116 }
5117 }
5118 }
5119
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005120 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5121 ArrayList<PackageChange> changes) {
5122 if (changes == null) {
5123 return;
5124 }
5125 pw.print(prefix); pw.println("Package changes:");
5126 for (int i=0; i<changes.size(); i++) {
5127 PackageChange pc = changes.get(i);
5128 if (pc.mUpdate) {
5129 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5130 pw.print(" vers="); pw.println(pc.mVersionCode);
5131 } else {
5132 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5133 }
5134 }
5135 }
5136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005137 /**
5138 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5139 *
5140 * @param pw a Printer to receive the dump output.
5141 */
5142 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005143 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005144 prepareForDumpLocked();
5145
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005146 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005147 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005148
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005149 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005150 final long historyTotalSize = getHistoryTotalSize();
5151 final long historyUsedSize = getHistoryUsedSize();
5152 if (startIteratingHistoryLocked()) {
5153 try {
5154 pw.print("Battery History (");
5155 pw.print((100*historyUsedSize)/historyTotalSize);
5156 pw.print("% used, ");
5157 printSizeValue(pw, historyUsedSize);
5158 pw.print(" used of ");
5159 printSizeValue(pw, historyTotalSize);
5160 pw.print(", ");
5161 pw.print(getHistoryStringPoolSize());
5162 pw.print(" strings using ");
5163 printSizeValue(pw, getHistoryStringPoolBytes());
5164 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005165 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005166 pw.println();
5167 } finally {
5168 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005169 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005170 }
5171
5172 if (startIteratingOldHistoryLocked()) {
5173 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005174 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005175 pw.println("Old battery History:");
5176 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005177 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005178 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005179 if (baseTime < 0) {
5180 baseTime = rec.time;
5181 }
5182 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005183 }
5184 pw.println();
5185 } finally {
5186 finishIteratingOldHistoryLocked();
5187 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005188 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005189 }
5190
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005191 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005192 return;
5193 }
5194
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005195 if (!filtering) {
5196 SparseArray<? extends Uid> uidStats = getUidStats();
5197 final int NU = uidStats.size();
5198 boolean didPid = false;
5199 long nowRealtime = SystemClock.elapsedRealtime();
5200 for (int i=0; i<NU; i++) {
5201 Uid uid = uidStats.valueAt(i);
5202 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
5203 if (pids != null) {
5204 for (int j=0; j<pids.size(); j++) {
5205 Uid.Pid pid = pids.valueAt(j);
5206 if (!didPid) {
5207 pw.println("Per-PID Stats:");
5208 didPid = true;
5209 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005210 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
5211 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005212 pw.print(" PID "); pw.print(pids.keyAt(j));
5213 pw.print(" wake time: ");
5214 TimeUtils.formatDuration(time, pw);
5215 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005216 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005217 }
5218 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005219 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005220 pw.println();
5221 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005222 }
5223
5224 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005225 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
5226 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005227 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5228 if (timeRemaining >= 0) {
5229 pw.print(" Estimated discharge time remaining: ");
5230 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5231 pw.println();
5232 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005233 final LevelStepTracker steps = getDischargeLevelStepTracker();
5234 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5235 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
5236 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5237 STEP_LEVEL_MODE_VALUES[i], null));
5238 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005239 pw.println();
5240 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005241 if (dumpDurationSteps(pw, " ", "Charge step durations:",
5242 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005243 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5244 if (timeRemaining >= 0) {
5245 pw.print(" Estimated charge time remaining: ");
5246 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5247 pw.println();
5248 }
5249 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005250 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005251 }
5252 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
5253 pw.println("Daily stats:");
5254 pw.print(" Current start time: ");
5255 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5256 getCurrentDailyStartTime()).toString());
5257 pw.print(" Next min deadline: ");
5258 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5259 getNextMinDailyDeadline()).toString());
5260 pw.print(" Next max deadline: ");
5261 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5262 getNextMaxDailyDeadline()).toString());
5263 StringBuilder sb = new StringBuilder(64);
5264 int[] outInt = new int[1];
5265 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
5266 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005267 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
5268 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005269 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005270 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
5271 dsteps, false)) {
5272 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5273 sb, outInt);
5274 }
5275 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
5276 csteps, false)) {
5277 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5278 sb, outInt);
5279 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005280 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005281 } else {
5282 pw.println(" Current daily steps:");
5283 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5284 sb, outInt);
5285 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5286 sb, outInt);
5287 }
5288 }
5289 DailyItem dit;
5290 int curIndex = 0;
5291 while ((dit=getDailyItemLocked(curIndex)) != null) {
5292 curIndex++;
5293 if ((flags&DUMP_DAILY_ONLY) != 0) {
5294 pw.println();
5295 }
5296 pw.print(" Daily from ");
5297 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
5298 pw.print(" to ");
5299 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
5300 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005301 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005302 if (dumpDurationSteps(pw, " ",
5303 " Discharge step durations:", dit.mDischargeSteps, false)) {
5304 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5305 sb, outInt);
5306 }
5307 if (dumpDurationSteps(pw, " ",
5308 " Charge step durations:", dit.mChargeSteps, false)) {
5309 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5310 sb, outInt);
5311 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005312 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005313 } else {
5314 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5315 sb, outInt);
5316 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5317 sb, outInt);
5318 }
5319 }
5320 pw.println();
5321 }
5322 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005323 pw.println("Statistics since last charge:");
5324 pw.println(" System starts: " + getStartCount()
5325 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005326 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5327 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005328 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005329 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005330 }
5331
5332 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005333 public void dumpCheckinLocked(Context context, PrintWriter pw,
5334 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005335 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005336
5337 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005338 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5339 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005340
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005341 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5342
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005343 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005344 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005345
5346 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005347 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005348 try {
5349 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5350 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5351 pw.print(HISTORY_STRING_POOL); pw.print(',');
5352 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005353 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005354 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005355 pw.print(",\"");
5356 String str = getHistoryTagPoolString(i);
5357 str = str.replace("\\", "\\\\");
5358 str = str.replace("\"", "\\\"");
5359 pw.print(str);
5360 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005361 pw.println();
5362 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005363 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005364 } finally {
5365 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08005366 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005367 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005368 }
5369
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005370 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005371 return;
5372 }
5373
Dianne Hackborne4a59512010-12-07 11:08:07 -08005374 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005375 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08005376 for (int i=0; i<apps.size(); i++) {
5377 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005378 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
5379 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08005380 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005381 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
5382 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005383 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005384 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005385 }
5386 SparseArray<? extends Uid> uidStats = getUidStats();
5387 final int NU = uidStats.size();
5388 String[] lineArgs = new String[2];
5389 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005390 int uid = UserHandle.getAppId(uidStats.keyAt(i));
5391 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
5392 if (pkgs != null && !pkgs.second.value) {
5393 pkgs.second.value = true;
5394 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08005395 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005396 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005397 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
5398 (Object[])lineArgs);
5399 }
5400 }
5401 }
5402 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005403 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005404 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005405 String[] lineArgs = new String[1];
5406 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5407 if (timeRemaining >= 0) {
5408 lineArgs[0] = Long.toString(timeRemaining);
5409 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
5410 (Object[])lineArgs);
5411 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005412 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005413 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5414 if (timeRemaining >= 0) {
5415 lineArgs[0] = Long.toString(timeRemaining);
5416 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
5417 (Object[])lineArgs);
5418 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07005419 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
5420 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005421 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005422 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005423}