blob: 7f94d0e60fc5327681ddb2d16284041b63078ab1 [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
1073 public HistoryStepDetails() {
1074 clear();
1075 }
1076
1077 public void clear() {
1078 userTime = systemTime = 0;
1079 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1080 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1081 = appCpuUTime3 = appCpuSTime3 = 0;
1082 }
1083
1084 public void writeToParcel(Parcel out) {
1085 out.writeInt(userTime);
1086 out.writeInt(systemTime);
1087 out.writeInt(appCpuUid1);
1088 out.writeInt(appCpuUTime1);
1089 out.writeInt(appCpuSTime1);
1090 out.writeInt(appCpuUid2);
1091 out.writeInt(appCpuUTime2);
1092 out.writeInt(appCpuSTime2);
1093 out.writeInt(appCpuUid3);
1094 out.writeInt(appCpuUTime3);
1095 out.writeInt(appCpuSTime3);
1096 out.writeInt(statUserTime);
1097 out.writeInt(statSystemTime);
1098 out.writeInt(statIOWaitTime);
1099 out.writeInt(statIrqTime);
1100 out.writeInt(statSoftIrqTime);
1101 out.writeInt(statIdlTime);
1102 }
1103
1104 public void readFromParcel(Parcel in) {
1105 userTime = in.readInt();
1106 systemTime = in.readInt();
1107 appCpuUid1 = in.readInt();
1108 appCpuUTime1 = in.readInt();
1109 appCpuSTime1 = in.readInt();
1110 appCpuUid2 = in.readInt();
1111 appCpuUTime2 = in.readInt();
1112 appCpuSTime2 = in.readInt();
1113 appCpuUid3 = in.readInt();
1114 appCpuUTime3 = in.readInt();
1115 appCpuSTime3 = in.readInt();
1116 statUserTime = in.readInt();
1117 statSystemTime = in.readInt();
1118 statIOWaitTime = in.readInt();
1119 statIrqTime = in.readInt();
1120 statSoftIrqTime = in.readInt();
1121 statIdlTime = in.readInt();
1122 }
1123 }
1124
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001125 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001126 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001127
1128 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001129 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001130
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001131 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001132 public static final byte CMD_NULL = -1;
1133 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001134 public static final byte CMD_CURRENT_TIME = 5;
1135 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001136 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001137 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001138
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001139 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001140
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001141 /**
1142 * Return whether the command code is a delta data update.
1143 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001144 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001145 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001146 }
1147
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001148 public byte batteryLevel;
1149 public byte batteryStatus;
1150 public byte batteryHealth;
1151 public byte batteryPlugType;
1152
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001153 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001154 public char batteryVoltage;
1155
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001156 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001157 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001158 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001159 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001160 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1161 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001162 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001163 public static final int STATE_PHONE_STATE_SHIFT = 6;
1164 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001165 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001166 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001167 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001168
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001169 // These states always appear directly in the first int token
1170 // of a delta change; they should be ones that change relatively
1171 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001172 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1173 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001174 public static final int STATE_GPS_ON_FLAG = 1<<29;
1175 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001176 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001177 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001178 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001179 // These are on the lower bits used for the command; if they change
1180 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001181 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001182 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001183 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001184 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1185 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1186 // empty slot
1187 // empty slot
1188 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001189
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001190 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001191 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1192
1193 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001194
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001195 public int states;
1196
Dianne Hackborn3251b902014-06-20 14:40:53 -07001197 // Constants from WIFI_SUPPL_STATE_*
1198 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1199 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1200 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1201 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1202 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1203 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1204
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001205 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001206 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1207 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1208 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001209 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001210 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1211 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1212 public static final int STATE2_CHARGING_FLAG = 1<<24;
1213 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1214 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1215 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001216 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001217
1218 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001219 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001220 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1221
1222 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001223
Dianne Hackborn40c87252014-03-19 16:55:40 -07001224 public int states2;
1225
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001226 // The wake lock that was acquired at this point.
1227 public HistoryTag wakelockTag;
1228
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001229 // Kernel wakeup reason at this point.
1230 public HistoryTag wakeReasonTag;
1231
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001232 // Non-null when there is more detailed information at this step.
1233 public HistoryStepDetails stepDetails;
1234
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001235 public static final int EVENT_FLAG_START = 0x8000;
1236 public static final int EVENT_FLAG_FINISH = 0x4000;
1237
1238 // No event in this item.
1239 public static final int EVENT_NONE = 0x0000;
1240 // Event is about a process that is running.
1241 public static final int EVENT_PROC = 0x0001;
1242 // Event is about an application package that is in the foreground.
1243 public static final int EVENT_FOREGROUND = 0x0002;
1244 // Event is about an application package that is at the top of the screen.
1245 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001246 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001247 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001248 // Events for all additional wake locks aquired/release within a wake block.
1249 // These are not generated by default.
1250 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001251 // Event is about an application executing a scheduled job.
1252 public static final int EVENT_JOB = 0x0006;
1253 // Events for users running.
1254 public static final int EVENT_USER_RUNNING = 0x0007;
1255 // Events for foreground user.
1256 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001257 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001258 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001259 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001260 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001261 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001262 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001263 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001264 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001265 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001266 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001267 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001268 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001269 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001270 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001271 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001272 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001273 // Event for a package being on the temporary whitelist.
1274 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001275 // Event for the screen waking up.
1276 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Amith Yamasani67768492015-06-09 12:23:58 -07001277
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001278 // Number of event types.
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001279 public static final int EVENT_COUNT = 0x0013;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001280 // Mask to extract out only the type part of the event.
1281 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001282
1283 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1284 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1285 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1286 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1287 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1288 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001289 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1290 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001291 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1292 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001293 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1294 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1295 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1296 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1297 public static final int EVENT_USER_FOREGROUND_START =
1298 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1299 public static final int EVENT_USER_FOREGROUND_FINISH =
1300 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001301 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1302 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001303 public static final int EVENT_TEMP_WHITELIST_START =
1304 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1305 public static final int EVENT_TEMP_WHITELIST_FINISH =
1306 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001307
1308 // For CMD_EVENT.
1309 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001310 public HistoryTag eventTag;
1311
Dianne Hackborn9a755432014-05-15 17:05:22 -07001312 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001313 public long currentTime;
1314
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001315 // Meta-data when reading.
1316 public int numReadInts;
1317
1318 // Pre-allocated objects.
1319 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001320 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001321 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001322
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001323 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001324 }
1325
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001326 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001327 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001328 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001329 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001330 }
1331
1332 public int describeContents() {
1333 return 0;
1334 }
1335
1336 public void writeToParcel(Parcel dest, int flags) {
1337 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001338 int bat = (((int)cmd)&0xff)
1339 | ((((int)batteryLevel)<<8)&0xff00)
1340 | ((((int)batteryStatus)<<16)&0xf0000)
1341 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001342 | ((((int)batteryPlugType)<<24)&0xf000000)
1343 | (wakelockTag != null ? 0x10000000 : 0)
1344 | (wakeReasonTag != null ? 0x20000000 : 0)
1345 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001346 dest.writeInt(bat);
1347 bat = (((int)batteryTemperature)&0xffff)
1348 | ((((int)batteryVoltage)<<16)&0xffff0000);
1349 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001350 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001351 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001352 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001353 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001354 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001355 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001356 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001357 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001358 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001359 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001360 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001361 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001362 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001363 dest.writeLong(currentTime);
1364 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001365 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001366
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001367 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001368 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001369 int bat = src.readInt();
1370 cmd = (byte)(bat&0xff);
1371 batteryLevel = (byte)((bat>>8)&0xff);
1372 batteryStatus = (byte)((bat>>16)&0xf);
1373 batteryHealth = (byte)((bat>>20)&0xf);
1374 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001375 int bat2 = src.readInt();
1376 batteryTemperature = (short)(bat2&0xffff);
1377 batteryVoltage = (char)((bat2>>16)&0xffff);
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001378 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001379 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001380 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001381 wakelockTag = localWakelockTag;
1382 wakelockTag.readFromParcel(src);
1383 } else {
1384 wakelockTag = null;
1385 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001386 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001387 wakeReasonTag = localWakeReasonTag;
1388 wakeReasonTag.readFromParcel(src);
1389 } else {
1390 wakeReasonTag = null;
1391 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001392 if ((bat&0x40000000) != 0) {
1393 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001394 eventTag = localEventTag;
1395 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001396 } else {
1397 eventCode = EVENT_NONE;
1398 eventTag = null;
1399 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001400 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001401 currentTime = src.readLong();
1402 } else {
1403 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001404 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001405 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001406 }
1407
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001408 public void clear() {
1409 time = 0;
1410 cmd = CMD_NULL;
1411 batteryLevel = 0;
1412 batteryStatus = 0;
1413 batteryHealth = 0;
1414 batteryPlugType = 0;
1415 batteryTemperature = 0;
1416 batteryVoltage = 0;
1417 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001418 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001419 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001420 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001421 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001422 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001423 }
1424
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001425 public void setTo(HistoryItem o) {
1426 time = o.time;
1427 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001428 setToCommon(o);
1429 }
1430
1431 public void setTo(long time, byte cmd, HistoryItem o) {
1432 this.time = time;
1433 this.cmd = cmd;
1434 setToCommon(o);
1435 }
1436
1437 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001438 batteryLevel = o.batteryLevel;
1439 batteryStatus = o.batteryStatus;
1440 batteryHealth = o.batteryHealth;
1441 batteryPlugType = o.batteryPlugType;
1442 batteryTemperature = o.batteryTemperature;
1443 batteryVoltage = o.batteryVoltage;
1444 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001445 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001446 if (o.wakelockTag != null) {
1447 wakelockTag = localWakelockTag;
1448 wakelockTag.setTo(o.wakelockTag);
1449 } else {
1450 wakelockTag = null;
1451 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001452 if (o.wakeReasonTag != null) {
1453 wakeReasonTag = localWakeReasonTag;
1454 wakeReasonTag.setTo(o.wakeReasonTag);
1455 } else {
1456 wakeReasonTag = null;
1457 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001458 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001459 if (o.eventTag != null) {
1460 eventTag = localEventTag;
1461 eventTag.setTo(o.eventTag);
1462 } else {
1463 eventTag = null;
1464 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001465 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001466 }
1467
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001468 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001469 return batteryLevel == o.batteryLevel
1470 && batteryStatus == o.batteryStatus
1471 && batteryHealth == o.batteryHealth
1472 && batteryPlugType == o.batteryPlugType
1473 && batteryTemperature == o.batteryTemperature
1474 && batteryVoltage == o.batteryVoltage
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001475 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001476 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001477 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001478 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001479
1480 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001481 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001482 return false;
1483 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001484 if (wakelockTag != o.wakelockTag) {
1485 if (wakelockTag == null || o.wakelockTag == null) {
1486 return false;
1487 }
1488 if (!wakelockTag.equals(o.wakelockTag)) {
1489 return false;
1490 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001491 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001492 if (wakeReasonTag != o.wakeReasonTag) {
1493 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1494 return false;
1495 }
1496 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1497 return false;
1498 }
1499 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001500 if (eventTag != o.eventTag) {
1501 if (eventTag == null || o.eventTag == null) {
1502 return false;
1503 }
1504 if (!eventTag.equals(o.eventTag)) {
1505 return false;
1506 }
1507 }
1508 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001509 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001510 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001511
1512 public final static class HistoryEventTracker {
1513 private final HashMap<String, SparseIntArray>[] mActiveEvents
1514 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1515
1516 public boolean updateState(int code, String name, int uid, int poolIdx) {
1517 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1518 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1519 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1520 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001521 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001522 mActiveEvents[idx] = active;
1523 }
1524 SparseIntArray uids = active.get(name);
1525 if (uids == null) {
1526 uids = new SparseIntArray();
1527 active.put(name, uids);
1528 }
1529 if (uids.indexOfKey(uid) >= 0) {
1530 // Already set, nothing to do!
1531 return false;
1532 }
1533 uids.put(uid, poolIdx);
1534 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1535 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1536 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1537 if (active == null) {
1538 // not currently active, nothing to do.
1539 return false;
1540 }
1541 SparseIntArray uids = active.get(name);
1542 if (uids == null) {
1543 // not currently active, nothing to do.
1544 return false;
1545 }
1546 idx = uids.indexOfKey(uid);
1547 if (idx < 0) {
1548 // not currently active, nothing to do.
1549 return false;
1550 }
1551 uids.removeAt(idx);
1552 if (uids.size() <= 0) {
1553 active.remove(name);
1554 }
1555 }
1556 return true;
1557 }
1558
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001559 public void removeEvents(int code) {
1560 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1561 mActiveEvents[idx] = null;
1562 }
1563
Dianne Hackborn37de0982014-05-09 09:32:18 -07001564 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1565 return mActiveEvents[code];
1566 }
1567 }
1568
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001569 public static final class BitDescription {
1570 public final int mask;
1571 public final int shift;
1572 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001573 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001574 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001575 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001576
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001577 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001578 this.mask = mask;
1579 this.shift = -1;
1580 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001581 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001582 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001583 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001584 }
1585
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001586 public BitDescription(int mask, int shift, String name, String shortName,
1587 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001588 this.mask = mask;
1589 this.shift = shift;
1590 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001591 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001592 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001593 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001594 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001595 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001596
Dianne Hackbornfc064132014-06-02 12:42:12 -07001597 /**
1598 * Don't allow any more batching in to the current history event. This
1599 * is called when printing partial histories, so to ensure that the next
1600 * history event will go in to a new batch after what was printed in the
1601 * last partial history.
1602 */
1603 public abstract void commitCurrentHistoryBatchLocked();
1604
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001605 public abstract int getHistoryTotalSize();
1606
1607 public abstract int getHistoryUsedSize();
1608
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001609 public abstract boolean startIteratingHistoryLocked();
1610
Dianne Hackborn099bc622014-01-22 13:39:16 -08001611 public abstract int getHistoryStringPoolSize();
1612
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001613 public abstract int getHistoryStringPoolBytes();
1614
1615 public abstract String getHistoryTagPoolString(int index);
1616
1617 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001618
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001619 public abstract boolean getNextHistoryLocked(HistoryItem out);
1620
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001621 public abstract void finishIteratingHistoryLocked();
1622
1623 public abstract boolean startIteratingOldHistoryLocked();
1624
1625 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1626
1627 public abstract void finishIteratingOldHistoryLocked();
1628
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001630 * Return the base time offset for the battery history.
1631 */
1632 public abstract long getHistoryBaseTime();
1633
1634 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 * Returns the number of times the device has been started.
1636 */
1637 public abstract int getStartCount();
1638
1639 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001640 * 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 -08001641 * running on battery.
1642 *
1643 * {@hide}
1644 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001645 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001647 /**
1648 * Returns the number of times the screen was turned on.
1649 *
1650 * {@hide}
1651 */
1652 public abstract int getScreenOnCount(int which);
1653
Jeff Browne95c3cd2014-05-02 16:59:26 -07001654 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1655
Dianne Hackborn617f8772009-03-31 15:04:46 -07001656 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1657 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1658 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1659 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1660 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1661
1662 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1663 "dark", "dim", "medium", "light", "bright"
1664 };
1665
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001666 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1667 "0", "1", "2", "3", "4"
1668 };
1669
Dianne Hackborn617f8772009-03-31 15:04:46 -07001670 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001671
Dianne Hackborn617f8772009-03-31 15:04:46 -07001672 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001673 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001674 * the given brightness
1675 *
1676 * {@hide}
1677 */
1678 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001679 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001682 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001683 * running on battery.
1684 *
1685 * {@hide}
1686 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001687 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001688
1689 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001690 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001691 *
1692 * {@hide}
1693 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001694 public abstract int getPowerSaveModeEnabledCount(int which);
1695
1696 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001697 * Constant for device idle mode: not active.
1698 */
1699 public static final int DEVICE_IDLE_MODE_OFF = 0;
1700
1701 /**
1702 * Constant for device idle mode: active in lightweight mode.
1703 */
1704 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1705
1706 /**
1707 * Constant for device idle mode: active in full mode.
1708 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001709 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001710
1711 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001712 * Returns the time in microseconds that device has been in idle mode while
1713 * running on battery.
1714 *
1715 * {@hide}
1716 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001717 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001718
1719 /**
1720 * Returns the number of times that the devie has gone in to idle mode.
1721 *
1722 * {@hide}
1723 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001724 public abstract int getDeviceIdleModeCount(int mode, int which);
1725
1726 /**
1727 * Return the longest duration we spent in a particular device idle mode (fully in the
1728 * mode, not in idle maintenance etc).
1729 */
1730 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001731
1732 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001733 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001734 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001735 * counts all of the time that we consider the device to be idle, whether or not
1736 * it is currently in the actual device idle mode.
1737 *
1738 * {@hide}
1739 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001740 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001741
1742 /**
1743 * Returns the number of times that the devie has started idling.
1744 *
1745 * {@hide}
1746 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001747 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001748
1749 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001750 * Returns the number of times that connectivity state changed.
1751 *
1752 * {@hide}
1753 */
1754 public abstract int getNumConnectivityChange(int which);
1755
1756 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001757 * 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 -08001758 * running on battery.
1759 *
1760 * {@hide}
1761 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001762 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001763
1764 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001765 * Returns the number of times a phone call was activated.
1766 *
1767 * {@hide}
1768 */
1769 public abstract int getPhoneOnCount(int which);
1770
1771 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001772 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001773 * the given signal strength.
1774 *
1775 * {@hide}
1776 */
1777 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001778 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001779
Dianne Hackborn617f8772009-03-31 15:04:46 -07001780 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001781 * Returns the time in microseconds that the phone has been trying to
1782 * acquire a signal.
1783 *
1784 * {@hide}
1785 */
1786 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001787 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001788
1789 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001790 * Returns the number of times the phone has entered the given signal strength.
1791 *
1792 * {@hide}
1793 */
1794 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1795
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001796 /**
1797 * Returns the time in microseconds that the mobile network has been active
1798 * (in a high power state).
1799 *
1800 * {@hide}
1801 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001802 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001803
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001804 /**
1805 * Returns the number of times that the mobile network has transitioned to the
1806 * active state.
1807 *
1808 * {@hide}
1809 */
1810 public abstract int getMobileRadioActiveCount(int which);
1811
1812 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001813 * Returns the time in microseconds that is the difference between the mobile radio
1814 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1815 * from the radio.
1816 *
1817 * {@hide}
1818 */
1819 public abstract long getMobileRadioActiveAdjustedTime(int which);
1820
1821 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001822 * Returns the time in microseconds that the mobile network has been active
1823 * (in a high power state) but not being able to blame on an app.
1824 *
1825 * {@hide}
1826 */
1827 public abstract long getMobileRadioActiveUnknownTime(int which);
1828
1829 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001830 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001831 *
1832 * {@hide}
1833 */
1834 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001835
Dianne Hackborn627bba72009-03-24 22:32:56 -07001836 public static final int DATA_CONNECTION_NONE = 0;
1837 public static final int DATA_CONNECTION_GPRS = 1;
1838 public static final int DATA_CONNECTION_EDGE = 2;
1839 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001840 public static final int DATA_CONNECTION_CDMA = 4;
1841 public static final int DATA_CONNECTION_EVDO_0 = 5;
1842 public static final int DATA_CONNECTION_EVDO_A = 6;
1843 public static final int DATA_CONNECTION_1xRTT = 7;
1844 public static final int DATA_CONNECTION_HSDPA = 8;
1845 public static final int DATA_CONNECTION_HSUPA = 9;
1846 public static final int DATA_CONNECTION_HSPA = 10;
1847 public static final int DATA_CONNECTION_IDEN = 11;
1848 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001849 public static final int DATA_CONNECTION_LTE = 13;
1850 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001851 public static final int DATA_CONNECTION_HSPAP = 15;
1852 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001853
Dianne Hackborn627bba72009-03-24 22:32:56 -07001854 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001855 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001856 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001857 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001858 };
1859
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001860 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001861
1862 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001863 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001864 * the given data connection.
1865 *
1866 * {@hide}
1867 */
1868 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001869 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001871 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001872 * Returns the number of times the phone has entered the given data
1873 * connection type.
1874 *
1875 * {@hide}
1876 */
1877 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001878
Dianne Hackborn3251b902014-06-20 14:40:53 -07001879 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1880 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1881 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1882 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1883 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1884 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1885 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1886 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1887 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1888 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1889 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1890 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1891 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1892
1893 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1894
1895 static final String[] WIFI_SUPPL_STATE_NAMES = {
1896 "invalid", "disconn", "disabled", "inactive", "scanning",
1897 "authenticating", "associating", "associated", "4-way-handshake",
1898 "group-handshake", "completed", "dormant", "uninit"
1899 };
1900
1901 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1902 "inv", "dsc", "dis", "inact", "scan",
1903 "auth", "ascing", "asced", "4-way",
1904 "group", "compl", "dorm", "uninit"
1905 };
1906
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001907 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1908 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001909 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001910 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1911 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001912 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001913 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1914 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1915 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001916 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001917 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001918 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001919 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001920 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1921 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001922 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1923 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1924 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1925 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1926 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1927 new String[] {"in", "out", "emergency", "off"},
1928 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001929 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1930 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1931 SignalStrength.SIGNAL_STRENGTH_NAMES,
1932 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001933 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1934 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1935 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001936 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001937
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001938 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1939 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001940 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001941 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001942 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001943 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001944 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001945 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
1946 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
1947 new String[] { "off", "light", "full", "???" },
1948 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001949 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
1950 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
1951 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001952 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1953 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1954 new String[] { "0", "1", "2", "3", "4" },
1955 new String[] { "0", "1", "2", "3", "4" }),
1956 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1957 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1958 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07001959 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001960 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001961 };
1962
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001963 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001964 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001965 "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active", "tmpwhitelist",
1966 "screenwake",
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001967 };
1968
1969 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001970 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001971 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
1972 "Esw",
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001973 };
1974
Dianne Hackborn617f8772009-03-31 15:04:46 -07001975 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001976 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001977 * running on battery.
1978 *
1979 * {@hide}
1980 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001981 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001982
1983 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001984 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001985 * been in the running state while the device was running on battery.
1986 *
1987 * {@hide}
1988 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001989 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001990
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001991 public static final int WIFI_STATE_OFF = 0;
1992 public static final int WIFI_STATE_OFF_SCANNING = 1;
1993 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
1994 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
1995 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
1996 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
1997 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
1998 public static final int WIFI_STATE_SOFT_AP = 7;
1999
2000 static final String[] WIFI_STATE_NAMES = {
2001 "off", "scanning", "no_net", "disconn",
2002 "sta", "p2p", "sta_p2p", "soft_ap"
2003 };
2004
2005 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2006
2007 /**
2008 * Returns the time in microseconds that WiFi has been running in the given state.
2009 *
2010 * {@hide}
2011 */
2012 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002013 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002014
2015 /**
2016 * Returns the number of times that WiFi has entered the given state.
2017 *
2018 * {@hide}
2019 */
2020 public abstract int getWifiStateCount(int wifiState, int which);
2021
The Android Open Source Project10592532009-03-18 17:39:46 -07002022 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002023 * Returns the time in microseconds that the wifi supplicant has been
2024 * in a given state.
2025 *
2026 * {@hide}
2027 */
2028 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2029
2030 /**
2031 * Returns the number of times that the wifi supplicant has transitioned
2032 * to a given state.
2033 *
2034 * {@hide}
2035 */
2036 public abstract int getWifiSupplStateCount(int state, int which);
2037
2038 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2039
2040 /**
2041 * Returns the time in microseconds that WIFI has been running with
2042 * the given signal strength.
2043 *
2044 * {@hide}
2045 */
2046 public abstract long getWifiSignalStrengthTime(int strengthBin,
2047 long elapsedRealtimeUs, int which);
2048
2049 /**
2050 * Returns the number of times WIFI has entered the given signal strength.
2051 *
2052 * {@hide}
2053 */
2054 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2055
2056 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002057 * Returns the time in microseconds that the flashlight has been on while the device was
2058 * running on battery.
2059 *
2060 * {@hide}
2061 */
2062 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2063
2064 /**
2065 * Returns the number of times that the flashlight has been turned on while the device was
2066 * running on battery.
2067 *
2068 * {@hide}
2069 */
2070 public abstract long getFlashlightOnCount(int which);
2071
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002072 /**
2073 * Returns the time in microseconds that the camera has been on while the device was
2074 * running on battery.
2075 *
2076 * {@hide}
2077 */
2078 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2079
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002080 /**
2081 * Returns the time in microseconds that bluetooth scans were running while the device was
2082 * on battery.
2083 *
2084 * {@hide}
2085 */
2086 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002087
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002088 public static final int NETWORK_MOBILE_RX_DATA = 0;
2089 public static final int NETWORK_MOBILE_TX_DATA = 1;
2090 public static final int NETWORK_WIFI_RX_DATA = 2;
2091 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002092 public static final int NETWORK_BT_RX_DATA = 4;
2093 public static final int NETWORK_BT_TX_DATA = 5;
2094 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_BT_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002095
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002096 public abstract long getNetworkActivityBytes(int type, int which);
2097 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002098
Adam Lesinskie08af192015-03-25 16:42:59 -07002099 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002100 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002101 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002102 * actual power data.
2103 */
2104 public abstract boolean hasWifiActivityReporting();
2105
2106 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002107 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2108 * in various radio controller states, such as transmit, receive, and idle.
2109 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002110 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002111 public abstract ControllerActivityCounter getWifiControllerActivity();
2112
2113 /**
2114 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2115 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2116 * actual power data.
2117 */
2118 public abstract boolean hasBluetoothActivityReporting();
2119
2120 /**
2121 * 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}
2124 */
2125 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2126
2127 /**
2128 * Returns true if the BatteryStats object has detailed modem power reports.
2129 * When true, calling {@link #getModemControllerActivity()} will yield the
2130 * actual power data.
2131 */
2132 public abstract boolean hasModemActivityReporting();
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 getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002140
The Android Open Source Project10592532009-03-18 17:39:46 -07002141 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002142 * Return the wall clock time when battery stats data collection started.
2143 */
2144 public abstract long getStartClockTime();
2145
2146 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002147 * Return platform version tag that we were running in when the battery stats started.
2148 */
2149 public abstract String getStartPlatformVersion();
2150
2151 /**
2152 * Return platform version tag that we were running in when the battery stats ended.
2153 */
2154 public abstract String getEndPlatformVersion();
2155
2156 /**
2157 * Return the internal version code of the parcelled format.
2158 */
2159 public abstract int getParcelVersion();
2160
2161 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 * Return whether we are currently running on battery.
2163 */
2164 public abstract boolean getIsOnBattery();
2165
2166 /**
2167 * Returns a SparseArray containing the statistics for each uid.
2168 */
2169 public abstract SparseArray<? extends Uid> getUidStats();
2170
2171 /**
2172 * Returns the current battery uptime in microseconds.
2173 *
2174 * @param curTime the amount of elapsed realtime in microseconds.
2175 */
2176 public abstract long getBatteryUptime(long curTime);
2177
2178 /**
2179 * Returns the current battery realtime in microseconds.
2180 *
2181 * @param curTime the amount of elapsed realtime in microseconds.
2182 */
2183 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07002184
2185 /**
Evan Millar633a1742009-04-02 16:36:33 -07002186 * Returns the battery percentage level at the last time the device was unplugged from power, or
2187 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002188 */
Evan Millar633a1742009-04-02 16:36:33 -07002189 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07002190
2191 /**
Evan Millar633a1742009-04-02 16:36:33 -07002192 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2193 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002194 */
Evan Millar633a1742009-04-02 16:36:33 -07002195 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196
2197 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002198 * Get the amount the battery has discharged since the stats were
2199 * last reset after charging, as a lower-end approximation.
2200 */
2201 public abstract int getLowDischargeAmountSinceCharge();
2202
2203 /**
2204 * Get the amount the battery has discharged since the stats were
2205 * last reset after charging, as an upper-end approximation.
2206 */
2207 public abstract int getHighDischargeAmountSinceCharge();
2208
2209 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002210 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2211 */
2212 public abstract int getDischargeAmount(int which);
2213
2214 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002215 * Get the amount the battery has discharged while the screen was on,
2216 * since the last time power was unplugged.
2217 */
2218 public abstract int getDischargeAmountScreenOn();
2219
2220 /**
2221 * Get the amount the battery has discharged while the screen was on,
2222 * since the last time the device was charged.
2223 */
2224 public abstract int getDischargeAmountScreenOnSinceCharge();
2225
2226 /**
2227 * Get the amount the battery has discharged while the screen was off,
2228 * since the last time power was unplugged.
2229 */
2230 public abstract int getDischargeAmountScreenOff();
2231
2232 /**
2233 * Get the amount the battery has discharged while the screen was off,
2234 * since the last time the device was charged.
2235 */
2236 public abstract int getDischargeAmountScreenOffSinceCharge();
2237
2238 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 * Returns the total, last, or current battery uptime in microseconds.
2240 *
2241 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002242 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002243 */
2244 public abstract long computeBatteryUptime(long curTime, int which);
2245
2246 /**
2247 * Returns the total, last, or current battery realtime in microseconds.
2248 *
2249 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002250 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 */
2252 public abstract long computeBatteryRealtime(long curTime, int which);
2253
2254 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002255 * Returns the total, last, or current battery screen off uptime in microseconds.
2256 *
2257 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002258 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002259 */
2260 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2261
2262 /**
2263 * Returns the total, last, or current battery screen off realtime in microseconds.
2264 *
2265 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002266 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002267 */
2268 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2269
2270 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 * Returns the total, last, or current uptime in microseconds.
2272 *
2273 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002274 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 */
2276 public abstract long computeUptime(long curTime, int which);
2277
2278 /**
2279 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002280 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002282 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 */
2284 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002285
2286 /**
2287 * Compute an approximation for how much run time (in microseconds) is remaining on
2288 * the battery. Returns -1 if no time can be computed: either there is not
2289 * enough current data to make a decision, or the battery is currently
2290 * charging.
2291 *
2292 * @param curTime The current elepsed realtime in microseconds.
2293 */
2294 public abstract long computeBatteryTimeRemaining(long curTime);
2295
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002296 // The part of a step duration that is the actual time.
2297 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2298
2299 // Bits in a step duration that are the new battery level we are at.
2300 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002301 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002302
2303 // Bits in a step duration that are the initial mode we were in at that step.
2304 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002305 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002306
2307 // Bits in a step duration that indicate which modes changed during that step.
2308 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002309 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002310
2311 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2312 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2313
2314 // Step duration mode: power save is on.
2315 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2316
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002317 // Step duration mode: device is currently in idle mode.
2318 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2319
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002320 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2321 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002322 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2323 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002324 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2325 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2326 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2327 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2328 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002329 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2330 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002331 };
2332 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2333 (Display.STATE_OFF-1),
2334 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002335 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002336 (Display.STATE_ON-1),
2337 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2338 (Display.STATE_DOZE-1),
2339 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2340 (Display.STATE_DOZE_SUSPEND-1),
2341 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002342 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002343 };
2344 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2345 "screen off",
2346 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002347 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002348 "screen on",
2349 "screen on power save",
2350 "screen doze",
2351 "screen doze power save",
2352 "screen doze-suspend",
2353 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002354 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002355 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002356
2357 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002358 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002359 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002360 public abstract LevelStepTracker getDischargeLevelStepTracker();
2361
2362 /**
2363 * Return the array of daily discharge step durations.
2364 */
2365 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002366
2367 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002368 * Compute an approximation for how much time (in microseconds) remains until the battery
2369 * is fully charged. Returns -1 if no time can be computed: either there is not
2370 * enough current data to make a decision, or the battery is currently
2371 * discharging.
2372 *
2373 * @param curTime The current elepsed realtime in microseconds.
2374 */
2375 public abstract long computeChargeTimeRemaining(long curTime);
2376
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002377 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002378 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002379 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002380 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002381
2382 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002383 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002384 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002385 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002386
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002387 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2388
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002389 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002390
Evan Millarc64edde2009-04-18 12:26:32 -07002391 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002393 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2394
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002395 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 long days = seconds / (60 * 60 * 24);
2397 if (days != 0) {
2398 out.append(days);
2399 out.append("d ");
2400 }
2401 long used = days * 60 * 60 * 24;
2402
2403 long hours = (seconds - used) / (60 * 60);
2404 if (hours != 0 || used != 0) {
2405 out.append(hours);
2406 out.append("h ");
2407 }
2408 used += hours * 60 * 60;
2409
2410 long mins = (seconds-used) / 60;
2411 if (mins != 0 || used != 0) {
2412 out.append(mins);
2413 out.append("m ");
2414 }
2415 used += mins * 60;
2416
2417 if (seconds != 0 || used != 0) {
2418 out.append(seconds-used);
2419 out.append("s ");
2420 }
2421 }
2422
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002423 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002425 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 sb.append(time - (sec * 1000));
2427 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 }
2429
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002430 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002431 long sec = time / 1000;
2432 formatTimeRaw(sb, sec);
2433 sb.append(time - (sec * 1000));
2434 sb.append("ms");
2435 }
2436
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002437 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002438 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002439 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 }
2441 float perc = ((float)num) / ((float)den) * 100;
2442 mFormatBuilder.setLength(0);
2443 mFormatter.format("%.1f%%", perc);
2444 return mFormatBuilder.toString();
2445 }
2446
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002447 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002448 mFormatBuilder.setLength(0);
2449
2450 if (bytes < BYTES_PER_KB) {
2451 return bytes + "B";
2452 } else if (bytes < BYTES_PER_MB) {
2453 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2454 return mFormatBuilder.toString();
2455 } else if (bytes < BYTES_PER_GB){
2456 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2457 return mFormatBuilder.toString();
2458 } else {
2459 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2460 return mFormatBuilder.toString();
2461 }
2462 }
2463
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002464 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002465 if (timer != null) {
2466 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002467 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002468 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2469 return totalTimeMillis;
2470 }
2471 return 0;
2472 }
2473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002474 /**
2475 *
2476 * @param sb a StringBuilder object.
2477 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002478 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002480 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002481 * @param linePrefix a String to be prepended to each line of output.
2482 * @return the line prefix
2483 */
2484 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002485 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002486
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002488 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002489
Evan Millarc64edde2009-04-18 12:26:32 -07002490 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 if (totalTimeMillis != 0) {
2492 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002493 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002494 if (name != null) {
2495 sb.append(name);
2496 sb.append(' ');
2497 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002498 sb.append('(');
2499 sb.append(count);
2500 sb.append(" times)");
2501 return ", ";
2502 }
2503 }
2504 return linePrefix;
2505 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002506
2507 /**
2508 *
2509 * @param pw a PrintWriter object to print to.
2510 * @param sb a StringBuilder object.
2511 * @param timer a Timer object contining the wakelock times.
2512 * @param rawRealtime the current on-battery time in microseconds.
2513 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2514 * @param prefix a String to be prepended to each line of output.
2515 * @param type the name of the timer.
2516 */
2517 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
2518 long rawRealtime, int which, String prefix, String type) {
2519 if (timer != null) {
2520 // Convert from microseconds to milliseconds with rounding
2521 final long totalTime = (timer.getTotalTimeLocked(
2522 rawRealtime, which) + 500) / 1000;
2523 final int count = timer.getCountLocked(which);
2524 if (totalTime != 0) {
2525 sb.setLength(0);
2526 sb.append(prefix);
2527 sb.append(" ");
2528 sb.append(type);
2529 sb.append(": ");
2530 formatTimeMs(sb, totalTime);
2531 sb.append("realtime (");
2532 sb.append(count);
2533 sb.append(" times)");
2534 pw.println(sb.toString());
2535 return true;
2536 }
2537 }
2538 return false;
2539 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540
2541 /**
2542 * Checkin version of wakelock printer. Prints simple comma-separated list.
2543 *
2544 * @param sb a StringBuilder object.
2545 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002546 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002548 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002549 * @param linePrefix a String to be prepended to each line of output.
2550 * @return the line prefix
2551 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002552 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2553 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 long totalTimeMicros = 0;
2555 int count = 0;
2556 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002557 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002558 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 }
2560 sb.append(linePrefix);
2561 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2562 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002563 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 sb.append(count);
2565 return ",";
2566 }
2567
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002568 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2569 String type) {
2570 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2571 pw.print(',');
2572 pw.print(uid);
2573 pw.print(',');
2574 pw.print(category);
2575 pw.print(',');
2576 pw.print(type);
2577 }
2578
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 /**
2580 * Dump a comma-separated line of values for terse checkin mode.
2581 *
2582 * @param pw the PageWriter to dump log to
2583 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2584 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2585 * @param args type-dependent data arguments
2586 */
2587 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2588 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002589 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002590 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002591 pw.print(',');
2592 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002594 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002596
2597 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002598 * Dump a given timer stat for terse checkin mode.
2599 *
2600 * @param pw the PageWriter to dump log to
2601 * @param uid the UID to log
2602 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2603 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2604 * @param timer a {@link Timer} to dump stats for
2605 * @param rawRealtime the current elapsed realtime of the system in microseconds
2606 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2607 */
2608 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2609 Timer timer, long rawRealtime, int which) {
2610 if (timer != null) {
2611 // Convert from microseconds to milliseconds with rounding
2612 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2613 / 1000;
2614 final int count = timer.getCountLocked(which);
2615 if (totalTime != 0) {
2616 dumpLine(pw, uid, category, type, totalTime, count);
2617 }
2618 }
2619 }
2620
2621 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002622 * Checks if the ControllerActivityCounter has any data worth dumping.
2623 */
2624 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2625 if (counter == null) {
2626 return false;
2627 }
2628
2629 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2630 || counter.getRxTimeCounter().getCountLocked(which) != 0
2631 || counter.getPowerCounter().getCountLocked(which) != 0) {
2632 return true;
2633 }
2634
2635 for (LongCounter c : counter.getTxTimeCounters()) {
2636 if (c.getCountLocked(which) != 0) {
2637 return true;
2638 }
2639 }
2640 return false;
2641 }
2642
2643 /**
2644 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2645 * The order of the arguments in the final check in line is:
2646 *
2647 * idle, rx, power, tx...
2648 *
2649 * where tx... is one or more transmit level times.
2650 */
2651 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2652 String type,
2653 ControllerActivityCounter counter,
2654 int which) {
2655 if (!controllerActivityHasData(counter, which)) {
2656 return;
2657 }
2658
2659 dumpLineHeader(pw, uid, category, type);
2660 pw.print(",");
2661 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2662 pw.print(",");
2663 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2664 pw.print(",");
2665 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2666 for (LongCounter c : counter.getTxTimeCounters()) {
2667 pw.print(",");
2668 pw.print(c.getCountLocked(which));
2669 }
2670 pw.println();
2671 }
2672
2673 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2674 String prefix, String controllerName,
2675 ControllerActivityCounter counter,
2676 int which) {
2677 if (controllerActivityHasData(counter, which)) {
2678 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2679 }
2680 }
2681
2682 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2683 String controllerName,
2684 ControllerActivityCounter counter, int which) {
2685 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2686 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2687 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2688 long totalTxTimeMs = 0;
2689 for (LongCounter txState : counter.getTxTimeCounters()) {
2690 totalTxTimeMs += txState.getCountLocked(which);
2691 }
2692
2693 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2694
2695 sb.setLength(0);
2696 sb.append(prefix);
2697 sb.append(" ");
2698 sb.append(controllerName);
2699 sb.append(" Idle time: ");
2700 formatTimeMs(sb, idleTimeMs);
2701 sb.append("(");
2702 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2703 sb.append(")");
2704 pw.println(sb.toString());
2705
2706 sb.setLength(0);
2707 sb.append(prefix);
2708 sb.append(" ");
2709 sb.append(controllerName);
2710 sb.append(" Rx time: ");
2711 formatTimeMs(sb, rxTimeMs);
2712 sb.append("(");
2713 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
2714 sb.append(")");
2715 pw.println(sb.toString());
2716
2717 sb.setLength(0);
2718 sb.append(prefix);
2719 sb.append(" ");
2720 sb.append(controllerName);
2721 sb.append(" Tx time: ");
2722 formatTimeMs(sb, totalTxTimeMs);
2723 sb.append("(");
2724 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
2725 sb.append(")");
2726 pw.println(sb.toString());
2727
2728 final int numTxLvls = counter.getTxTimeCounters().length;
2729 if (numTxLvls > 1) {
2730 for (int lvl = 0; lvl < numTxLvls; lvl++) {
2731 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
2732 sb.setLength(0);
2733 sb.append(prefix);
2734 sb.append(" [");
2735 sb.append(lvl);
2736 sb.append("] ");
2737 formatTimeMs(sb, txLvlTimeMs);
2738 sb.append("(");
2739 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
2740 sb.append(")");
2741 pw.println(sb.toString());
2742 }
2743 }
2744
2745 sb.setLength(0);
2746 sb.append(prefix);
2747 sb.append(" ");
2748 sb.append(controllerName);
2749 sb.append(" Power drain: ").append(
2750 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
2751 sb.append("mAh");
2752 pw.println(sb.toString());
2753 }
2754
2755 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07002756 * Temporary for settings.
2757 */
2758 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2759 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2760 }
2761
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 /**
2763 * Checkin server version of dump to produce more compact, computer-readable log.
2764 *
2765 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002767 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2768 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002769 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2770 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2771 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002772 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2773 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002774 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2775 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2776 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 final long totalRealtime = computeRealtime(rawRealtime, which);
2778 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002779 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002780 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002781 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002782 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
2783 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002784 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002785 rawRealtime, which);
2786 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
2787 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002788 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002789 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002790 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002791 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002792
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002793 final StringBuilder sb = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002795 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07002796 final int NU = uidStats.size();
2797
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002798 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 // Dump "battery" stat
2801 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002802 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002803 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002804 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002805 getStartClockTime(),
2806 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002808 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002809 long fullWakeLockTimeTotal = 0;
2810 long partialWakeLockTimeTotal = 0;
2811
2812 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002813 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002814
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002815 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
2816 = u.getWakelockStats();
2817 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2818 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07002819
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002820 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2821 if (fullWakeTimer != null) {
2822 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2823 which);
2824 }
2825
2826 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2827 if (partialWakeTimer != null) {
2828 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
2829 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002830 }
2831 }
2832 }
Adam Lesinskie283d332015-04-16 12:29:25 -07002833
2834 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002835 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2836 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2837 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2838 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2839 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2840 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2841 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2842 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002843 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
2844 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002845 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2846 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002847 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
2848 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002849
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002850 // Dump Modem controller stats
2851 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
2852 getModemControllerActivity(), which);
2853
Adam Lesinskie283d332015-04-16 12:29:25 -07002854 // Dump Wifi controller stats
2855 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2856 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002857 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08002858 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002859
2860 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
2861 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002862
2863 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002864 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
2865 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07002866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002867 // Dump misc stats
2868 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07002869 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002870 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07002871 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002872 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002873 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002874 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
2875 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07002876 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002877 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
2878 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
2879 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
2880 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07002881 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002882
2883 // Dump screen brightness stats
2884 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2885 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002886 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002887 }
2888 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002889
Dianne Hackborn627bba72009-03-24 22:32:56 -07002890 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002891 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2892 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002893 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002894 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002895 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002896 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002897 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002898 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002899 args[i] = getPhoneSignalStrengthCount(i, which);
2900 }
2901 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002902
Dianne Hackborn627bba72009-03-24 22:32:56 -07002903 // Dump network type stats
2904 args = new Object[NUM_DATA_CONNECTION_TYPES];
2905 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002906 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002907 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002908 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2909 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2910 args[i] = getPhoneDataConnectionCount(i, which);
2911 }
2912 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002913
2914 // Dump wifi state stats
2915 args = new Object[NUM_WIFI_STATES];
2916 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002917 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002918 }
2919 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2920 for (int i=0; i<NUM_WIFI_STATES; i++) {
2921 args[i] = getWifiStateCount(i, which);
2922 }
2923 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2924
Dianne Hackborn3251b902014-06-20 14:40:53 -07002925 // Dump wifi suppl state stats
2926 args = new Object[NUM_WIFI_SUPPL_STATES];
2927 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2928 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2929 }
2930 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2931 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2932 args[i] = getWifiSupplStateCount(i, which);
2933 }
2934 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
2935
2936 // Dump wifi signal strength stats
2937 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
2938 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2939 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
2940 }
2941 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
2942 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2943 args[i] = getWifiSignalStrengthCount(i, which);
2944 }
2945 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
2946
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002947 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002948 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07002949 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002950 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002951
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002952 if (which == STATS_SINCE_UNPLUGGED) {
2953 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2954 getDischargeStartLevel()-getDischargeCurrentLevel(),
2955 getDischargeStartLevel()-getDischargeCurrentLevel(),
2956 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
2957 } else {
2958 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2959 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002960 getDischargeAmountScreenOnSinceCharge(),
2961 getDischargeAmountScreenOffSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002962 }
2963
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002964 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002965 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002966 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002967 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002968 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002969 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002970 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002971 sb.toString());
2972 }
Evan Millarc64edde2009-04-18 12:26:32 -07002973 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002974 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002975 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002976 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
2977 // Not doing the regular wake lock formatting to remain compatible
2978 // with the old checkin format.
2979 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
2980 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002981 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002982 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002983 }
2984 }
Evan Millarc64edde2009-04-18 12:26:32 -07002985 }
2986
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002987 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002988 helper.create(this);
2989 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002990 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002991 if (sippers != null && sippers.size() > 0) {
2992 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
2993 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08002994 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002995 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
2996 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
2997 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002998 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002999 int uid = 0;
3000 String label;
3001 switch (bs.drainType) {
3002 case IDLE:
3003 label="idle";
3004 break;
3005 case CELL:
3006 label="cell";
3007 break;
3008 case PHONE:
3009 label="phone";
3010 break;
3011 case WIFI:
3012 label="wifi";
3013 break;
3014 case BLUETOOTH:
3015 label="blue";
3016 break;
3017 case SCREEN:
3018 label="scrn";
3019 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003020 case FLASHLIGHT:
3021 label="flashlight";
3022 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003023 case APP:
3024 uid = bs.uidObj.getUid();
3025 label = "uid";
3026 break;
3027 case USER:
3028 uid = UserHandle.getUid(bs.userId, 0);
3029 label = "user";
3030 break;
3031 case UNACCOUNTED:
3032 label = "unacc";
3033 break;
3034 case OVERCOUNTED:
3035 label = "over";
3036 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003037 case CAMERA:
3038 label = "camera";
3039 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003040 default:
3041 label = "???";
3042 }
3043 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07003044 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003045 }
3046 }
3047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003048 for (int iu = 0; iu < NU; iu++) {
3049 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003050 if (reqUid >= 0 && uid != reqUid) {
3051 continue;
3052 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003053 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003055 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003056 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3057 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3058 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3059 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3060 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3061 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3062 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3063 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
3064 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3065 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003066 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3067 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003068 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3069 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003070 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
3071 || btBytesRx > 0 || btBytesTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003072 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3073 wifiBytesRx, wifiBytesTx,
3074 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003075 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003076 mobileActiveTime, mobileActiveCount,
3077 btBytesRx, btBytesTx);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003078 }
3079
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003080 // Dump modem controller data, per UID.
3081 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3082 u.getModemControllerActivity(), which);
3083
3084 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003085 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3086 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3087 final int wifiScanCount = u.getWifiScanCount(which);
3088 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003089 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003090 || uidWifiRunningTime != 0) {
3091 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3092 uidWifiRunningTime, wifiScanCount,
3093 /* legacy fields follow, keep at 0 */ 0, 0, 0, 0);
The Android Open Source Project10592532009-03-18 17:39:46 -07003094 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003095
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003096 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3097 u.getWifiControllerActivity(), which);
3098
Adam Lesinskiba9d8932016-04-12 12:06:03 -07003099 dumpTimer(pw, uid, category, BLUETOOTH_MISC_DATA, u.getBluetoothScanTimer(),
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003100 rawRealtime, which);
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003101
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003102 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3103 u.getBluetoothControllerActivity(), which);
3104
Dianne Hackborn617f8772009-03-31 15:04:46 -07003105 if (u.hasUserActivity()) {
3106 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3107 boolean hasData = false;
3108 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3109 int val = u.getUserActivityCount(i, which);
3110 args[i] = val;
3111 if (val != 0) hasData = true;
3112 }
3113 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003114 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003115 }
3116 }
3117
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003118 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3119 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3120 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3121 String linePrefix = "";
3122 sb.setLength(0);
3123 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3124 rawRealtime, "f", which, linePrefix);
3125 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
3126 rawRealtime, "p", which, linePrefix);
3127 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3128 rawRealtime, "w", which, linePrefix);
3129
3130 // Only log if we had at lease one wakelock...
3131 if (sb.length() > 0) {
3132 String name = wakelocks.keyAt(iw);
3133 if (name.indexOf(',') >= 0) {
3134 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003136 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003137 }
3138 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003139
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003140 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3141 for (int isy=syncs.size()-1; isy>=0; isy--) {
3142 final Timer timer = syncs.valueAt(isy);
3143 // Convert from microseconds to milliseconds with rounding
3144 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3145 final int count = timer.getCountLocked(which);
3146 if (totalTime != 0) {
3147 dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003148 }
3149 }
3150
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003151 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3152 for (int ij=jobs.size()-1; ij>=0; ij--) {
3153 final Timer timer = jobs.valueAt(ij);
3154 // Convert from microseconds to milliseconds with rounding
3155 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3156 final int count = timer.getCountLocked(which);
3157 if (totalTime != 0) {
3158 dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003159 }
3160 }
3161
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003162 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3163 rawRealtime, which);
3164 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3165 rawRealtime, which);
3166 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3167 rawRealtime, which);
3168 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3169 rawRealtime, which);
3170
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003171 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3172 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003173 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003174 final Uid.Sensor se = sensors.valueAt(ise);
3175 final int sensorNumber = sensors.keyAt(ise);
3176 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003177 if (timer != null) {
3178 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003179 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3180 / 1000;
3181 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003182 if (totalTime != 0) {
3183 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
3184 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 }
3186 }
3187
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003188 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3189 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003190
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003191 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3192 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003193
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003194 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003195 long totalStateTime = 0;
3196 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003197 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3198 totalStateTime += time;
3199 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003200 }
3201 if (totalStateTime > 0) {
3202 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3203 }
3204
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003205 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3206 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
3207 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
3208 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
3209 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
3210 powerCpuMaUs / 1000);
3211 }
3212
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003213 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3214 = u.getProcessStats();
3215 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3216 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003217
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003218 final long userMillis = ps.getUserTime(which);
3219 final long systemMillis = ps.getSystemTime(which);
3220 final long foregroundMillis = ps.getForegroundTime(which);
3221 final int starts = ps.getStarts(which);
3222 final int numCrashes = ps.getNumCrashes(which);
3223 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003224
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003225 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3226 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
3227 dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis,
3228 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 }
3230 }
3231
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003232 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3233 = u.getPackageStats();
3234 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3235 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3236 int wakeups = 0;
3237 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3238 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
3239 wakeups += alarms.valueAt(iwa).getCountLocked(which);
3240 }
3241 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3242 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3243 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3244 final long startTime = ss.getStartTime(batteryUptime, which);
3245 final int starts = ss.getStarts(which);
3246 final int launches = ss.getLaunches(which);
3247 if (startTime != 0 || starts != 0 || launches != 0) {
3248 dumpLine(pw, uid, category, APK_DATA,
3249 wakeups, // wakeup alarms
3250 packageStats.keyAt(ipkg), // Apk
3251 serviceStats.keyAt(isvc), // service
3252 startTime / 1000, // time spent started, in ms
3253 starts,
3254 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255 }
3256 }
3257 }
3258 }
3259 }
3260
Dianne Hackborn81038902012-11-26 17:04:09 -08003261 static final class TimerEntry {
3262 final String mName;
3263 final int mId;
3264 final BatteryStats.Timer mTimer;
3265 final long mTime;
3266 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3267 mName = name;
3268 mId = id;
3269 mTimer = timer;
3270 mTime = time;
3271 }
3272 }
3273
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003274 private void printmAh(PrintWriter printer, double power) {
3275 printer.print(BatteryStatsHelper.makemAh(power));
3276 }
3277
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003278 private void printmAh(StringBuilder sb, double power) {
3279 sb.append(BatteryStatsHelper.makemAh(power));
3280 }
3281
Dianne Hackbornd953c532014-08-16 18:17:38 -07003282 /**
3283 * Temporary for settings.
3284 */
3285 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3286 int reqUid) {
3287 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3288 }
3289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003290 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003291 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003292 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3294 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3295 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296
3297 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3298 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3299 final long totalRealtime = computeRealtime(rawRealtime, which);
3300 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003301 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3302 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3303 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003304 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3305 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003306
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003307 final StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07003308
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003309 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003310 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003312 sb.setLength(0);
3313 sb.append(prefix);
3314 sb.append(" Time on battery: ");
3315 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3316 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3317 sb.append(") realtime, ");
3318 formatTimeMs(sb, whichBatteryUptime / 1000);
3319 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3320 sb.append(") uptime");
3321 pw.println(sb.toString());
3322 sb.setLength(0);
3323 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003324 sb.append(" Time on battery screen off: ");
3325 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3326 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3327 sb.append(") realtime, ");
3328 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3329 sb.append("(");
3330 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3331 sb.append(") uptime");
3332 pw.println(sb.toString());
3333 sb.setLength(0);
3334 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003335 sb.append(" Total run time: ");
3336 formatTimeMs(sb, totalRealtime / 1000);
3337 sb.append("realtime, ");
3338 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003339 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003340 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003341 if (batteryTimeRemaining >= 0) {
3342 sb.setLength(0);
3343 sb.append(prefix);
3344 sb.append(" Battery time remaining: ");
3345 formatTimeMs(sb, batteryTimeRemaining / 1000);
3346 pw.println(sb.toString());
3347 }
3348 if (chargeTimeRemaining >= 0) {
3349 sb.setLength(0);
3350 sb.append(prefix);
3351 sb.append(" Charge time remaining: ");
3352 formatTimeMs(sb, chargeTimeRemaining / 1000);
3353 pw.println(sb.toString());
3354 }
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003355 pw.print(" Start clock time: ");
3356 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3357
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003358 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003359 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003360 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003361 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3362 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003363 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003364 rawRealtime, which);
3365 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3366 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003367 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003368 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003369 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3370 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3371 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003372 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003373 sb.append(prefix);
3374 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3375 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003376 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003377 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3378 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003379 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003380 pw.println(sb.toString());
3381 sb.setLength(0);
3382 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003383 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003384 boolean didOne = false;
3385 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003386 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003387 if (time == 0) {
3388 continue;
3389 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003390 sb.append("\n ");
3391 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003392 didOne = true;
3393 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3394 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003395 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003396 sb.append("(");
3397 sb.append(formatRatioLocked(time, screenOnTime));
3398 sb.append(")");
3399 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003400 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003401 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003402 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003403 sb.setLength(0);
3404 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003405 sb.append(" Power save mode enabled: ");
3406 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003407 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003408 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003409 sb.append(")");
3410 pw.println(sb.toString());
3411 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003412 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003413 sb.setLength(0);
3414 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003415 sb.append(" Device light idling: ");
3416 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003417 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003418 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3419 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003420 sb.append("x");
3421 pw.println(sb.toString());
3422 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003423 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003424 sb.setLength(0);
3425 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003426 sb.append(" Idle mode light time: ");
3427 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003428 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003429 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3430 sb.append(") ");
3431 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003432 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003433 sb.append(" -- longest ");
3434 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3435 pw.println(sb.toString());
3436 }
3437 if (deviceIdlingTime != 0) {
3438 sb.setLength(0);
3439 sb.append(prefix);
3440 sb.append(" Device full idling: ");
3441 formatTimeMs(sb, deviceIdlingTime / 1000);
3442 sb.append("(");
3443 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003444 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003445 sb.append("x");
3446 pw.println(sb.toString());
3447 }
3448 if (deviceIdleModeFullTime != 0) {
3449 sb.setLength(0);
3450 sb.append(prefix);
3451 sb.append(" Idle mode full time: ");
3452 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3453 sb.append("(");
3454 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3455 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003456 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003457 sb.append("x");
3458 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003459 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003460 pw.println(sb.toString());
3461 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003462 if (phoneOnTime != 0) {
3463 sb.setLength(0);
3464 sb.append(prefix);
3465 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3466 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003467 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003468 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003469 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003470 if (connChanges != 0) {
3471 pw.print(prefix);
3472 pw.print(" Connectivity changes: "); pw.println(connChanges);
3473 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003474
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003475 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003476 long fullWakeLockTimeTotalMicros = 0;
3477 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003478
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003479 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003480
Evan Millar22ac0432009-03-31 11:33:18 -07003481 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003482 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003483
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003484 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3485 = u.getWakelockStats();
3486 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3487 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003488
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003489 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3490 if (fullWakeTimer != null) {
3491 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3492 rawRealtime, which);
3493 }
3494
3495 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3496 if (partialWakeTimer != null) {
3497 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3498 rawRealtime, which);
3499 if (totalTimeMicros > 0) {
3500 if (reqUid < 0) {
3501 // Only show the ordered list of all wake
3502 // locks if the caller is not asking for data
3503 // about a specific uid.
3504 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3505 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003506 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003507 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003508 }
3509 }
3510 }
3511 }
3512
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003513 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3514 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3515 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3516 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3517 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3518 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3519 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3520 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08003521 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3522 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003523
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003524 if (fullWakeLockTimeTotalMicros != 0) {
3525 sb.setLength(0);
3526 sb.append(prefix);
3527 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3528 (fullWakeLockTimeTotalMicros + 500) / 1000);
3529 pw.println(sb.toString());
3530 }
3531
3532 if (partialWakeLockTimeTotalMicros != 0) {
3533 sb.setLength(0);
3534 sb.append(prefix);
3535 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3536 (partialWakeLockTimeTotalMicros + 500) / 1000);
3537 pw.println(sb.toString());
3538 }
3539
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003540 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003541 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3542 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3543 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3544 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003545 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003546 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003547 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003548 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003549 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003550 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003551 if (time == 0) {
3552 continue;
3553 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003554 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003555 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003556 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003557 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003558 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003559 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003560 sb.append("(");
3561 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003562 sb.append(") ");
3563 sb.append(getPhoneSignalStrengthCount(i, which));
3564 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003565 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003566 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003567 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003568
3569 sb.setLength(0);
3570 sb.append(prefix);
3571 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003572 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003573 pw.println(sb.toString());
3574
Dianne Hackborn627bba72009-03-24 22:32:56 -07003575 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003576 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003577 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003578 didOne = false;
3579 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003580 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003581 if (time == 0) {
3582 continue;
3583 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003584 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003585 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003586 didOne = true;
3587 sb.append(DATA_CONNECTION_NAMES[i]);
3588 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003589 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003590 sb.append("(");
3591 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003592 sb.append(") ");
3593 sb.append(getPhoneDataConnectionCount(i, which));
3594 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003595 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003596 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003597 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003598
3599 sb.setLength(0);
3600 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003601 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003602 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003603 formatTimeMs(sb, mobileActiveTime / 1000);
3604 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3605 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3606 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003607 pw.println(sb.toString());
3608
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003609 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3610 if (mobileActiveUnknownTime != 0) {
3611 sb.setLength(0);
3612 sb.append(prefix);
3613 sb.append(" Mobile radio active unknown time: ");
3614 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3615 sb.append("(");
3616 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3617 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3618 sb.append("x");
3619 pw.println(sb.toString());
3620 }
3621
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003622 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3623 if (mobileActiveAdjustedTime != 0) {
3624 sb.setLength(0);
3625 sb.append(prefix);
3626 sb.append(" Mobile radio active adjusted time: ");
3627 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3628 sb.append("(");
3629 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3630 sb.append(")");
3631 pw.println(sb.toString());
3632 }
3633
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003634 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
3635
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003636 pw.print(prefix);
3637 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3638 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3639 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3640 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003641 sb.setLength(0);
3642 sb.append(prefix);
3643 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3644 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3645 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3646 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003647 sb.append(")");
3648 pw.println(sb.toString());
3649
3650 sb.setLength(0);
3651 sb.append(prefix);
3652 sb.append(" Wifi states:");
3653 didOne = false;
3654 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003655 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003656 if (time == 0) {
3657 continue;
3658 }
3659 sb.append("\n ");
3660 didOne = true;
3661 sb.append(WIFI_STATE_NAMES[i]);
3662 sb.append(" ");
3663 formatTimeMs(sb, time/1000);
3664 sb.append("(");
3665 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3666 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003667 sb.append(getWifiStateCount(i, which));
3668 sb.append("x");
3669 }
3670 if (!didOne) sb.append(" (no activity)");
3671 pw.println(sb.toString());
3672
3673 sb.setLength(0);
3674 sb.append(prefix);
3675 sb.append(" Wifi supplicant states:");
3676 didOne = false;
3677 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3678 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3679 if (time == 0) {
3680 continue;
3681 }
3682 sb.append("\n ");
3683 didOne = true;
3684 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3685 sb.append(" ");
3686 formatTimeMs(sb, time/1000);
3687 sb.append("(");
3688 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3689 sb.append(") ");
3690 sb.append(getWifiSupplStateCount(i, which));
3691 sb.append("x");
3692 }
3693 if (!didOne) sb.append(" (no activity)");
3694 pw.println(sb.toString());
3695
3696 sb.setLength(0);
3697 sb.append(prefix);
3698 sb.append(" Wifi signal levels:");
3699 didOne = false;
3700 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3701 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3702 if (time == 0) {
3703 continue;
3704 }
3705 sb.append("\n ");
3706 sb.append(prefix);
3707 didOne = true;
3708 sb.append("level(");
3709 sb.append(i);
3710 sb.append(") ");
3711 formatTimeMs(sb, time/1000);
3712 sb.append("(");
3713 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3714 sb.append(") ");
3715 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003716 sb.append("x");
3717 }
3718 if (!didOne) sb.append(" (no activity)");
3719 pw.println(sb.toString());
3720
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003721 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07003722
Adam Lesinski50e47602015-12-04 17:04:54 -08003723 pw.print(prefix);
3724 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
3725 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
3726
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003727 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
3728 sb.setLength(0);
3729 sb.append(prefix);
3730 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
3731 pw.println(sb.toString());
3732
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003733 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
3734 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003735
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003736 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003737
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003738 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003739 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003740 pw.print(prefix); pw.println(" Device is currently unplugged");
3741 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3742 pw.println(getDischargeStartLevel());
3743 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3744 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003745 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003746 pw.print(prefix); pw.println(" Device is currently plugged into power");
3747 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3748 pw.println(getDischargeStartLevel());
3749 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3750 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003751 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003752 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3753 pw.println(getDischargeAmountScreenOn());
3754 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3755 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003756 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003757 } else {
3758 pw.print(prefix); pw.println(" Device battery use since last full charge");
3759 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3760 pw.println(getLowDischargeAmountSinceCharge());
3761 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3762 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003763 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3764 pw.println(getDischargeAmountScreenOnSinceCharge());
3765 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3766 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003767 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003768 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003769
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003770 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003771 helper.create(this);
3772 helper.refreshStats(which, UserHandle.USER_ALL);
3773 List<BatterySipper> sippers = helper.getUsageList();
3774 if (sippers != null && sippers.size() > 0) {
3775 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3776 pw.print(prefix); pw.print(" Capacity: ");
3777 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003778 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003779 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3780 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3781 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3782 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003783 pw.println();
3784 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003785 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003786 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003787 switch (bs.drainType) {
3788 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003789 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003790 break;
3791 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003792 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003793 break;
3794 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003795 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003796 break;
3797 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003798 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003799 break;
3800 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003801 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003802 break;
3803 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003804 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003805 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003806 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003807 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003808 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003809 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003810 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003811 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003812 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003813 break;
3814 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003815 pw.print(" User "); pw.print(bs.userId);
3816 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003817 break;
3818 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003819 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003820 break;
3821 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003822 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003823 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003824 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003825 pw.print(" Camera: ");
3826 break;
3827 default:
3828 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003829 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003830 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003831 printmAh(pw, bs.totalPowerMah);
3832
Adam Lesinski57123002015-06-12 16:12:07 -07003833 if (bs.usagePowerMah != bs.totalPowerMah) {
3834 // If the usage (generic power) isn't the whole amount, we list out
3835 // what components are involved in the calculation.
3836
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003837 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07003838 if (bs.usagePowerMah != 0) {
3839 pw.print(" usage=");
3840 printmAh(pw, bs.usagePowerMah);
3841 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003842 if (bs.cpuPowerMah != 0) {
3843 pw.print(" cpu=");
3844 printmAh(pw, bs.cpuPowerMah);
3845 }
3846 if (bs.wakeLockPowerMah != 0) {
3847 pw.print(" wake=");
3848 printmAh(pw, bs.wakeLockPowerMah);
3849 }
3850 if (bs.mobileRadioPowerMah != 0) {
3851 pw.print(" radio=");
3852 printmAh(pw, bs.mobileRadioPowerMah);
3853 }
3854 if (bs.wifiPowerMah != 0) {
3855 pw.print(" wifi=");
3856 printmAh(pw, bs.wifiPowerMah);
3857 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003858 if (bs.bluetoothPowerMah != 0) {
3859 pw.print(" bt=");
3860 printmAh(pw, bs.bluetoothPowerMah);
3861 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003862 if (bs.gpsPowerMah != 0) {
3863 pw.print(" gps=");
3864 printmAh(pw, bs.gpsPowerMah);
3865 }
3866 if (bs.sensorPowerMah != 0) {
3867 pw.print(" sensor=");
3868 printmAh(pw, bs.sensorPowerMah);
3869 }
3870 if (bs.cameraPowerMah != 0) {
3871 pw.print(" camera=");
3872 printmAh(pw, bs.cameraPowerMah);
3873 }
3874 if (bs.flashlightPowerMah != 0) {
3875 pw.print(" flash=");
3876 printmAh(pw, bs.flashlightPowerMah);
3877 }
3878 pw.print(" )");
3879 }
3880 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003881 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08003882 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003883 }
3884
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003885 sippers = helper.getMobilemsppList();
3886 if (sippers != null && sippers.size() > 0) {
3887 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003888 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003889 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003890 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003891 sb.setLength(0);
3892 sb.append(prefix); sb.append(" Uid ");
3893 UserHandle.formatUid(sb, bs.uidObj.getUid());
3894 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
3895 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
3896 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003897 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003898 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003899 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003900 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003901 sb.setLength(0);
3902 sb.append(prefix);
3903 sb.append(" TOTAL TIME: ");
3904 formatTimeMs(sb, totalTime);
3905 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
3906 sb.append(")");
3907 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003908 pw.println();
3909 }
3910
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003911 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
3912 @Override
3913 public int compare(TimerEntry lhs, TimerEntry rhs) {
3914 long lhsTime = lhs.mTime;
3915 long rhsTime = rhs.mTime;
3916 if (lhsTime < rhsTime) {
3917 return 1;
3918 }
3919 if (lhsTime > rhsTime) {
3920 return -1;
3921 }
3922 return 0;
3923 }
3924 };
3925
3926 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003927 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
3928 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003929 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003930 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
3931 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
3932 : kernelWakelocks.entrySet()) {
3933 final BatteryStats.Timer timer = ent.getValue();
3934 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003935 if (totalTimeMillis > 0) {
3936 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
3937 }
3938 }
3939 if (ktimers.size() > 0) {
3940 Collections.sort(ktimers, timerComparator);
3941 pw.print(prefix); pw.println(" All kernel wake locks:");
3942 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003943 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003944 String linePrefix = ": ";
3945 sb.setLength(0);
3946 sb.append(prefix);
3947 sb.append(" Kernel Wake lock ");
3948 sb.append(timer.mName);
3949 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
3950 which, linePrefix);
3951 if (!linePrefix.equals(": ")) {
3952 sb.append(" realtime");
3953 // Only print out wake locks that were held
3954 pw.println(sb.toString());
3955 }
3956 }
3957 pw.println();
3958 }
3959 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003960
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003961 if (timers.size() > 0) {
3962 Collections.sort(timers, timerComparator);
3963 pw.print(prefix); pw.println(" All partial wake locks:");
3964 for (int i=0; i<timers.size(); i++) {
3965 TimerEntry timer = timers.get(i);
3966 sb.setLength(0);
3967 sb.append(" Wake lock ");
3968 UserHandle.formatUid(sb, timer.mId);
3969 sb.append(" ");
3970 sb.append(timer.mName);
3971 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3972 sb.append(" realtime");
3973 pw.println(sb.toString());
3974 }
3975 timers.clear();
3976 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08003977 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003978
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003979 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003980 if (wakeupReasons.size() > 0) {
3981 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003982 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003983 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003984 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003985 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
3986 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003987 }
3988 Collections.sort(reasons, timerComparator);
3989 for (int i=0; i<reasons.size(); i++) {
3990 TimerEntry timer = reasons.get(i);
3991 String linePrefix = ": ";
3992 sb.setLength(0);
3993 sb.append(prefix);
3994 sb.append(" Wakeup reason ");
3995 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003996 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3997 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003998 pw.println(sb.toString());
3999 }
4000 pw.println();
4001 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004002 }
Evan Millar22ac0432009-03-31 11:33:18 -07004003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004004 for (int iu=0; iu<NU; iu++) {
4005 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004006 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004007 continue;
4008 }
4009
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004010 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004011
4012 pw.print(prefix);
4013 pw.print(" ");
4014 UserHandle.formatUid(pw, uid);
4015 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004016 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004017
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004018 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4019 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4020 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4021 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004022 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4023 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4024
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004025 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4026 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004027 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4028 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004029
4030 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4031 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4032
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004033 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4034 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4035 final int wifiScanCount = u.getWifiScanCount(which);
4036 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004037
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004038 if (mobileRxBytes > 0 || mobileTxBytes > 0
4039 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004040 pw.print(prefix); pw.print(" Mobile network: ");
4041 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004042 pw.print(formatBytesLocked(mobileTxBytes));
4043 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4044 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004045 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004046 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4047 sb.setLength(0);
4048 sb.append(prefix); sb.append(" Mobile radio active: ");
4049 formatTimeMs(sb, uidMobileActiveTime / 1000);
4050 sb.append("(");
4051 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4052 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4053 long packets = mobileRxPackets + mobileTxPackets;
4054 if (packets == 0) {
4055 packets = 1;
4056 }
4057 sb.append(" @ ");
4058 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4059 sb.append(" mspp");
4060 pw.println(sb.toString());
4061 }
4062
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004063 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4064 u.getModemControllerActivity(), which);
4065
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004066 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004067 pw.print(prefix); pw.print(" Wi-Fi network: ");
4068 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004069 pw.print(formatBytesLocked(wifiTxBytes));
4070 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4071 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004072 }
4073
Dianne Hackborn62793e42015-03-09 11:15:41 -07004074 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004075 || uidWifiRunningTime != 0) {
4076 sb.setLength(0);
4077 sb.append(prefix); sb.append(" Wifi Running: ");
4078 formatTimeMs(sb, uidWifiRunningTime / 1000);
4079 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4080 whichBatteryRealtime)); sb.append(")\n");
4081 sb.append(prefix); sb.append(" Full Wifi Lock: ");
4082 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4083 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4084 whichBatteryRealtime)); sb.append(")\n");
4085 sb.append(prefix); sb.append(" Wifi Scan: ");
4086 formatTimeMs(sb, wifiScanTime / 1000);
4087 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004088 whichBatteryRealtime)); sb.append(") ");
4089 sb.append(wifiScanCount);
4090 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004091 pw.println(sb.toString());
4092 }
4093
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004094 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4095 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004096
Adam Lesinski50e47602015-12-04 17:04:54 -08004097 if (btRxBytes > 0 || btTxBytes > 0) {
4098 pw.print(prefix); pw.print(" Bluetooth network: ");
4099 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4100 pw.print(formatBytesLocked(btTxBytes));
4101 pw.println(" sent");
4102 }
4103
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004104 uidActivity |= printTimer(pw, sb, u.getBluetoothScanTimer(), rawRealtime, which, prefix,
4105 "Bluetooth Scan");
4106
Dianne Hackborn617f8772009-03-31 15:04:46 -07004107 if (u.hasUserActivity()) {
4108 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004109 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004110 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004111 if (val != 0) {
4112 if (!hasData) {
4113 sb.setLength(0);
4114 sb.append(" User activity: ");
4115 hasData = true;
4116 } else {
4117 sb.append(", ");
4118 }
4119 sb.append(val);
4120 sb.append(" ");
4121 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4122 }
4123 }
4124 if (hasData) {
4125 pw.println(sb.toString());
4126 }
4127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004128
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004129 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4130 = u.getWakelockStats();
4131 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004132 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004133 int countWakelock = 0;
4134 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4135 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4136 String linePrefix = ": ";
4137 sb.setLength(0);
4138 sb.append(prefix);
4139 sb.append(" Wake lock ");
4140 sb.append(wakelocks.keyAt(iw));
4141 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4142 "full", which, linePrefix);
4143 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
4144 "partial", which, linePrefix);
4145 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4146 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004147 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4148 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004149 sb.append(" realtime");
4150 pw.println(sb.toString());
4151 uidActivity = true;
4152 countWakelock++;
4153
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004154 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4155 rawRealtime, which);
4156 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4157 rawRealtime, which);
4158 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4159 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004160 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004161 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004162 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004163 if (countWakelock > 1) {
4164 if (totalFullWakelock != 0 || totalPartialWakelock != 0
4165 || totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004166 sb.setLength(0);
4167 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004168 sb.append(" TOTAL wake: ");
4169 boolean needComma = false;
4170 if (totalFullWakelock != 0) {
4171 needComma = true;
4172 formatTimeMs(sb, totalFullWakelock);
4173 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004174 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004175 if (totalPartialWakelock != 0) {
4176 if (needComma) {
4177 sb.append(", ");
4178 }
4179 needComma = true;
4180 formatTimeMs(sb, totalPartialWakelock);
4181 sb.append("partial");
4182 }
4183 if (totalWindowWakelock != 0) {
4184 if (needComma) {
4185 sb.append(", ");
4186 }
4187 needComma = true;
4188 formatTimeMs(sb, totalWindowWakelock);
4189 sb.append("window");
4190 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004191 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004192 if (needComma) {
4193 sb.append(",");
4194 }
4195 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004196 formatTimeMs(sb, totalDrawWakelock);
4197 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004198 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004199 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004200 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004201 }
4202 }
4203
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004204 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4205 for (int isy=syncs.size()-1; isy>=0; isy--) {
4206 final Timer timer = syncs.valueAt(isy);
4207 // Convert from microseconds to milliseconds with rounding
4208 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4209 final int count = timer.getCountLocked(which);
4210 sb.setLength(0);
4211 sb.append(prefix);
4212 sb.append(" Sync ");
4213 sb.append(syncs.keyAt(isy));
4214 sb.append(": ");
4215 if (totalTime != 0) {
4216 formatTimeMs(sb, totalTime);
4217 sb.append("realtime (");
4218 sb.append(count);
4219 sb.append(" times)");
4220 } else {
4221 sb.append("(not used)");
4222 }
4223 pw.println(sb.toString());
4224 uidActivity = true;
4225 }
4226
4227 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4228 for (int ij=jobs.size()-1; ij>=0; ij--) {
4229 final Timer timer = jobs.valueAt(ij);
4230 // Convert from microseconds to milliseconds with rounding
4231 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4232 final int count = timer.getCountLocked(which);
4233 sb.setLength(0);
4234 sb.append(prefix);
4235 sb.append(" Job ");
4236 sb.append(jobs.keyAt(ij));
4237 sb.append(": ");
4238 if (totalTime != 0) {
4239 formatTimeMs(sb, totalTime);
4240 sb.append("realtime (");
4241 sb.append(count);
4242 sb.append(" times)");
4243 } else {
4244 sb.append("(not used)");
4245 }
4246 pw.println(sb.toString());
4247 uidActivity = true;
4248 }
4249
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004250 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
4251 prefix, "Flashlight");
4252 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
4253 prefix, "Camera");
4254 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
4255 prefix, "Video");
4256 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
4257 prefix, "Audio");
4258
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004259 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4260 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004261 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004262 final Uid.Sensor se = sensors.valueAt(ise);
4263 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004264 sb.setLength(0);
4265 sb.append(prefix);
4266 sb.append(" Sensor ");
4267 int handle = se.getHandle();
4268 if (handle == Uid.Sensor.GPS) {
4269 sb.append("GPS");
4270 } else {
4271 sb.append(handle);
4272 }
4273 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004274
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004275 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004276 if (timer != null) {
4277 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004278 final long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn61659e52014-07-09 16:13:01 -07004279 rawRealtime, which) + 500) / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004280 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004281 //timer.logState();
4282 if (totalTime != 0) {
4283 formatTimeMs(sb, totalTime);
4284 sb.append("realtime (");
4285 sb.append(count);
4286 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004287 } else {
4288 sb.append("(not used)");
4289 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004290 } else {
4291 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004292 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004293
4294 pw.println(sb.toString());
4295 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004296 }
4297
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004298 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4299 "Vibrator");
4300 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4301 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004302
Dianne Hackborn61659e52014-07-09 16:13:01 -07004303 long totalStateTime = 0;
4304 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4305 long time = u.getProcessStateTime(ips, rawRealtime, which);
4306 if (time > 0) {
4307 totalStateTime += time;
4308 sb.setLength(0);
4309 sb.append(prefix);
4310 sb.append(" ");
4311 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4312 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08004313 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004314 pw.println(sb.toString());
4315 uidActivity = true;
4316 }
4317 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08004318 if (totalStateTime > 0) {
4319 sb.setLength(0);
4320 sb.append(prefix);
4321 sb.append(" Total running: ");
4322 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4323 pw.println(sb.toString());
4324 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004325
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004326 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4327 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004328 final long powerCpuMaUs = u.getCpuPowerMaUs(which);
4329 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004330 sb.setLength(0);
4331 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004332 sb.append(" Total cpu time: u=");
4333 formatTimeMs(sb, userCpuTimeUs / 1000);
4334 sb.append("s=");
4335 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07004336 sb.append("p=");
4337 printmAh(sb, powerCpuMaUs / (1000.0 * 1000.0 * 60.0 * 60.0));
4338 sb.append("mAh");
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004339 pw.println(sb.toString());
4340 }
4341
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004342 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4343 = u.getProcessStats();
4344 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4345 final Uid.Proc ps = processStats.valueAt(ipr);
4346 long userTime;
4347 long systemTime;
4348 long foregroundTime;
4349 int starts;
4350 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004351
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004352 userTime = ps.getUserTime(which);
4353 systemTime = ps.getSystemTime(which);
4354 foregroundTime = ps.getForegroundTime(which);
4355 starts = ps.getStarts(which);
4356 final int numCrashes = ps.getNumCrashes(which);
4357 final int numAnrs = ps.getNumAnrs(which);
4358 numExcessive = which == STATS_SINCE_CHARGED
4359 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004361 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
4362 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
4363 sb.setLength(0);
4364 sb.append(prefix); sb.append(" Proc ");
4365 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
4366 sb.append(prefix); sb.append(" CPU: ");
4367 formatTimeMs(sb, userTime); sb.append("usr + ");
4368 formatTimeMs(sb, systemTime); sb.append("krn ; ");
4369 formatTimeMs(sb, foregroundTime); sb.append("fg");
4370 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
4371 sb.append("\n"); sb.append(prefix); sb.append(" ");
4372 boolean hasOne = false;
4373 if (starts != 0) {
4374 hasOne = true;
4375 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07004376 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004377 if (numCrashes != 0) {
4378 if (hasOne) {
4379 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004380 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004381 hasOne = true;
4382 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004383 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004384 if (numAnrs != 0) {
4385 if (hasOne) {
4386 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004388 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 }
4390 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004391 pw.println(sb.toString());
4392 for (int e=0; e<numExcessive; e++) {
4393 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
4394 if (ew != null) {
4395 pw.print(prefix); pw.print(" * Killed for ");
4396 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
4397 pw.print("wake lock");
4398 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
4399 pw.print("cpu");
4400 } else {
4401 pw.print("unknown");
4402 }
4403 pw.print(" use: ");
4404 TimeUtils.formatDuration(ew.usedTime, pw);
4405 pw.print(" over ");
4406 TimeUtils.formatDuration(ew.overTime, pw);
4407 if (ew.overTime != 0) {
4408 pw.print(" (");
4409 pw.print((ew.usedTime*100)/ew.overTime);
4410 pw.println("%)");
4411 }
4412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004413 }
4414 uidActivity = true;
4415 }
4416 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004417
4418 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4419 = u.getPackageStats();
4420 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4421 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
4422 pw.println(":");
4423 boolean apkActivity = false;
4424 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4425 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4426 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
4427 pw.print(prefix); pw.print(" Wakeup alarm ");
4428 pw.print(alarms.keyAt(iwa)); pw.print(": ");
4429 pw.print(alarms.valueAt(iwa).getCountLocked(which));
4430 pw.println(" times");
4431 apkActivity = true;
4432 }
4433 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4434 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4435 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4436 final long startTime = ss.getStartTime(batteryUptime, which);
4437 final int starts = ss.getStarts(which);
4438 final int launches = ss.getLaunches(which);
4439 if (startTime != 0 || starts != 0 || launches != 0) {
4440 sb.setLength(0);
4441 sb.append(prefix); sb.append(" Service ");
4442 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
4443 sb.append(prefix); sb.append(" Created for: ");
4444 formatTimeMs(sb, startTime / 1000);
4445 sb.append("uptime\n");
4446 sb.append(prefix); sb.append(" Starts: ");
4447 sb.append(starts);
4448 sb.append(", launches: "); sb.append(launches);
4449 pw.println(sb.toString());
4450 apkActivity = true;
4451 }
4452 }
4453 if (!apkActivity) {
4454 pw.print(prefix); pw.println(" (nothing executed)");
4455 }
4456 uidActivity = true;
4457 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004459 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004460 }
4461 }
4462 }
4463
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004464 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004465 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004466 int diff = oldval ^ newval;
4467 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004468 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004469 for (int i=0; i<descriptions.length; i++) {
4470 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004471 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004472 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004473 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004474 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004475 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004476 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
4477 didWake = true;
4478 pw.print("=");
4479 if (longNames) {
4480 UserHandle.formatUid(pw, wakelockTag.uid);
4481 pw.print(":\"");
4482 pw.print(wakelockTag.string);
4483 pw.print("\"");
4484 } else {
4485 pw.print(wakelockTag.poolIdx);
4486 }
4487 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004488 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004489 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004490 pw.print("=");
4491 int val = (newval&bd.mask)>>bd.shift;
4492 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004493 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004494 } else {
4495 pw.print(val);
4496 }
4497 }
4498 }
4499 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004500 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07004501 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004502 if (longNames) {
4503 UserHandle.formatUid(pw, wakelockTag.uid);
4504 pw.print(":\"");
4505 pw.print(wakelockTag.string);
4506 pw.print("\"");
4507 } else {
4508 pw.print(wakelockTag.poolIdx);
4509 }
4510 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004511 }
4512
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004513 public void prepareForDumpLocked() {
4514 }
4515
4516 public static class HistoryPrinter {
4517 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004518 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004519 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004520 int oldStatus = -1;
4521 int oldHealth = -1;
4522 int oldPlug = -1;
4523 int oldTemp = -1;
4524 int oldVolt = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004525 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004526
Dianne Hackborn3251b902014-06-20 14:40:53 -07004527 void reset() {
4528 oldState = oldState2 = 0;
4529 oldLevel = -1;
4530 oldStatus = -1;
4531 oldHealth = -1;
4532 oldPlug = -1;
4533 oldTemp = -1;
4534 oldVolt = -1;
4535 }
4536
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004537 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004538 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004539 if (!checkin) {
4540 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004541 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004542 pw.print(" (");
4543 pw.print(rec.numReadInts);
4544 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004545 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004546 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4547 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004548 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004549 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004550 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004551 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004552 }
4553 lastTime = rec.time;
4554 }
4555 if (rec.cmd == HistoryItem.CMD_START) {
4556 if (checkin) {
4557 pw.print(":");
4558 }
4559 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004560 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004561 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4562 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004563 if (checkin) {
4564 pw.print(":");
4565 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004566 if (rec.cmd == HistoryItem.CMD_RESET) {
4567 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004568 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004569 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004570 pw.print("TIME:");
4571 if (checkin) {
4572 pw.println(rec.currentTime);
4573 } else {
4574 pw.print(" ");
4575 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4576 rec.currentTime).toString());
4577 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004578 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4579 if (checkin) {
4580 pw.print(":");
4581 }
4582 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004583 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4584 if (checkin) {
4585 pw.print(":");
4586 }
4587 pw.println("*OVERFLOW*");
4588 } else {
4589 if (!checkin) {
4590 if (rec.batteryLevel < 10) pw.print("00");
4591 else if (rec.batteryLevel < 100) pw.print("0");
4592 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004593 if (verbose) {
4594 pw.print(" ");
4595 if (rec.states < 0) ;
4596 else if (rec.states < 0x10) pw.print("0000000");
4597 else if (rec.states < 0x100) pw.print("000000");
4598 else if (rec.states < 0x1000) pw.print("00000");
4599 else if (rec.states < 0x10000) pw.print("0000");
4600 else if (rec.states < 0x100000) pw.print("000");
4601 else if (rec.states < 0x1000000) pw.print("00");
4602 else if (rec.states < 0x10000000) pw.print("0");
4603 pw.print(Integer.toHexString(rec.states));
4604 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004605 } else {
4606 if (oldLevel != rec.batteryLevel) {
4607 oldLevel = rec.batteryLevel;
4608 pw.print(",Bl="); pw.print(rec.batteryLevel);
4609 }
4610 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004611 if (oldStatus != rec.batteryStatus) {
4612 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004613 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004614 switch (oldStatus) {
4615 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004616 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004617 break;
4618 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004619 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004620 break;
4621 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004622 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004623 break;
4624 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004625 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004626 break;
4627 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004628 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004629 break;
4630 default:
4631 pw.print(oldStatus);
4632 break;
4633 }
4634 }
4635 if (oldHealth != rec.batteryHealth) {
4636 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004637 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004638 switch (oldHealth) {
4639 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004640 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004641 break;
4642 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004643 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004644 break;
4645 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004646 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004647 break;
4648 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004649 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004650 break;
4651 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004652 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004653 break;
4654 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004655 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004656 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004657 case BatteryManager.BATTERY_HEALTH_COLD:
4658 pw.print(checkin ? "c" : "cold");
4659 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004660 default:
4661 pw.print(oldHealth);
4662 break;
4663 }
4664 }
4665 if (oldPlug != rec.batteryPlugType) {
4666 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004667 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004668 switch (oldPlug) {
4669 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004670 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004671 break;
4672 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004673 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004674 break;
4675 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004676 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004677 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004678 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004679 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004680 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004681 default:
4682 pw.print(oldPlug);
4683 break;
4684 }
4685 }
4686 if (oldTemp != rec.batteryTemperature) {
4687 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004688 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004689 pw.print(oldTemp);
4690 }
4691 if (oldVolt != rec.batteryVoltage) {
4692 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004693 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004694 pw.print(oldVolt);
4695 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004696 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004697 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004698 printBitDescriptions(pw, oldState2, rec.states2, null,
4699 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004700 if (rec.wakeReasonTag != null) {
4701 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004702 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004703 pw.print(rec.wakeReasonTag.poolIdx);
4704 } else {
4705 pw.print(" wake_reason=");
4706 pw.print(rec.wakeReasonTag.uid);
4707 pw.print(":\"");
4708 pw.print(rec.wakeReasonTag.string);
4709 pw.print("\"");
4710 }
4711 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004712 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004713 pw.print(checkin ? "," : " ");
4714 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4715 pw.print("+");
4716 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4717 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004718 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004719 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4720 : HISTORY_EVENT_NAMES;
4721 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4722 | HistoryItem.EVENT_FLAG_FINISH);
4723 if (idx >= 0 && idx < eventNames.length) {
4724 pw.print(eventNames[idx]);
4725 } else {
4726 pw.print(checkin ? "Ev" : "event");
4727 pw.print(idx);
4728 }
4729 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004730 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004731 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004732 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004733 UserHandle.formatUid(pw, rec.eventTag.uid);
4734 pw.print(":\"");
4735 pw.print(rec.eventTag.string);
4736 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004737 }
4738 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004739 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004740 if (rec.stepDetails != null) {
4741 if (!checkin) {
4742 pw.print(" Details: cpu=");
4743 pw.print(rec.stepDetails.userTime);
4744 pw.print("u+");
4745 pw.print(rec.stepDetails.systemTime);
4746 pw.print("s");
4747 if (rec.stepDetails.appCpuUid1 >= 0) {
4748 pw.print(" (");
4749 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4750 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4751 if (rec.stepDetails.appCpuUid2 >= 0) {
4752 pw.print(", ");
4753 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4754 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4755 }
4756 if (rec.stepDetails.appCpuUid3 >= 0) {
4757 pw.print(", ");
4758 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4759 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4760 }
4761 pw.print(')');
4762 }
4763 pw.println();
4764 pw.print(" /proc/stat=");
4765 pw.print(rec.stepDetails.statUserTime);
4766 pw.print(" usr, ");
4767 pw.print(rec.stepDetails.statSystemTime);
4768 pw.print(" sys, ");
4769 pw.print(rec.stepDetails.statIOWaitTime);
4770 pw.print(" io, ");
4771 pw.print(rec.stepDetails.statIrqTime);
4772 pw.print(" irq, ");
4773 pw.print(rec.stepDetails.statSoftIrqTime);
4774 pw.print(" sirq, ");
4775 pw.print(rec.stepDetails.statIdlTime);
4776 pw.print(" idle");
4777 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4778 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4779 + rec.stepDetails.statSoftIrqTime;
4780 int total = totalRun + rec.stepDetails.statIdlTime;
4781 if (total > 0) {
4782 pw.print(" (");
4783 float perc = ((float)totalRun) / ((float)total) * 100;
4784 pw.print(String.format("%.1f%%", perc));
4785 pw.print(" of ");
4786 StringBuilder sb = new StringBuilder(64);
4787 formatTimeMsNoSpace(sb, total*10);
4788 pw.print(sb);
4789 pw.print(")");
4790 }
4791 pw.println();
4792 } else {
4793 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4794 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4795 pw.print(rec.stepDetails.userTime);
4796 pw.print(":");
4797 pw.print(rec.stepDetails.systemTime);
4798 if (rec.stepDetails.appCpuUid1 >= 0) {
4799 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4800 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4801 if (rec.stepDetails.appCpuUid2 >= 0) {
4802 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4803 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4804 }
4805 if (rec.stepDetails.appCpuUid3 >= 0) {
4806 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4807 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4808 }
4809 }
4810 pw.println();
4811 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4812 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4813 pw.print(rec.stepDetails.statUserTime);
4814 pw.print(',');
4815 pw.print(rec.stepDetails.statSystemTime);
4816 pw.print(',');
4817 pw.print(rec.stepDetails.statIOWaitTime);
4818 pw.print(',');
4819 pw.print(rec.stepDetails.statIrqTime);
4820 pw.print(',');
4821 pw.print(rec.stepDetails.statSoftIrqTime);
4822 pw.print(',');
4823 pw.print(rec.stepDetails.statIdlTime);
4824 pw.println();
4825 }
4826 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004827 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004828 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004829 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004830 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004831
4832 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4833 UserHandle.formatUid(pw, uid);
4834 pw.print("=");
4835 pw.print(utime);
4836 pw.print("u+");
4837 pw.print(stime);
4838 pw.print("s");
4839 }
4840
4841 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
4842 pw.print('/');
4843 pw.print(uid);
4844 pw.print(":");
4845 pw.print(utime);
4846 pw.print(":");
4847 pw.print(stime);
4848 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004849 }
4850
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004851 private void printSizeValue(PrintWriter pw, long size) {
4852 float result = size;
4853 String suffix = "";
4854 if (result >= 10*1024) {
4855 suffix = "KB";
4856 result = result / 1024;
4857 }
4858 if (result >= 10*1024) {
4859 suffix = "MB";
4860 result = result / 1024;
4861 }
4862 if (result >= 10*1024) {
4863 suffix = "GB";
4864 result = result / 1024;
4865 }
4866 if (result >= 10*1024) {
4867 suffix = "TB";
4868 result = result / 1024;
4869 }
4870 if (result >= 10*1024) {
4871 suffix = "PB";
4872 result = result / 1024;
4873 }
4874 pw.print((int)result);
4875 pw.print(suffix);
4876 }
4877
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004878 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
4879 String label3, long estimatedTime) {
4880 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004881 return false;
4882 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004883 pw.print(label1);
4884 pw.print(label2);
4885 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004886 StringBuilder sb = new StringBuilder(64);
4887 formatTimeMs(sb, estimatedTime);
4888 pw.print(sb);
4889 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004890 return true;
4891 }
4892
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004893 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
4894 LevelStepTracker steps, boolean checkin) {
4895 if (steps == null) {
4896 return false;
4897 }
4898 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004899 if (count <= 0) {
4900 return false;
4901 }
4902 if (!checkin) {
4903 pw.println(header);
4904 }
Kweku Adams030980a2015-04-01 16:07:48 -07004905 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004906 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004907 long duration = steps.getDurationAt(i);
4908 int level = steps.getLevelAt(i);
4909 long initMode = steps.getInitModeAt(i);
4910 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004911 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004912 lineArgs[0] = Long.toString(duration);
4913 lineArgs[1] = Integer.toString(level);
4914 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4915 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4916 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
4917 case Display.STATE_ON: lineArgs[2] = "s+"; break;
4918 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
4919 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07004920 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004921 }
4922 } else {
4923 lineArgs[2] = "";
4924 }
4925 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4926 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
4927 } else {
4928 lineArgs[3] = "";
4929 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004930 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07004931 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004932 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07004933 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004934 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004935 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
4936 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004937 pw.print(prefix);
4938 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004939 TimeUtils.formatDuration(duration, pw);
4940 pw.print(" to "); pw.print(level);
4941 boolean haveModes = false;
4942 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4943 pw.print(" (");
4944 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4945 case Display.STATE_OFF: pw.print("screen-off"); break;
4946 case Display.STATE_ON: pw.print("screen-on"); break;
4947 case Display.STATE_DOZE: pw.print("screen-doze"); break;
4948 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07004949 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004950 }
4951 haveModes = true;
4952 }
4953 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4954 pw.print(haveModes ? ", " : " (");
4955 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
4956 ? "power-save-on" : "power-save-off");
4957 haveModes = true;
4958 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004959 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
4960 pw.print(haveModes ? ", " : " (");
4961 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
4962 ? "device-idle-on" : "device-idle-off");
4963 haveModes = true;
4964 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004965 if (haveModes) {
4966 pw.print(")");
4967 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004968 pw.println();
4969 }
4970 }
4971 return true;
4972 }
4973
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004974 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004975 public static final int DUMP_DAILY_ONLY = 1<<2;
4976 public static final int DUMP_HISTORY_ONLY = 1<<3;
4977 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
4978 public static final int DUMP_VERBOSE = 1<<5;
4979 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004980
Dianne Hackborn37de0982014-05-09 09:32:18 -07004981 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
4982 final HistoryPrinter hprinter = new HistoryPrinter();
4983 final HistoryItem rec = new HistoryItem();
4984 long lastTime = -1;
4985 long baseTime = -1;
4986 boolean printed = false;
4987 HistoryEventTracker tracker = null;
4988 while (getNextHistoryLocked(rec)) {
4989 lastTime = rec.time;
4990 if (baseTime < 0) {
4991 baseTime = lastTime;
4992 }
4993 if (rec.time >= histStart) {
4994 if (histStart >= 0 && !printed) {
4995 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07004996 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004997 || rec.cmd == HistoryItem.CMD_START
4998 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004999 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005000 hprinter.printNextItem(pw, rec, baseTime, checkin,
5001 (flags&DUMP_VERBOSE) != 0);
5002 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005003 } else if (rec.currentTime != 0) {
5004 printed = true;
5005 byte cmd = rec.cmd;
5006 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005007 hprinter.printNextItem(pw, rec, baseTime, checkin,
5008 (flags&DUMP_VERBOSE) != 0);
5009 rec.cmd = cmd;
5010 }
5011 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005012 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5013 hprinter.printNextItem(pw, rec, baseTime, checkin,
5014 (flags&DUMP_VERBOSE) != 0);
5015 rec.cmd = HistoryItem.CMD_UPDATE;
5016 }
5017 int oldEventCode = rec.eventCode;
5018 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005019 rec.eventTag = new HistoryTag();
5020 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5021 HashMap<String, SparseIntArray> active
5022 = tracker.getStateForEvent(i);
5023 if (active == null) {
5024 continue;
5025 }
5026 for (HashMap.Entry<String, SparseIntArray> ent
5027 : active.entrySet()) {
5028 SparseIntArray uids = ent.getValue();
5029 for (int j=0; j<uids.size(); j++) {
5030 rec.eventCode = i;
5031 rec.eventTag.string = ent.getKey();
5032 rec.eventTag.uid = uids.keyAt(j);
5033 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005034 hprinter.printNextItem(pw, rec, baseTime, checkin,
5035 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005036 rec.wakeReasonTag = null;
5037 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005038 }
5039 }
5040 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005041 rec.eventCode = oldEventCode;
5042 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005043 tracker = null;
5044 }
5045 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005046 hprinter.printNextItem(pw, rec, baseTime, checkin,
5047 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005048 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5049 // This is an attempt to aggregate the previous state and generate
5050 // fake events to reflect that state at the point where we start
5051 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005052 if (tracker == null) {
5053 tracker = new HistoryEventTracker();
5054 }
5055 tracker.updateState(rec.eventCode, rec.eventTag.string,
5056 rec.eventTag.uid, rec.eventTag.poolIdx);
5057 }
5058 }
5059 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005060 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005061 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5062 }
5063 }
5064
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005065 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5066 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5067 if (steps == null) {
5068 return;
5069 }
5070 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5071 if (timeRemaining >= 0) {
5072 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5073 tmpSb.setLength(0);
5074 formatTimeMs(tmpSb, timeRemaining);
5075 pw.print(tmpSb);
5076 pw.print(" (from "); pw.print(tmpOutInt[0]);
5077 pw.println(" steps)");
5078 }
5079 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5080 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5081 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5082 if (estimatedTime > 0) {
5083 pw.print(prefix); pw.print(label); pw.print(" ");
5084 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5085 pw.print(" time: ");
5086 tmpSb.setLength(0);
5087 formatTimeMs(tmpSb, estimatedTime);
5088 pw.print(tmpSb);
5089 pw.print(" (from "); pw.print(tmpOutInt[0]);
5090 pw.println(" steps)");
5091 }
5092 }
5093 }
5094
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005095 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5096 ArrayList<PackageChange> changes) {
5097 if (changes == null) {
5098 return;
5099 }
5100 pw.print(prefix); pw.println("Package changes:");
5101 for (int i=0; i<changes.size(); i++) {
5102 PackageChange pc = changes.get(i);
5103 if (pc.mUpdate) {
5104 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5105 pw.print(" vers="); pw.println(pc.mVersionCode);
5106 } else {
5107 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5108 }
5109 }
5110 }
5111
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005112 /**
5113 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5114 *
5115 * @param pw a Printer to receive the dump output.
5116 */
5117 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005118 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005119 prepareForDumpLocked();
5120
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005121 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005122 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005123
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005124 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005125 final long historyTotalSize = getHistoryTotalSize();
5126 final long historyUsedSize = getHistoryUsedSize();
5127 if (startIteratingHistoryLocked()) {
5128 try {
5129 pw.print("Battery History (");
5130 pw.print((100*historyUsedSize)/historyTotalSize);
5131 pw.print("% used, ");
5132 printSizeValue(pw, historyUsedSize);
5133 pw.print(" used of ");
5134 printSizeValue(pw, historyTotalSize);
5135 pw.print(", ");
5136 pw.print(getHistoryStringPoolSize());
5137 pw.print(" strings using ");
5138 printSizeValue(pw, getHistoryStringPoolBytes());
5139 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005140 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005141 pw.println();
5142 } finally {
5143 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005144 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005145 }
5146
5147 if (startIteratingOldHistoryLocked()) {
5148 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005149 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005150 pw.println("Old battery History:");
5151 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005152 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005153 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005154 if (baseTime < 0) {
5155 baseTime = rec.time;
5156 }
5157 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005158 }
5159 pw.println();
5160 } finally {
5161 finishIteratingOldHistoryLocked();
5162 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005163 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005164 }
5165
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005166 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005167 return;
5168 }
5169
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005170 if (!filtering) {
5171 SparseArray<? extends Uid> uidStats = getUidStats();
5172 final int NU = uidStats.size();
5173 boolean didPid = false;
5174 long nowRealtime = SystemClock.elapsedRealtime();
5175 for (int i=0; i<NU; i++) {
5176 Uid uid = uidStats.valueAt(i);
5177 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
5178 if (pids != null) {
5179 for (int j=0; j<pids.size(); j++) {
5180 Uid.Pid pid = pids.valueAt(j);
5181 if (!didPid) {
5182 pw.println("Per-PID Stats:");
5183 didPid = true;
5184 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005185 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
5186 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005187 pw.print(" PID "); pw.print(pids.keyAt(j));
5188 pw.print(" wake time: ");
5189 TimeUtils.formatDuration(time, pw);
5190 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005191 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005192 }
5193 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005194 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005195 pw.println();
5196 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005197 }
5198
5199 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005200 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
5201 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005202 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5203 if (timeRemaining >= 0) {
5204 pw.print(" Estimated discharge time remaining: ");
5205 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5206 pw.println();
5207 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005208 final LevelStepTracker steps = getDischargeLevelStepTracker();
5209 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5210 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
5211 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5212 STEP_LEVEL_MODE_VALUES[i], null));
5213 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005214 pw.println();
5215 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005216 if (dumpDurationSteps(pw, " ", "Charge step durations:",
5217 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005218 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5219 if (timeRemaining >= 0) {
5220 pw.print(" Estimated charge time remaining: ");
5221 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5222 pw.println();
5223 }
5224 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005225 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005226 }
5227 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
5228 pw.println("Daily stats:");
5229 pw.print(" Current start time: ");
5230 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5231 getCurrentDailyStartTime()).toString());
5232 pw.print(" Next min deadline: ");
5233 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5234 getNextMinDailyDeadline()).toString());
5235 pw.print(" Next max deadline: ");
5236 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5237 getNextMaxDailyDeadline()).toString());
5238 StringBuilder sb = new StringBuilder(64);
5239 int[] outInt = new int[1];
5240 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
5241 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005242 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
5243 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005244 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005245 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
5246 dsteps, false)) {
5247 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5248 sb, outInt);
5249 }
5250 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
5251 csteps, false)) {
5252 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5253 sb, outInt);
5254 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005255 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005256 } else {
5257 pw.println(" Current daily steps:");
5258 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5259 sb, outInt);
5260 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5261 sb, outInt);
5262 }
5263 }
5264 DailyItem dit;
5265 int curIndex = 0;
5266 while ((dit=getDailyItemLocked(curIndex)) != null) {
5267 curIndex++;
5268 if ((flags&DUMP_DAILY_ONLY) != 0) {
5269 pw.println();
5270 }
5271 pw.print(" Daily from ");
5272 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
5273 pw.print(" to ");
5274 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
5275 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005276 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005277 if (dumpDurationSteps(pw, " ",
5278 " Discharge step durations:", dit.mDischargeSteps, false)) {
5279 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5280 sb, outInt);
5281 }
5282 if (dumpDurationSteps(pw, " ",
5283 " Charge step durations:", dit.mChargeSteps, false)) {
5284 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5285 sb, outInt);
5286 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005287 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005288 } else {
5289 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5290 sb, outInt);
5291 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5292 sb, outInt);
5293 }
5294 }
5295 pw.println();
5296 }
5297 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005298 pw.println("Statistics since last charge:");
5299 pw.println(" System starts: " + getStartCount()
5300 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005301 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5302 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005303 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005304 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005305 }
5306
5307 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005308 public void dumpCheckinLocked(Context context, PrintWriter pw,
5309 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005310 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005311
5312 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005313 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5314 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005315
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005316 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5317
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005318 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005319 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005320
5321 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005322 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005323 try {
5324 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5325 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5326 pw.print(HISTORY_STRING_POOL); pw.print(',');
5327 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005328 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005329 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005330 pw.print(",\"");
5331 String str = getHistoryTagPoolString(i);
5332 str = str.replace("\\", "\\\\");
5333 str = str.replace("\"", "\\\"");
5334 pw.print(str);
5335 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005336 pw.println();
5337 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005338 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005339 } finally {
5340 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08005341 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005342 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005343 }
5344
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005345 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005346 return;
5347 }
5348
Dianne Hackborne4a59512010-12-07 11:08:07 -08005349 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005350 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08005351 for (int i=0; i<apps.size(); i++) {
5352 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005353 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
5354 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08005355 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005356 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
5357 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005358 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005359 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005360 }
5361 SparseArray<? extends Uid> uidStats = getUidStats();
5362 final int NU = uidStats.size();
5363 String[] lineArgs = new String[2];
5364 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005365 int uid = UserHandle.getAppId(uidStats.keyAt(i));
5366 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
5367 if (pkgs != null && !pkgs.second.value) {
5368 pkgs.second.value = true;
5369 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08005370 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07005371 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08005372 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
5373 (Object[])lineArgs);
5374 }
5375 }
5376 }
5377 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005378 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005379 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005380 String[] lineArgs = new String[1];
5381 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5382 if (timeRemaining >= 0) {
5383 lineArgs[0] = Long.toString(timeRemaining);
5384 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
5385 (Object[])lineArgs);
5386 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005387 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005388 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5389 if (timeRemaining >= 0) {
5390 lineArgs[0] = Long.toString(timeRemaining);
5391 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
5392 (Object[])lineArgs);
5393 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07005394 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
5395 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005397 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005398}