blob: 499d6bbdf535960f2bb65c31f9c3162f90b1d5d7 [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;
James Carr2dd7e5e2016-07-20 18:48:39 -070033import android.util.LongSparseArray;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070034import android.util.MutableBoolean;
35import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.util.Printer;
37import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070038import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070039import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070040import android.view.Display;
Amith Yamasaniab9ad192016-12-06 12:46:59 -080041
Dianne Hackborna7c837f2014-01-15 16:20:44 -080042import com.android.internal.os.BatterySipper;
43import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
45/**
46 * A class providing access to battery usage statistics, including information on
47 * wakelocks, processes, packages, and services. All times are represented in microseconds
48 * except where indicated otherwise.
49 * @hide
50 */
51public abstract class BatteryStats implements Parcelable {
Joe Onorato92fd23f2016-07-25 11:18:42 -070052 private static final String TAG = "BatteryStats";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
54 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070055
56 /** @hide */
57 public static final String SERVICE_NAME = "batterystats";
58
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 /**
60 * A constant indicating a partial wake lock timer.
61 */
62 public static final int WAKE_TYPE_PARTIAL = 0;
63
64 /**
65 * A constant indicating a full wake lock timer.
66 */
67 public static final int WAKE_TYPE_FULL = 1;
68
69 /**
70 * A constant indicating a window wake lock timer.
71 */
72 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 /**
75 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 */
77 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070078
79 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070080 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070081 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070082 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070083
84 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070085 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070086 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070087 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070088
89 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070090 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070091 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070092 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
Dianne Hackborn62793e42015-03-09 11:15:41 -070094 /**
95 * A constant indicating a wifi multicast timer
96 */
97 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700100 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700101 */
102 public static final int VIDEO_TURNED_ON = 8;
103
104 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800105 * A constant indicating a vibrator on timer
106 */
107 public static final int VIBRATOR_ON = 9;
108
109 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700110 * A constant indicating a foreground activity timer
111 */
112 public static final int FOREGROUND_ACTIVITY = 10;
113
114 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700115 * A constant indicating a wifi batched scan is active
116 */
117 public static final int WIFI_BATCHED_SCAN = 11;
118
119 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700120 * A constant indicating a process state timer
121 */
122 public static final int PROCESS_STATE = 12;
123
124 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700125 * A constant indicating a sync timer
126 */
127 public static final int SYNC = 13;
128
129 /**
130 * A constant indicating a job timer
131 */
132 public static final int JOB = 14;
133
134 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800135 * A constant indicating an audio turn on timer
136 */
137 public static final int AUDIO_TURNED_ON = 15;
138
139 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700140 * A constant indicating a flashlight turn on timer
141 */
142 public static final int FLASHLIGHT_TURNED_ON = 16;
143
144 /**
145 * A constant indicating a camera turn on timer
146 */
147 public static final int CAMERA_TURNED_ON = 17;
148
149 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700150 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700151 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700152 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700153
154 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800155 * A constant indicating a bluetooth scan timer.
156 */
157 public static final int BLUETOOTH_SCAN_ON = 19;
158
159 /**
Bookatzc8c44962017-05-11 12:12:54 -0700160 * A constant indicating an aggregated partial wake lock timer.
161 */
162 public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20;
163
164 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 * Include all of the data in the stats, including previously saved data.
166 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700167 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168
169 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 * Include only the current run in the stats.
171 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700172 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173
174 /**
175 * Include only the run since the last time the device was unplugged in the stats.
176 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700177 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700178
179 // NOTE: Update this list if you add/change any stats above.
180 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700181 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700182 private static final String[] STAT_NAMES = { "l", "c", "u" };
183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700185 * Current version of checkin data format.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700186 *
187 * New in version 19:
188 * - Wakelock data (wl) gets current and max times.
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800189 * New in version 20:
Bookatz2bffb5b2017-04-13 11:59:33 -0700190 * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs.
Bookatz506a8182017-05-01 14:18:42 -0700191 * New in version 21:
192 * - Actual (not just apportioned) Wakelock time is also recorded.
Bookatzc8c44962017-05-11 12:12:54 -0700193 * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded.
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700194 */
Bookatz506a8182017-05-01 14:18:42 -0700195 static final String CHECKIN_VERSION = "21";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700196
197 /**
198 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700200 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700201
Evan Millar22ac0432009-03-31 11:33:18 -0700202 private static final long BYTES_PER_KB = 1024;
203 private static final long BYTES_PER_MB = 1048576; // 1024^2
204 private static final long BYTES_PER_GB = 1073741824; //1024^3
Bookatz506a8182017-05-01 14:18:42 -0700205
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700206 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800207 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700208 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700210 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700211 private static final String CPU_DATA = "cpu";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700212 private static final String GLOBAL_CPU_FREQ_DATA = "gcf";
213 private static final String CPU_TIMES_AT_FREQ_DATA = "ctf";
Evan Millare84de8d2009-04-02 22:16:12 -0700214 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800215 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700216 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700217 private static final String STATE_TIME_DATA = "st";
Bookatz506a8182017-05-01 14:18:42 -0700218 // wl line is:
219 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
220 // full totalTime, 'f', count, current duration, max duration, total duration,
221 // partial totalTime, 'p', count, current duration, max duration, total duration,
222 // window totalTime, 'w', count, current duration, max duration, total duration
223 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700224 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700225 // awl line is:
226 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
227 // cumulative partial wakelock duration, cumulative background partial wakelock duration
228 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700229 private static final String SYNC_DATA = "sy";
230 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700231 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700232 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700233 private static final String NETWORK_DATA = "nt";
234 private static final String USER_ACTIVITY_DATA = "ua";
235 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800236 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700237 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700238 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700239 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800240 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
241 private static final String WIFI_CONTROLLER_DATA = "wfcd";
242 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
243 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700244 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700245 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800246 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800247 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
248 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800249 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700250 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700251 private static final String SCREEN_BRIGHTNESS_DATA = "br";
252 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700253 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700254 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
255 private static final String DATA_CONNECTION_TIME_DATA = "dct";
256 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800257 private static final String WIFI_STATE_TIME_DATA = "wst";
258 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700259 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
260 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
261 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
262 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800263 private static final String POWER_USE_SUMMARY_DATA = "pws";
264 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700265 private static final String DISCHARGE_STEP_DATA = "dsd";
266 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700267 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
268 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700269 private static final String FLASHLIGHT_DATA = "fla";
270 private static final String CAMERA_DATA = "cam";
271 private static final String VIDEO_DATA = "vid";
272 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273
Adam Lesinski010bf372016-04-11 12:18:18 -0700274 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
275
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700276 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 private final Formatter mFormatter = new Formatter(mFormatBuilder);
278
279 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700280 * Indicates times spent by the uid at each cpu frequency in all process states.
281 *
282 * Other types might include times spent in foreground, background etc.
283 */
284 private final String UID_TIMES_TYPE_ALL = "A";
285
286 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700287 * State for keeping track of counting information.
288 */
289 public static abstract class Counter {
290
291 /**
292 * Returns the count associated with this Counter for the
293 * selected type of statistics.
294 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700295 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700296 */
Evan Millarc64edde2009-04-18 12:26:32 -0700297 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700298
299 /**
300 * Temporary for debugging.
301 */
302 public abstract void logState(Printer pw, String prefix);
303 }
304
305 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700306 * State for keeping track of long counting information.
307 */
308 public static abstract class LongCounter {
309
310 /**
311 * Returns the count associated with this Counter for the
312 * selected type of statistics.
313 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700314 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700315 */
316 public abstract long getCountLocked(int which);
317
318 /**
319 * Temporary for debugging.
320 */
321 public abstract void logState(Printer pw, String prefix);
322 }
323
324 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700325 * State for keeping track of array of long counting information.
326 */
327 public static abstract class LongCounterArray {
328 /**
329 * Returns the counts associated with this Counter for the
330 * selected type of statistics.
331 *
332 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
333 */
334 public abstract long[] getCountsLocked(int which);
335
336 /**
337 * Temporary for debugging.
338 */
339 public abstract void logState(Printer pw, String prefix);
340 }
341
342 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800343 * Container class that aggregates counters for transmit, receive, and idle state of a
344 * radio controller.
345 */
346 public static abstract class ControllerActivityCounter {
347 /**
348 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
349 * idle state.
350 */
351 public abstract LongCounter getIdleTimeCounter();
352
353 /**
354 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
355 * receive state.
356 */
357 public abstract LongCounter getRxTimeCounter();
358
359 /**
360 * An array of {@link LongCounter}, representing various transmit levels, where each level
361 * may draw a different amount of power. The levels themselves are controller-specific.
362 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
363 * various transmit level states.
364 */
365 public abstract LongCounter[] getTxTimeCounters();
366
367 /**
368 * @return a non-null {@link LongCounter} representing the power consumed by the controller
369 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
370 * yield a value of 0 if the device doesn't support power calculations.
371 */
372 public abstract LongCounter getPowerCounter();
373 }
374
375 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 * State for keeping track of timing information.
377 */
378 public static abstract class Timer {
379
380 /**
381 * Returns the count associated with this Timer for the
382 * selected type of statistics.
383 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700384 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 */
Evan Millarc64edde2009-04-18 12:26:32 -0700386 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387
388 /**
389 * Returns the total time in microseconds associated with this Timer for the
390 * selected type of statistics.
391 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800392 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700393 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 * @return a time in microseconds
395 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800396 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700399 * Returns the total time in microseconds associated with this Timer since the
400 * 'mark' was last set.
401 *
402 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
403 * @return a time in microseconds
404 */
405 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
406
407 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700408 * Returns the max duration if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800409 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700410
411 */
412 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
413 return -1;
414 }
415
416 /**
417 * Returns the current time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800418 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700419 */
420 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
421 return -1;
422 }
423
424 /**
Bookatz867c0d72017-03-07 18:23:42 -0800425 * Returns the current time the timer has been active, if it is being tracked.
426 *
427 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
428 * been on since reset.
429 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
430 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
431 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
432 * the actual total time.
433 * Not all Timer subclasses track the max, total, current durations.
434 */
435 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
436 return -1;
437 }
438
439 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700440 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
441 * used, for example, for tracking background usage. Secondary timers are never pooled.
442 *
443 * Not all Timer subclasses have a secondary timer; those that don't return null.
444 */
445 public Timer getSubTimer() {
446 return null;
447 }
448
449 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700450 * Returns whether the timer is currently running. Some types of timers
451 * (e.g. BatchTimers) don't know whether the event is currently active,
452 * and report false.
453 */
454 public boolean isRunningLocked() {
455 return false;
456 }
457
458 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 * Temporary for debugging.
460 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700461 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 }
463
464 /**
465 * The statistics associated with a particular uid.
466 */
467 public static abstract class Uid {
468
469 /**
470 * Returns a mapping containing wakelock statistics.
471 *
472 * @return a Map from Strings to Uid.Wakelock objects.
473 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700474 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475
476 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700477 * Returns a mapping containing sync statistics.
478 *
479 * @return a Map from Strings to Timer objects.
480 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700481 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700482
483 /**
484 * Returns a mapping containing scheduled job statistics.
485 *
486 * @return a Map from Strings to Timer objects.
487 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700488 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700489
490 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 * The statistics associated with a particular wake lock.
492 */
493 public static abstract class Wakelock {
494 public abstract Timer getWakeTime(int type);
495 }
496
497 /**
Bookatzc8c44962017-05-11 12:12:54 -0700498 * The cumulative time the uid spent holding any partial wakelocks. This will generally
499 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
500 * wakelocks that overlap in time (and therefore over-counts).
501 */
502 public abstract Timer getAggregatedPartialWakelockTimer();
503
504 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 * Returns a mapping containing sensor statistics.
506 *
507 * @return a Map from Integer sensor ids to Uid.Sensor objects.
508 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700509 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510
511 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700512 * Returns a mapping containing active process data.
513 */
514 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700515
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700516 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 * Returns a mapping containing process statistics.
518 *
519 * @return a Map from Strings to Uid.Proc objects.
520 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700521 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522
523 /**
524 * Returns a mapping containing package statistics.
525 *
526 * @return a Map from Strings to Uid.Pkg objects.
527 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700528 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700529
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800530 public abstract ControllerActivityCounter getWifiControllerActivity();
531 public abstract ControllerActivityCounter getBluetoothControllerActivity();
532 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800533
534 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 * {@hide}
536 */
537 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700538
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800539 public abstract void noteWifiRunningLocked(long elapsedRealtime);
540 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
541 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
542 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
543 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
544 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
545 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
546 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
547 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
548 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800549 public abstract void noteActivityResumedLocked(long elapsedRealtime);
550 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800551 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
552 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
553 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700554 public abstract int getWifiScanCount(int which);
Bookatz867c0d72017-03-07 18:23:42 -0800555 public abstract int getWifiScanBackgroundCount(int which);
556 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
557 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800558 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700559 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800560 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700561 public abstract Timer getAudioTurnedOnTimer();
562 public abstract Timer getVideoTurnedOnTimer();
563 public abstract Timer getFlashlightTurnedOnTimer();
564 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700565 public abstract Timer getForegroundActivityTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800566 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800567 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700568 public abstract Counter getBluetoothScanResultCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700569
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700570 public abstract long[] getCpuFreqTimes(int which);
571 public abstract long[] getScreenOffCpuFreqTimes(int which);
572
Dianne Hackborna0200e32016-03-30 18:01:41 -0700573 // Note: the following times are disjoint. They can be added together to find the
574 // total time a uid has had any processes running at all.
575
576 /**
577 * Time this uid has any processes in the top state (or above such as persistent).
578 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800579 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700580 /**
581 * Time this uid has any process with a started out bound foreground service, but
582 * none in the "top" state.
583 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800584 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700585 /**
586 * Time this uid has any process that is top while the device is sleeping, but none
587 * in the "foreground service" or better state.
588 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800589 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700590 /**
591 * Time this uid has any process in an active foreground state, but none in the
592 * "top sleeping" or better state.
593 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800594 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700595 /**
596 * Time this uid has any process in an active background state, but none in the
597 * "foreground" or better state.
598 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800599 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700600 /**
601 * Time this uid has any processes that are sitting around cached, not in one of the
602 * other active states.
603 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800604 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700605 /**
606 * Total number of process states we track.
607 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800608 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700609
610 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800611 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700612 };
613
614 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800615 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700616
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800617 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618
Robert Greenwalta029ea12013-09-25 16:38:12 -0700619 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
620
Dianne Hackborn617f8772009-03-31 15:04:46 -0700621 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700622 * Note that these must match the constants in android.os.PowerManager.
623 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
624 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700625 */
626 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700627 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700628 };
Bookatzc8c44962017-05-11 12:12:54 -0700629
Phil Weaverda80d672016-03-15 16:25:46 -0700630 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700631
Dianne Hackborn617f8772009-03-31 15:04:46 -0700632 public abstract void noteUserActivityLocked(int type);
633 public abstract boolean hasUserActivity();
634 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700635
636 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800637 public abstract long getNetworkActivityBytes(int type, int which);
638 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800639 public abstract long getMobileRadioActiveTime(int which);
640 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700641
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700642 /**
643 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
644 */
645 public abstract long getUserCpuTimeUs(int which);
646
647 /**
648 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
649 */
650 public abstract long getSystemCpuTimeUs(int which);
651
652 /**
Adam Lesinski6832f392015-09-05 18:05:40 -0700653 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a
654 * given CPU cluster.
655 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700656 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700657 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700658 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
659 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700660 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700661 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700662
Adam Lesinski5f056f62016-07-14 16:56:08 -0700663 /**
664 * Returns the number of times this UID woke up the Application Processor to
665 * process a mobile radio packet.
666 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
667 */
668 public abstract long getMobileRadioApWakeupCount(int which);
669
670 /**
671 * Returns the number of times this UID woke up the Application Processor to
672 * process a WiFi packet.
673 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
674 */
675 public abstract long getWifiRadioApWakeupCount(int which);
676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800678 /*
679 * FIXME: it's not correct to use this magic value because it
680 * could clash with a sensor handle (which are defined by
681 * the sensor HAL, and therefore out of our control
682 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 // Magic sensor number for the GPS.
684 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800689
Bookatz867c0d72017-03-07 18:23:42 -0800690 /** Returns a Timer for sensor usage when app is in the background. */
691 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 }
693
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700694 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800695 public int mWakeNesting;
696 public long mWakeSumMs;
697 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700698 }
699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 /**
701 * The statistics associated with a particular process.
702 */
703 public static abstract class Proc {
704
Dianne Hackborn287952c2010-09-22 22:34:31 -0700705 public static class ExcessivePower {
706 public static final int TYPE_WAKE = 1;
707 public static final int TYPE_CPU = 2;
708
709 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700710 public long overTime;
711 public long usedTime;
712 }
713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800715 * Returns true if this process is still active in the battery stats.
716 */
717 public abstract boolean isActive();
718
719 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700720 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800721 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700722 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 */
724 public abstract long getUserTime(int which);
725
726 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700727 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700729 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 */
731 public abstract long getSystemTime(int which);
732
733 /**
734 * Returns the number of times the process has been started.
735 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700736 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 */
738 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700739
740 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800741 * Returns the number of times the process has crashed.
742 *
743 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
744 */
745 public abstract int getNumCrashes(int which);
746
747 /**
748 * Returns the number of times the process has ANRed.
749 *
750 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
751 */
752 public abstract int getNumAnrs(int which);
753
754 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700755 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700756 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700757 * @return foreground cpu time in microseconds
758 */
759 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700760
Dianne Hackborn287952c2010-09-22 22:34:31 -0700761 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700762
Dianne Hackborn287952c2010-09-22 22:34:31 -0700763 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 }
765
766 /**
767 * The statistics associated with a particular package.
768 */
769 public static abstract class Pkg {
770
771 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700772 * Returns information about all wakeup alarms that have been triggered for this
773 * package. The mapping keys are tag names for the alarms, the counter contains
774 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700776 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777
778 /**
779 * Returns a mapping containing service statistics.
780 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700781 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782
783 /**
784 * The statistics associated with a particular service.
785 */
Joe Onoratoabded112016-02-08 16:49:39 -0800786 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787
788 /**
789 * Returns the amount of time spent started.
790 *
791 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700792 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 * @return
794 */
795 public abstract long getStartTime(long batteryUptime, int which);
796
797 /**
798 * Returns the total number of times startService() has been called.
799 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700800 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 */
802 public abstract int getStarts(int which);
803
804 /**
805 * Returns the total number times the service has been launched.
806 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700807 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 */
809 public abstract int getLaunches(int which);
810 }
811 }
812 }
813
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800814 public static final class LevelStepTracker {
815 public long mLastStepTime = -1;
816 public int mNumStepDurations;
817 public final long[] mStepDurations;
818
819 public LevelStepTracker(int maxLevelSteps) {
820 mStepDurations = new long[maxLevelSteps];
821 }
822
823 public LevelStepTracker(int numSteps, long[] steps) {
824 mNumStepDurations = numSteps;
825 mStepDurations = new long[numSteps];
826 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
827 }
828
829 public long getDurationAt(int index) {
830 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
831 }
832
833 public int getLevelAt(int index) {
834 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
835 >> STEP_LEVEL_LEVEL_SHIFT);
836 }
837
838 public int getInitModeAt(int index) {
839 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
840 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
841 }
842
843 public int getModModeAt(int index) {
844 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
845 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
846 }
847
848 private void appendHex(long val, int topOffset, StringBuilder out) {
849 boolean hasData = false;
850 while (topOffset >= 0) {
851 int digit = (int)( (val>>topOffset) & 0xf );
852 topOffset -= 4;
853 if (!hasData && digit == 0) {
854 continue;
855 }
856 hasData = true;
857 if (digit >= 0 && digit <= 9) {
858 out.append((char)('0' + digit));
859 } else {
860 out.append((char)('a' + digit - 10));
861 }
862 }
863 }
864
865 public void encodeEntryAt(int index, StringBuilder out) {
866 long item = mStepDurations[index];
867 long duration = item & STEP_LEVEL_TIME_MASK;
868 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
869 >> STEP_LEVEL_LEVEL_SHIFT);
870 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
871 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
872 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
873 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
874 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
875 case Display.STATE_OFF: out.append('f'); break;
876 case Display.STATE_ON: out.append('o'); break;
877 case Display.STATE_DOZE: out.append('d'); break;
878 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
879 }
880 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
881 out.append('p');
882 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700883 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
884 out.append('i');
885 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800886 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
887 case Display.STATE_OFF: out.append('F'); break;
888 case Display.STATE_ON: out.append('O'); break;
889 case Display.STATE_DOZE: out.append('D'); break;
890 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
891 }
892 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
893 out.append('P');
894 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700895 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
896 out.append('I');
897 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800898 out.append('-');
899 appendHex(level, 4, out);
900 out.append('-');
901 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
902 }
903
904 public void decodeEntryAt(int index, String value) {
905 final int N = value.length();
906 int i = 0;
907 char c;
908 long out = 0;
909 while (i < N && (c=value.charAt(i)) != '-') {
910 i++;
911 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800912 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800913 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800914 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800915 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800916 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800917 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800918 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
919 << STEP_LEVEL_INITIAL_MODE_SHIFT);
920 break;
921 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
922 << STEP_LEVEL_INITIAL_MODE_SHIFT);
923 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700924 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
925 << STEP_LEVEL_INITIAL_MODE_SHIFT);
926 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800927 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
928 break;
929 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
930 break;
931 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
932 break;
933 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
934 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
935 break;
936 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
937 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800938 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700939 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
940 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
941 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800942 }
943 }
944 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800945 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800946 while (i < N && (c=value.charAt(i)) != '-') {
947 i++;
948 level <<= 4;
949 if (c >= '0' && c <= '9') {
950 level += c - '0';
951 } else if (c >= 'a' && c <= 'f') {
952 level += c - 'a' + 10;
953 } else if (c >= 'A' && c <= 'F') {
954 level += c - 'A' + 10;
955 }
956 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800957 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800958 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
959 long duration = 0;
960 while (i < N && (c=value.charAt(i)) != '-') {
961 i++;
962 duration <<= 4;
963 if (c >= '0' && c <= '9') {
964 duration += c - '0';
965 } else if (c >= 'a' && c <= 'f') {
966 duration += c - 'a' + 10;
967 } else if (c >= 'A' && c <= 'F') {
968 duration += c - 'A' + 10;
969 }
970 }
971 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
972 }
973
974 public void init() {
975 mLastStepTime = -1;
976 mNumStepDurations = 0;
977 }
978
979 public void clearTime() {
980 mLastStepTime = -1;
981 }
982
983 public long computeTimePerLevel() {
984 final long[] steps = mStepDurations;
985 final int numSteps = mNumStepDurations;
986
987 // For now we'll do a simple average across all steps.
988 if (numSteps <= 0) {
989 return -1;
990 }
991 long total = 0;
992 for (int i=0; i<numSteps; i++) {
993 total += steps[i] & STEP_LEVEL_TIME_MASK;
994 }
995 return total / numSteps;
996 /*
997 long[] buckets = new long[numSteps];
998 int numBuckets = 0;
999 int numToAverage = 4;
1000 int i = 0;
1001 while (i < numSteps) {
1002 long totalTime = 0;
1003 int num = 0;
1004 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1005 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1006 num++;
1007 }
1008 buckets[numBuckets] = totalTime / num;
1009 numBuckets++;
1010 numToAverage *= 2;
1011 i += num;
1012 }
1013 if (numBuckets < 1) {
1014 return -1;
1015 }
1016 long averageTime = buckets[numBuckets-1];
1017 for (i=numBuckets-2; i>=0; i--) {
1018 averageTime = (averageTime + buckets[i]) / 2;
1019 }
1020 return averageTime;
1021 */
1022 }
1023
1024 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1025 int[] outNumOfInterest) {
1026 final long[] steps = mStepDurations;
1027 final int count = mNumStepDurations;
1028 if (count <= 0) {
1029 return -1;
1030 }
1031 long total = 0;
1032 int numOfInterest = 0;
1033 for (int i=0; i<count; i++) {
1034 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1035 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1036 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1037 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1038 // If the modes of interest didn't change during this step period...
1039 if ((modMode&modesOfInterest) == 0) {
1040 // And the mode values during this period match those we are measuring...
1041 if ((initMode&modesOfInterest) == modeValues) {
1042 // Then this can be used to estimate the total time!
1043 numOfInterest++;
1044 total += steps[i] & STEP_LEVEL_TIME_MASK;
1045 }
1046 }
1047 }
1048 if (numOfInterest <= 0) {
1049 return -1;
1050 }
1051
1052 if (outNumOfInterest != null) {
1053 outNumOfInterest[0] = numOfInterest;
1054 }
1055
1056 // The estimated time is the average time we spend in each level, multipled
1057 // by 100 -- the total number of battery levels
1058 return (total / numOfInterest) * 100;
1059 }
1060
1061 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1062 int stepCount = mNumStepDurations;
1063 final long lastStepTime = mLastStepTime;
1064 if (lastStepTime >= 0 && numStepLevels > 0) {
1065 final long[] steps = mStepDurations;
1066 long duration = elapsedRealtime - lastStepTime;
1067 for (int i=0; i<numStepLevels; i++) {
1068 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1069 long thisDuration = duration / (numStepLevels-i);
1070 duration -= thisDuration;
1071 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1072 thisDuration = STEP_LEVEL_TIME_MASK;
1073 }
1074 steps[0] = thisDuration | modeBits;
1075 }
1076 stepCount += numStepLevels;
1077 if (stepCount > steps.length) {
1078 stepCount = steps.length;
1079 }
1080 }
1081 mNumStepDurations = stepCount;
1082 mLastStepTime = elapsedRealtime;
1083 }
1084
1085 public void readFromParcel(Parcel in) {
1086 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001087 if (N > mStepDurations.length) {
1088 throw new ParcelFormatException("more step durations than available: " + N);
1089 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001090 mNumStepDurations = N;
1091 for (int i=0; i<N; i++) {
1092 mStepDurations[i] = in.readLong();
1093 }
1094 }
1095
1096 public void writeToParcel(Parcel out) {
1097 final int N = mNumStepDurations;
1098 out.writeInt(N);
1099 for (int i=0; i<N; i++) {
1100 out.writeLong(mStepDurations[i]);
1101 }
1102 }
1103 }
1104
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001105 public static final class PackageChange {
1106 public String mPackageName;
1107 public boolean mUpdate;
1108 public int mVersionCode;
1109 }
1110
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001111 public static final class DailyItem {
1112 public long mStartTime;
1113 public long mEndTime;
1114 public LevelStepTracker mDischargeSteps;
1115 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001116 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001117 }
1118
1119 public abstract DailyItem getDailyItemLocked(int daysAgo);
1120
1121 public abstract long getCurrentDailyStartTime();
1122
1123 public abstract long getNextMinDailyDeadline();
1124
1125 public abstract long getNextMaxDailyDeadline();
1126
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001127 public abstract long[] getCpuFreqs();
1128
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001129 public final static class HistoryTag {
1130 public String string;
1131 public int uid;
1132
1133 public int poolIdx;
1134
1135 public void setTo(HistoryTag o) {
1136 string = o.string;
1137 uid = o.uid;
1138 poolIdx = o.poolIdx;
1139 }
1140
1141 public void setTo(String _string, int _uid) {
1142 string = _string;
1143 uid = _uid;
1144 poolIdx = -1;
1145 }
1146
1147 public void writeToParcel(Parcel dest, int flags) {
1148 dest.writeString(string);
1149 dest.writeInt(uid);
1150 }
1151
1152 public void readFromParcel(Parcel src) {
1153 string = src.readString();
1154 uid = src.readInt();
1155 poolIdx = -1;
1156 }
1157
1158 @Override
1159 public boolean equals(Object o) {
1160 if (this == o) return true;
1161 if (o == null || getClass() != o.getClass()) return false;
1162
1163 HistoryTag that = (HistoryTag) o;
1164
1165 if (uid != that.uid) return false;
1166 if (!string.equals(that.string)) return false;
1167
1168 return true;
1169 }
1170
1171 @Override
1172 public int hashCode() {
1173 int result = string.hashCode();
1174 result = 31 * result + uid;
1175 return result;
1176 }
1177 }
1178
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001179 /**
1180 * Optional detailed information that can go into a history step. This is typically
1181 * generated each time the battery level changes.
1182 */
1183 public final static class HistoryStepDetails {
1184 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1185 public int userTime;
1186 public int systemTime;
1187
1188 // Top three apps using CPU in the last step, with times in 1/100 second.
1189 public int appCpuUid1;
1190 public int appCpuUTime1;
1191 public int appCpuSTime1;
1192 public int appCpuUid2;
1193 public int appCpuUTime2;
1194 public int appCpuSTime2;
1195 public int appCpuUid3;
1196 public int appCpuUTime3;
1197 public int appCpuSTime3;
1198
1199 // Information from /proc/stat
1200 public int statUserTime;
1201 public int statSystemTime;
1202 public int statIOWaitTime;
1203 public int statIrqTime;
1204 public int statSoftIrqTime;
1205 public int statIdlTime;
1206
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001207 // Platform-level low power state stats
1208 public String statPlatformIdleState;
1209
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001210 public HistoryStepDetails() {
1211 clear();
1212 }
1213
1214 public void clear() {
1215 userTime = systemTime = 0;
1216 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1217 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1218 = appCpuUTime3 = appCpuSTime3 = 0;
1219 }
1220
1221 public void writeToParcel(Parcel out) {
1222 out.writeInt(userTime);
1223 out.writeInt(systemTime);
1224 out.writeInt(appCpuUid1);
1225 out.writeInt(appCpuUTime1);
1226 out.writeInt(appCpuSTime1);
1227 out.writeInt(appCpuUid2);
1228 out.writeInt(appCpuUTime2);
1229 out.writeInt(appCpuSTime2);
1230 out.writeInt(appCpuUid3);
1231 out.writeInt(appCpuUTime3);
1232 out.writeInt(appCpuSTime3);
1233 out.writeInt(statUserTime);
1234 out.writeInt(statSystemTime);
1235 out.writeInt(statIOWaitTime);
1236 out.writeInt(statIrqTime);
1237 out.writeInt(statSoftIrqTime);
1238 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001239 out.writeString(statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001240 }
1241
1242 public void readFromParcel(Parcel in) {
1243 userTime = in.readInt();
1244 systemTime = in.readInt();
1245 appCpuUid1 = in.readInt();
1246 appCpuUTime1 = in.readInt();
1247 appCpuSTime1 = in.readInt();
1248 appCpuUid2 = in.readInt();
1249 appCpuUTime2 = in.readInt();
1250 appCpuSTime2 = in.readInt();
1251 appCpuUid3 = in.readInt();
1252 appCpuUTime3 = in.readInt();
1253 appCpuSTime3 = in.readInt();
1254 statUserTime = in.readInt();
1255 statSystemTime = in.readInt();
1256 statIOWaitTime = in.readInt();
1257 statIrqTime = in.readInt();
1258 statSoftIrqTime = in.readInt();
1259 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001260 statPlatformIdleState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001261 }
1262 }
1263
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001264 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001265 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001266
1267 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001268 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001269
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001270 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001271 public static final byte CMD_NULL = -1;
1272 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001273 public static final byte CMD_CURRENT_TIME = 5;
1274 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001275 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001276 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001277
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001278 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001279
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001280 /**
1281 * Return whether the command code is a delta data update.
1282 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001283 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001284 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001285 }
1286
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001287 public byte batteryLevel;
1288 public byte batteryStatus;
1289 public byte batteryHealth;
1290 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001291
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001292 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001293 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001294
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001295 // The charge of the battery in micro-Ampere-hours.
1296 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001297
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001298 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001299 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001300 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001301 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001302 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1303 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001304 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001305 public static final int STATE_PHONE_STATE_SHIFT = 6;
1306 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001307 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001308 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001309 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001310
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001311 // These states always appear directly in the first int token
1312 // of a delta change; they should be ones that change relatively
1313 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001314 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1315 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001316 public static final int STATE_GPS_ON_FLAG = 1<<29;
1317 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001318 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001319 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001320 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001321 // Do not use, this is used for coulomb delta count.
1322 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001323 // These are on the lower bits used for the command; if they change
1324 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001325 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001326 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001327 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001328 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1329 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1330 // empty slot
1331 // empty slot
1332 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001333
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001334 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001335 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1336
1337 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001338
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001339 public int states;
1340
Dianne Hackborn3251b902014-06-20 14:40:53 -07001341 // Constants from WIFI_SUPPL_STATE_*
1342 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1343 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1344 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1345 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1346 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1347 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1348
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001349 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001350 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1351 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1352 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001353 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001354 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1355 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1356 public static final int STATE2_CHARGING_FLAG = 1<<24;
1357 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1358 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1359 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001360 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001361
1362 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001363 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001364 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1365
1366 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001367
Dianne Hackborn40c87252014-03-19 16:55:40 -07001368 public int states2;
1369
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001370 // The wake lock that was acquired at this point.
1371 public HistoryTag wakelockTag;
1372
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001373 // Kernel wakeup reason at this point.
1374 public HistoryTag wakeReasonTag;
1375
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001376 // Non-null when there is more detailed information at this step.
1377 public HistoryStepDetails stepDetails;
1378
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001379 public static final int EVENT_FLAG_START = 0x8000;
1380 public static final int EVENT_FLAG_FINISH = 0x4000;
1381
1382 // No event in this item.
1383 public static final int EVENT_NONE = 0x0000;
1384 // Event is about a process that is running.
1385 public static final int EVENT_PROC = 0x0001;
1386 // Event is about an application package that is in the foreground.
1387 public static final int EVENT_FOREGROUND = 0x0002;
1388 // Event is about an application package that is at the top of the screen.
1389 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001390 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001391 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001392 // Events for all additional wake locks aquired/release within a wake block.
1393 // These are not generated by default.
1394 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001395 // Event is about an application executing a scheduled job.
1396 public static final int EVENT_JOB = 0x0006;
1397 // Events for users running.
1398 public static final int EVENT_USER_RUNNING = 0x0007;
1399 // Events for foreground user.
1400 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001401 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001402 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001403 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001404 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001405 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001406 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001407 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001408 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001409 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001410 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001411 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001412 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001413 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001414 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001415 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001416 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001417 // Event for a package being on the temporary whitelist.
1418 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001419 // Event for the screen waking up.
1420 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001421 // Event for the UID that woke up the application processor.
1422 // Used for wakeups coming from WiFi, modem, etc.
1423 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001424 // Event for reporting that a specific partial wake lock has been held for a long duration.
1425 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001426
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001427 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001428 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001429 // Mask to extract out only the type part of the event.
1430 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001431
1432 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1433 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1434 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1435 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1436 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1437 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001438 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1439 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001440 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1441 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001442 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1443 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1444 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1445 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1446 public static final int EVENT_USER_FOREGROUND_START =
1447 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1448 public static final int EVENT_USER_FOREGROUND_FINISH =
1449 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001450 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1451 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001452 public static final int EVENT_TEMP_WHITELIST_START =
1453 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1454 public static final int EVENT_TEMP_WHITELIST_FINISH =
1455 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001456 public static final int EVENT_LONG_WAKE_LOCK_START =
1457 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1458 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1459 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001460
1461 // For CMD_EVENT.
1462 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001463 public HistoryTag eventTag;
1464
Dianne Hackborn9a755432014-05-15 17:05:22 -07001465 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001466 public long currentTime;
1467
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001468 // Meta-data when reading.
1469 public int numReadInts;
1470
1471 // Pre-allocated objects.
1472 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001473 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001474 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001475
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001476 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001477 }
Bookatzc8c44962017-05-11 12:12:54 -07001478
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001479 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001480 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001481 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001482 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001483 }
Bookatzc8c44962017-05-11 12:12:54 -07001484
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001485 public int describeContents() {
1486 return 0;
1487 }
1488
1489 public void writeToParcel(Parcel dest, int flags) {
1490 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001491 int bat = (((int)cmd)&0xff)
1492 | ((((int)batteryLevel)<<8)&0xff00)
1493 | ((((int)batteryStatus)<<16)&0xf0000)
1494 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001495 | ((((int)batteryPlugType)<<24)&0xf000000)
1496 | (wakelockTag != null ? 0x10000000 : 0)
1497 | (wakeReasonTag != null ? 0x20000000 : 0)
1498 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001499 dest.writeInt(bat);
1500 bat = (((int)batteryTemperature)&0xffff)
1501 | ((((int)batteryVoltage)<<16)&0xffff0000);
1502 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001503 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001504 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001505 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001506 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001507 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001508 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001509 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001510 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001511 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001512 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001513 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001514 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001515 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001516 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001517 dest.writeLong(currentTime);
1518 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001519 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001520
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001521 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001522 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001523 int bat = src.readInt();
1524 cmd = (byte)(bat&0xff);
1525 batteryLevel = (byte)((bat>>8)&0xff);
1526 batteryStatus = (byte)((bat>>16)&0xf);
1527 batteryHealth = (byte)((bat>>20)&0xf);
1528 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001529 int bat2 = src.readInt();
1530 batteryTemperature = (short)(bat2&0xffff);
1531 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001532 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001533 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001534 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001535 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001536 wakelockTag = localWakelockTag;
1537 wakelockTag.readFromParcel(src);
1538 } else {
1539 wakelockTag = null;
1540 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001541 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001542 wakeReasonTag = localWakeReasonTag;
1543 wakeReasonTag.readFromParcel(src);
1544 } else {
1545 wakeReasonTag = null;
1546 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001547 if ((bat&0x40000000) != 0) {
1548 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001549 eventTag = localEventTag;
1550 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001551 } else {
1552 eventCode = EVENT_NONE;
1553 eventTag = null;
1554 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001555 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001556 currentTime = src.readLong();
1557 } else {
1558 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001559 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001560 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001561 }
1562
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001563 public void clear() {
1564 time = 0;
1565 cmd = CMD_NULL;
1566 batteryLevel = 0;
1567 batteryStatus = 0;
1568 batteryHealth = 0;
1569 batteryPlugType = 0;
1570 batteryTemperature = 0;
1571 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001572 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001573 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001574 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001575 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001576 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001577 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001578 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001579 }
Bookatzc8c44962017-05-11 12:12:54 -07001580
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001581 public void setTo(HistoryItem o) {
1582 time = o.time;
1583 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001584 setToCommon(o);
1585 }
1586
1587 public void setTo(long time, byte cmd, HistoryItem o) {
1588 this.time = time;
1589 this.cmd = cmd;
1590 setToCommon(o);
1591 }
1592
1593 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001594 batteryLevel = o.batteryLevel;
1595 batteryStatus = o.batteryStatus;
1596 batteryHealth = o.batteryHealth;
1597 batteryPlugType = o.batteryPlugType;
1598 batteryTemperature = o.batteryTemperature;
1599 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001600 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001601 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001602 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001603 if (o.wakelockTag != null) {
1604 wakelockTag = localWakelockTag;
1605 wakelockTag.setTo(o.wakelockTag);
1606 } else {
1607 wakelockTag = null;
1608 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001609 if (o.wakeReasonTag != null) {
1610 wakeReasonTag = localWakeReasonTag;
1611 wakeReasonTag.setTo(o.wakeReasonTag);
1612 } else {
1613 wakeReasonTag = null;
1614 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001615 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001616 if (o.eventTag != null) {
1617 eventTag = localEventTag;
1618 eventTag.setTo(o.eventTag);
1619 } else {
1620 eventTag = null;
1621 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001622 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001623 }
1624
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001625 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001626 return batteryLevel == o.batteryLevel
1627 && batteryStatus == o.batteryStatus
1628 && batteryHealth == o.batteryHealth
1629 && batteryPlugType == o.batteryPlugType
1630 && batteryTemperature == o.batteryTemperature
1631 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001632 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001633 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001634 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001635 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001636 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001637
1638 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001639 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001640 return false;
1641 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001642 if (wakelockTag != o.wakelockTag) {
1643 if (wakelockTag == null || o.wakelockTag == null) {
1644 return false;
1645 }
1646 if (!wakelockTag.equals(o.wakelockTag)) {
1647 return false;
1648 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001649 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001650 if (wakeReasonTag != o.wakeReasonTag) {
1651 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1652 return false;
1653 }
1654 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1655 return false;
1656 }
1657 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001658 if (eventTag != o.eventTag) {
1659 if (eventTag == null || o.eventTag == null) {
1660 return false;
1661 }
1662 if (!eventTag.equals(o.eventTag)) {
1663 return false;
1664 }
1665 }
1666 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001667 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001668 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001669
1670 public final static class HistoryEventTracker {
1671 private final HashMap<String, SparseIntArray>[] mActiveEvents
1672 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1673
1674 public boolean updateState(int code, String name, int uid, int poolIdx) {
1675 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1676 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1677 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1678 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001679 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001680 mActiveEvents[idx] = active;
1681 }
1682 SparseIntArray uids = active.get(name);
1683 if (uids == null) {
1684 uids = new SparseIntArray();
1685 active.put(name, uids);
1686 }
1687 if (uids.indexOfKey(uid) >= 0) {
1688 // Already set, nothing to do!
1689 return false;
1690 }
1691 uids.put(uid, poolIdx);
1692 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1693 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1694 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1695 if (active == null) {
1696 // not currently active, nothing to do.
1697 return false;
1698 }
1699 SparseIntArray uids = active.get(name);
1700 if (uids == null) {
1701 // not currently active, nothing to do.
1702 return false;
1703 }
1704 idx = uids.indexOfKey(uid);
1705 if (idx < 0) {
1706 // not currently active, nothing to do.
1707 return false;
1708 }
1709 uids.removeAt(idx);
1710 if (uids.size() <= 0) {
1711 active.remove(name);
1712 }
1713 }
1714 return true;
1715 }
1716
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001717 public void removeEvents(int code) {
1718 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1719 mActiveEvents[idx] = null;
1720 }
1721
Dianne Hackborn37de0982014-05-09 09:32:18 -07001722 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1723 return mActiveEvents[code];
1724 }
1725 }
1726
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001727 public static final class BitDescription {
1728 public final int mask;
1729 public final int shift;
1730 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001731 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001732 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001733 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001734
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001735 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001736 this.mask = mask;
1737 this.shift = -1;
1738 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001739 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001740 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001741 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001742 }
Bookatzc8c44962017-05-11 12:12:54 -07001743
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001744 public BitDescription(int mask, int shift, String name, String shortName,
1745 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001746 this.mask = mask;
1747 this.shift = shift;
1748 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001749 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001750 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001751 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001752 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001753 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001754
Dianne Hackbornfc064132014-06-02 12:42:12 -07001755 /**
1756 * Don't allow any more batching in to the current history event. This
1757 * is called when printing partial histories, so to ensure that the next
1758 * history event will go in to a new batch after what was printed in the
1759 * last partial history.
1760 */
1761 public abstract void commitCurrentHistoryBatchLocked();
1762
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001763 public abstract int getHistoryTotalSize();
1764
1765 public abstract int getHistoryUsedSize();
1766
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001767 public abstract boolean startIteratingHistoryLocked();
1768
Dianne Hackborn099bc622014-01-22 13:39:16 -08001769 public abstract int getHistoryStringPoolSize();
1770
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001771 public abstract int getHistoryStringPoolBytes();
1772
1773 public abstract String getHistoryTagPoolString(int index);
1774
1775 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001776
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001777 public abstract boolean getNextHistoryLocked(HistoryItem out);
1778
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001779 public abstract void finishIteratingHistoryLocked();
1780
1781 public abstract boolean startIteratingOldHistoryLocked();
1782
1783 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1784
1785 public abstract void finishIteratingOldHistoryLocked();
1786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001787 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001788 * Return the base time offset for the battery history.
1789 */
1790 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001791
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001792 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 * Returns the number of times the device has been started.
1794 */
1795 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001798 * 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 -08001799 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001800 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001801 * {@hide}
1802 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001803 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001804
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001805 /**
1806 * Returns the number of times the screen was turned on.
1807 *
1808 * {@hide}
1809 */
1810 public abstract int getScreenOnCount(int which);
1811
Jeff Browne95c3cd2014-05-02 16:59:26 -07001812 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1813
Dianne Hackborn617f8772009-03-31 15:04:46 -07001814 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1815 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1816 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1817 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1818 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001819
Dianne Hackborn617f8772009-03-31 15:04:46 -07001820 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1821 "dark", "dim", "medium", "light", "bright"
1822 };
Bookatzc8c44962017-05-11 12:12:54 -07001823
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001824 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1825 "0", "1", "2", "3", "4"
1826 };
1827
Dianne Hackborn617f8772009-03-31 15:04:46 -07001828 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001829
Dianne Hackborn617f8772009-03-31 15:04:46 -07001830 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001831 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001832 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001833 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001834 * {@hide}
1835 */
1836 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001837 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001838
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001839 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001840 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001841 * running on battery.
1842 *
1843 * {@hide}
1844 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001845 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001846
1847 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001848 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001849 *
1850 * {@hide}
1851 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001852 public abstract int getPowerSaveModeEnabledCount(int which);
1853
1854 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001855 * Constant for device idle mode: not active.
1856 */
1857 public static final int DEVICE_IDLE_MODE_OFF = 0;
1858
1859 /**
1860 * Constant for device idle mode: active in lightweight mode.
1861 */
1862 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1863
1864 /**
1865 * Constant for device idle mode: active in full mode.
1866 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001867 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001868
1869 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001870 * Returns the time in microseconds that device has been in idle mode while
1871 * running on battery.
1872 *
1873 * {@hide}
1874 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001875 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001876
1877 /**
1878 * Returns the number of times that the devie has gone in to idle mode.
1879 *
1880 * {@hide}
1881 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001882 public abstract int getDeviceIdleModeCount(int mode, int which);
1883
1884 /**
1885 * Return the longest duration we spent in a particular device idle mode (fully in the
1886 * mode, not in idle maintenance etc).
1887 */
1888 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001889
1890 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001891 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001892 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001893 * counts all of the time that we consider the device to be idle, whether or not
1894 * it is currently in the actual device idle mode.
1895 *
1896 * {@hide}
1897 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001898 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001899
1900 /**
1901 * Returns the number of times that the devie has started idling.
1902 *
1903 * {@hide}
1904 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001905 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001906
1907 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001908 * Returns the number of times that connectivity state changed.
1909 *
1910 * {@hide}
1911 */
1912 public abstract int getNumConnectivityChange(int which);
1913
1914 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001915 * 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 -08001916 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001917 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 * {@hide}
1919 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001920 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001921
Dianne Hackborn627bba72009-03-24 22:32:56 -07001922 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001923 * Returns the number of times a phone call was activated.
1924 *
1925 * {@hide}
1926 */
1927 public abstract int getPhoneOnCount(int which);
1928
1929 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001930 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001931 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001932 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07001933 * {@hide}
1934 */
1935 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001936 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001937
Dianne Hackborn617f8772009-03-31 15:04:46 -07001938 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001939 * Returns the time in microseconds that the phone has been trying to
1940 * acquire a signal.
1941 *
1942 * {@hide}
1943 */
1944 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001945 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001946
1947 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001948 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001949 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001950 * {@hide}
1951 */
1952 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1953
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001954 /**
1955 * Returns the time in microseconds that the mobile network has been active
1956 * (in a high power state).
1957 *
1958 * {@hide}
1959 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001960 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001961
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001962 /**
1963 * Returns the number of times that the mobile network has transitioned to the
1964 * active state.
1965 *
1966 * {@hide}
1967 */
1968 public abstract int getMobileRadioActiveCount(int which);
1969
1970 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001971 * Returns the time in microseconds that is the difference between the mobile radio
1972 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1973 * from the radio.
1974 *
1975 * {@hide}
1976 */
1977 public abstract long getMobileRadioActiveAdjustedTime(int which);
1978
1979 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001980 * Returns the time in microseconds that the mobile network has been active
1981 * (in a high power state) but not being able to blame on an app.
1982 *
1983 * {@hide}
1984 */
1985 public abstract long getMobileRadioActiveUnknownTime(int which);
1986
1987 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001988 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001989 *
1990 * {@hide}
1991 */
1992 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001993
Dianne Hackborn627bba72009-03-24 22:32:56 -07001994 public static final int DATA_CONNECTION_NONE = 0;
1995 public static final int DATA_CONNECTION_GPRS = 1;
1996 public static final int DATA_CONNECTION_EDGE = 2;
1997 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001998 public static final int DATA_CONNECTION_CDMA = 4;
1999 public static final int DATA_CONNECTION_EVDO_0 = 5;
2000 public static final int DATA_CONNECTION_EVDO_A = 6;
2001 public static final int DATA_CONNECTION_1xRTT = 7;
2002 public static final int DATA_CONNECTION_HSDPA = 8;
2003 public static final int DATA_CONNECTION_HSUPA = 9;
2004 public static final int DATA_CONNECTION_HSPA = 10;
2005 public static final int DATA_CONNECTION_IDEN = 11;
2006 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002007 public static final int DATA_CONNECTION_LTE = 13;
2008 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002009 public static final int DATA_CONNECTION_HSPAP = 15;
2010 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002011
Dianne Hackborn627bba72009-03-24 22:32:56 -07002012 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002013 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002014 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002015 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002016 };
Bookatzc8c44962017-05-11 12:12:54 -07002017
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002018 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002019
Dianne Hackborn627bba72009-03-24 22:32:56 -07002020 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002021 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002022 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002023 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002024 * {@hide}
2025 */
2026 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002027 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002029 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002030 * Returns the number of times the phone has entered the given data
2031 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002032 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002033 * {@hide}
2034 */
2035 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002036
Dianne Hackborn3251b902014-06-20 14:40:53 -07002037 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2038 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2039 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2040 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2041 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2042 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2043 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2044 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2045 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2046 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2047 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2048 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2049 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2050
2051 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2052
2053 static final String[] WIFI_SUPPL_STATE_NAMES = {
2054 "invalid", "disconn", "disabled", "inactive", "scanning",
2055 "authenticating", "associating", "associated", "4-way-handshake",
2056 "group-handshake", "completed", "dormant", "uninit"
2057 };
2058
2059 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2060 "inv", "dsc", "dis", "inact", "scan",
2061 "auth", "ascing", "asced", "4-way",
2062 "group", "compl", "dorm", "uninit"
2063 };
2064
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002065 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
2066 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002067 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002068 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2069 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002070 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002071 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2072 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2073 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002074 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002075 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002076 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002077 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002078 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2079 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002080 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2081 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2082 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2083 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2084 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2085 new String[] {"in", "out", "emergency", "off"},
2086 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002087 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2088 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2089 SignalStrength.SIGNAL_STRENGTH_NAMES,
2090 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002091 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2092 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2093 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002094 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002095
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002096 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2097 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002098 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002099 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002100 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002101 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002102 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002103 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2104 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2105 new String[] { "off", "light", "full", "???" },
2106 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002107 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2108 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2109 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002110 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2111 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2112 new String[] { "0", "1", "2", "3", "4" },
2113 new String[] { "0", "1", "2", "3", "4" }),
2114 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2115 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2116 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002117 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002118 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002119 };
2120
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002121 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002122 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002123 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2124 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002125 };
2126
2127 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002128 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002129 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002130 "Esw", "Ewa", "Elw", "Eec"
2131 };
2132
2133 @FunctionalInterface
2134 public interface IntToString {
2135 String applyAsString(int val);
2136 }
2137
2138 private static final IntToString sUidToString = UserHandle::formatUid;
2139 private static final IntToString sIntToString = Integer::toString;
2140
2141 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2142 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2143 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2144 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2145 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002146 };
2147
Dianne Hackborn617f8772009-03-31 15:04:46 -07002148 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002149 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002150 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002151 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002152 * {@hide}
2153 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002154 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002155
2156 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002157 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002158 * been in the running state while the device was running on battery.
2159 *
2160 * {@hide}
2161 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002162 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002163
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002164 public static final int WIFI_STATE_OFF = 0;
2165 public static final int WIFI_STATE_OFF_SCANNING = 1;
2166 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2167 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2168 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2169 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2170 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2171 public static final int WIFI_STATE_SOFT_AP = 7;
2172
2173 static final String[] WIFI_STATE_NAMES = {
2174 "off", "scanning", "no_net", "disconn",
2175 "sta", "p2p", "sta_p2p", "soft_ap"
2176 };
2177
2178 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2179
2180 /**
2181 * Returns the time in microseconds that WiFi has been running in the given state.
2182 *
2183 * {@hide}
2184 */
2185 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002186 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002187
2188 /**
2189 * Returns the number of times that WiFi has entered the given state.
2190 *
2191 * {@hide}
2192 */
2193 public abstract int getWifiStateCount(int wifiState, int which);
2194
The Android Open Source Project10592532009-03-18 17:39:46 -07002195 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002196 * Returns the time in microseconds that the wifi supplicant has been
2197 * in a given state.
2198 *
2199 * {@hide}
2200 */
2201 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2202
2203 /**
2204 * Returns the number of times that the wifi supplicant has transitioned
2205 * to a given state.
2206 *
2207 * {@hide}
2208 */
2209 public abstract int getWifiSupplStateCount(int state, int which);
2210
2211 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2212
2213 /**
2214 * Returns the time in microseconds that WIFI has been running with
2215 * the given signal strength.
2216 *
2217 * {@hide}
2218 */
2219 public abstract long getWifiSignalStrengthTime(int strengthBin,
2220 long elapsedRealtimeUs, int which);
2221
2222 /**
2223 * Returns the number of times WIFI has entered the given signal strength.
2224 *
2225 * {@hide}
2226 */
2227 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2228
2229 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002230 * Returns the time in microseconds that the flashlight has been on while the device was
2231 * running on battery.
2232 *
2233 * {@hide}
2234 */
2235 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2236
2237 /**
2238 * Returns the number of times that the flashlight has been turned on while the device was
2239 * running on battery.
2240 *
2241 * {@hide}
2242 */
2243 public abstract long getFlashlightOnCount(int which);
2244
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002245 /**
2246 * Returns the time in microseconds that the camera has been on while the device was
2247 * running on battery.
2248 *
2249 * {@hide}
2250 */
2251 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2252
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002253 /**
2254 * Returns the time in microseconds that bluetooth scans were running while the device was
2255 * on battery.
2256 *
2257 * {@hide}
2258 */
2259 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002260
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002261 public static final int NETWORK_MOBILE_RX_DATA = 0;
2262 public static final int NETWORK_MOBILE_TX_DATA = 1;
2263 public static final int NETWORK_WIFI_RX_DATA = 2;
2264 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002265 public static final int NETWORK_BT_RX_DATA = 4;
2266 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002267 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2268 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2269 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2270 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2271 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002272
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002273 public abstract long getNetworkActivityBytes(int type, int which);
2274 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002275
Adam Lesinskie08af192015-03-25 16:42:59 -07002276 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002277 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002278 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002279 * actual power data.
2280 */
2281 public abstract boolean hasWifiActivityReporting();
2282
2283 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002284 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2285 * in various radio controller states, such as transmit, receive, and idle.
2286 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002287 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002288 public abstract ControllerActivityCounter getWifiControllerActivity();
2289
2290 /**
2291 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2292 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2293 * actual power data.
2294 */
2295 public abstract boolean hasBluetoothActivityReporting();
2296
2297 /**
2298 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2299 * in various radio controller states, such as transmit, receive, and idle.
2300 * @return non-null {@link ControllerActivityCounter}
2301 */
2302 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2303
2304 /**
2305 * Returns true if the BatteryStats object has detailed modem power reports.
2306 * When true, calling {@link #getModemControllerActivity()} will yield the
2307 * actual power data.
2308 */
2309 public abstract boolean hasModemActivityReporting();
2310
2311 /**
2312 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2313 * in various radio controller states, such as transmit, receive, and idle.
2314 * @return non-null {@link ControllerActivityCounter}
2315 */
2316 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002317
The Android Open Source Project10592532009-03-18 17:39:46 -07002318 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002319 * Return the wall clock time when battery stats data collection started.
2320 */
2321 public abstract long getStartClockTime();
2322
2323 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002324 * Return platform version tag that we were running in when the battery stats started.
2325 */
2326 public abstract String getStartPlatformVersion();
2327
2328 /**
2329 * Return platform version tag that we were running in when the battery stats ended.
2330 */
2331 public abstract String getEndPlatformVersion();
2332
2333 /**
2334 * Return the internal version code of the parcelled format.
2335 */
2336 public abstract int getParcelVersion();
2337
2338 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 * Return whether we are currently running on battery.
2340 */
2341 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 /**
2344 * Returns a SparseArray containing the statistics for each uid.
2345 */
2346 public abstract SparseArray<? extends Uid> getUidStats();
2347
2348 /**
2349 * Returns the current battery uptime in microseconds.
2350 *
2351 * @param curTime the amount of elapsed realtime in microseconds.
2352 */
2353 public abstract long getBatteryUptime(long curTime);
2354
2355 /**
2356 * Returns the current battery realtime in microseconds.
2357 *
2358 * @param curTime the amount of elapsed realtime in microseconds.
2359 */
2360 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002361
The Android Open Source Project10592532009-03-18 17:39:46 -07002362 /**
Evan Millar633a1742009-04-02 16:36:33 -07002363 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002364 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002365 */
Evan Millar633a1742009-04-02 16:36:33 -07002366 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002367
The Android Open Source Project10592532009-03-18 17:39:46 -07002368 /**
Evan Millar633a1742009-04-02 16:36:33 -07002369 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2370 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002371 */
Evan Millar633a1742009-04-02 16:36:33 -07002372 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373
2374 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002375 * Get the amount the battery has discharged since the stats were
2376 * last reset after charging, as a lower-end approximation.
2377 */
2378 public abstract int getLowDischargeAmountSinceCharge();
2379
2380 /**
2381 * Get the amount the battery has discharged since the stats were
2382 * last reset after charging, as an upper-end approximation.
2383 */
2384 public abstract int getHighDischargeAmountSinceCharge();
2385
2386 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002387 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2388 */
2389 public abstract int getDischargeAmount(int which);
2390
2391 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002392 * Get the amount the battery has discharged while the screen was on,
2393 * since the last time power was unplugged.
2394 */
2395 public abstract int getDischargeAmountScreenOn();
2396
2397 /**
2398 * Get the amount the battery has discharged while the screen was on,
2399 * since the last time the device was charged.
2400 */
2401 public abstract int getDischargeAmountScreenOnSinceCharge();
2402
2403 /**
2404 * Get the amount the battery has discharged while the screen was off,
2405 * since the last time power was unplugged.
2406 */
2407 public abstract int getDischargeAmountScreenOff();
2408
2409 /**
2410 * Get the amount the battery has discharged while the screen was off,
2411 * since the last time the device was charged.
2412 */
2413 public abstract int getDischargeAmountScreenOffSinceCharge();
2414
2415 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 * Returns the total, last, or current battery uptime in microseconds.
2417 *
2418 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002419 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 */
2421 public abstract long computeBatteryUptime(long curTime, int which);
2422
2423 /**
2424 * Returns the total, last, or current battery realtime in microseconds.
2425 *
2426 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002427 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 */
2429 public abstract long computeBatteryRealtime(long curTime, int which);
2430
2431 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002432 * Returns the total, last, or current battery screen off uptime in microseconds.
2433 *
2434 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002435 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002436 */
2437 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2438
2439 /**
2440 * Returns the total, last, or current battery screen off realtime in microseconds.
2441 *
2442 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002443 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002444 */
2445 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2446
2447 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 * Returns the total, last, or current uptime in microseconds.
2449 *
2450 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002451 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002452 */
2453 public abstract long computeUptime(long curTime, int which);
2454
2455 /**
2456 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002457 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002459 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002460 */
2461 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002462
2463 /**
2464 * Compute an approximation for how much run time (in microseconds) is remaining on
2465 * the battery. Returns -1 if no time can be computed: either there is not
2466 * enough current data to make a decision, or the battery is currently
2467 * charging.
2468 *
2469 * @param curTime The current elepsed realtime in microseconds.
2470 */
2471 public abstract long computeBatteryTimeRemaining(long curTime);
2472
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002473 // The part of a step duration that is the actual time.
2474 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2475
2476 // Bits in a step duration that are the new battery level we are at.
2477 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002478 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002479
2480 // Bits in a step duration that are the initial mode we were in at that step.
2481 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002482 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002483
2484 // Bits in a step duration that indicate which modes changed during that step.
2485 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002486 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002487
2488 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2489 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2490
Santos Cordone94f0502017-02-24 12:31:20 -08002491 // The largest value for screen state that is tracked in battery states. Any values above
2492 // this should be mapped back to one of the tracked values before being tracked here.
2493 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2494
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002495 // Step duration mode: power save is on.
2496 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2497
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002498 // Step duration mode: device is currently in idle mode.
2499 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2500
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002501 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2502 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002503 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2504 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002505 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2506 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2507 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2508 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2509 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002510 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2511 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002512 };
2513 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2514 (Display.STATE_OFF-1),
2515 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002516 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002517 (Display.STATE_ON-1),
2518 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2519 (Display.STATE_DOZE-1),
2520 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2521 (Display.STATE_DOZE_SUSPEND-1),
2522 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002523 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002524 };
2525 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2526 "screen off",
2527 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002528 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002529 "screen on",
2530 "screen on power save",
2531 "screen doze",
2532 "screen doze power save",
2533 "screen doze-suspend",
2534 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002535 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002536 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002537
2538 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002539 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2540 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2541 * a coulomb counter.
2542 */
2543 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2544
2545 /**
2546 * Return the counter keeping track of the amount of battery discharge measured in
2547 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2548 * a coulomb counter.
2549 */
2550 public abstract LongCounter getDischargeCoulombCounter();
2551
2552 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002553 * Returns the estimated real battery capacity, which may be less than the capacity
2554 * declared by the PowerProfile.
2555 * @return The estimated battery capacity in mAh.
2556 */
2557 public abstract int getEstimatedBatteryCapacity();
2558
2559 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002560 * @return The minimum learned battery capacity in uAh.
2561 */
2562 public abstract int getMinLearnedBatteryCapacity();
2563
2564 /**
2565 * @return The maximum learned battery capacity in uAh.
2566 */
2567 public abstract int getMaxLearnedBatteryCapacity() ;
2568
2569 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002570 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002571 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002572 public abstract LevelStepTracker getDischargeLevelStepTracker();
2573
2574 /**
2575 * Return the array of daily discharge step durations.
2576 */
2577 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002578
2579 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002580 * Compute an approximation for how much time (in microseconds) remains until the battery
2581 * is fully charged. Returns -1 if no time can be computed: either there is not
2582 * enough current data to make a decision, or the battery is currently
2583 * discharging.
2584 *
2585 * @param curTime The current elepsed realtime in microseconds.
2586 */
2587 public abstract long computeChargeTimeRemaining(long curTime);
2588
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002589 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002590 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002591 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002592 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002593
2594 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002595 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002596 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002597 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002598
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002599 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2600
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002601 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002602
Evan Millarc64edde2009-04-18 12:26:32 -07002603 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604
James Carr2dd7e5e2016-07-20 18:48:39 -07002605 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2606
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002607 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2608
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002609 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 long days = seconds / (60 * 60 * 24);
2611 if (days != 0) {
2612 out.append(days);
2613 out.append("d ");
2614 }
2615 long used = days * 60 * 60 * 24;
2616
2617 long hours = (seconds - used) / (60 * 60);
2618 if (hours != 0 || used != 0) {
2619 out.append(hours);
2620 out.append("h ");
2621 }
2622 used += hours * 60 * 60;
2623
2624 long mins = (seconds-used) / 60;
2625 if (mins != 0 || used != 0) {
2626 out.append(mins);
2627 out.append("m ");
2628 }
2629 used += mins * 60;
2630
2631 if (seconds != 0 || used != 0) {
2632 out.append(seconds-used);
2633 out.append("s ");
2634 }
2635 }
2636
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002637 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002638 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002639 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002640 sb.append(time - (sec * 1000));
2641 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 }
2643
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002644 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002645 long sec = time / 1000;
2646 formatTimeRaw(sb, sec);
2647 sb.append(time - (sec * 1000));
2648 sb.append("ms");
2649 }
2650
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002651 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002652 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002653 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002654 }
2655 float perc = ((float)num) / ((float)den) * 100;
2656 mFormatBuilder.setLength(0);
2657 mFormatter.format("%.1f%%", perc);
2658 return mFormatBuilder.toString();
2659 }
2660
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002661 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002662 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002663
Evan Millar22ac0432009-03-31 11:33:18 -07002664 if (bytes < BYTES_PER_KB) {
2665 return bytes + "B";
2666 } else if (bytes < BYTES_PER_MB) {
2667 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2668 return mFormatBuilder.toString();
2669 } else if (bytes < BYTES_PER_GB){
2670 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2671 return mFormatBuilder.toString();
2672 } else {
2673 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2674 return mFormatBuilder.toString();
2675 }
2676 }
2677
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002678 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002679 if (timer != null) {
2680 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002681 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002682 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2683 return totalTimeMillis;
2684 }
2685 return 0;
2686 }
2687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 /**
2689 *
2690 * @param sb a StringBuilder object.
2691 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002692 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002694 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 * @param linePrefix a String to be prepended to each line of output.
2696 * @return the line prefix
2697 */
2698 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002699 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002701 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002702 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002703
Evan Millarc64edde2009-04-18 12:26:32 -07002704 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002705 if (totalTimeMillis != 0) {
2706 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002707 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002708 if (name != null) {
2709 sb.append(name);
2710 sb.append(' ');
2711 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 sb.append('(');
2713 sb.append(count);
2714 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002715 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2716 if (maxDurationMs >= 0) {
2717 sb.append(" max=");
2718 sb.append(maxDurationMs);
2719 }
Bookatz506a8182017-05-01 14:18:42 -07002720 // Put actual time if it is available and different from totalTimeMillis.
2721 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2722 if (totalDurMs > totalTimeMillis) {
2723 sb.append(" actual=");
2724 sb.append(totalDurMs);
2725 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002726 if (timer.isRunningLocked()) {
2727 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2728 if (currentMs >= 0) {
2729 sb.append(" (running for ");
2730 sb.append(currentMs);
2731 sb.append("ms)");
2732 } else {
2733 sb.append(" (running)");
2734 }
2735 }
2736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002737 return ", ";
2738 }
2739 }
2740 return linePrefix;
2741 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002742
2743 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002744 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002745 *
2746 * @param pw a PrintWriter object to print to.
2747 * @param sb a StringBuilder object.
2748 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002749 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002750 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2751 * @param prefix a String to be prepended to each line of output.
2752 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002753 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002754 */
2755 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002756 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002757 if (timer != null) {
2758 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002759 final long totalTimeMs = (timer.getTotalTimeLocked(
2760 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002761 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002762 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002763 sb.setLength(0);
2764 sb.append(prefix);
2765 sb.append(" ");
2766 sb.append(type);
2767 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002768 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002769 sb.append("realtime (");
2770 sb.append(count);
2771 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002772 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2773 if (maxDurationMs >= 0) {
2774 sb.append(" max=");
2775 sb.append(maxDurationMs);
2776 }
2777 if (timer.isRunningLocked()) {
2778 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2779 if (currentMs >= 0) {
2780 sb.append(" (running for ");
2781 sb.append(currentMs);
2782 sb.append("ms)");
2783 } else {
2784 sb.append(" (running)");
2785 }
2786 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002787 pw.println(sb.toString());
2788 return true;
2789 }
2790 }
2791 return false;
2792 }
Bookatzc8c44962017-05-11 12:12:54 -07002793
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 /**
2795 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002796 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 * @param sb a StringBuilder object.
2798 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002799 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002801 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 * @param linePrefix a String to be prepended to each line of output.
2803 * @return the line prefix
2804 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002805 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2806 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002807 long totalTimeMicros = 0;
2808 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07002809 long max = 0;
2810 long current = 0;
2811 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002812 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002813 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07002814 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002815 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2816 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07002817 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002818 }
2819 sb.append(linePrefix);
2820 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2821 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002822 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002824 sb.append(',');
2825 sb.append(current);
2826 sb.append(',');
2827 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07002828 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
2829 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
2830 // totalDuration independent of totalTimeMicros (since they are not pooled).
2831 if (name != null) {
2832 sb.append(',');
2833 sb.append(totalDuration);
2834 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 return ",";
2836 }
Bookatz506a8182017-05-01 14:18:42 -07002837
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002838 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2839 String type) {
2840 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2841 pw.print(',');
2842 pw.print(uid);
2843 pw.print(',');
2844 pw.print(category);
2845 pw.print(',');
2846 pw.print(type);
2847 }
2848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002849 /**
2850 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07002851 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 * @param pw the PageWriter to dump log to
2853 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2854 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2855 * @param args type-dependent data arguments
2856 */
Bookatzc8c44962017-05-11 12:12:54 -07002857 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002859 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002860 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002861 pw.print(',');
2862 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002864 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002866
2867 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002868 * Dump a given timer stat for terse checkin mode.
2869 *
2870 * @param pw the PageWriter to dump log to
2871 * @param uid the UID to log
2872 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2873 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2874 * @param timer a {@link Timer} to dump stats for
2875 * @param rawRealtime the current elapsed realtime of the system in microseconds
2876 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2877 */
2878 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2879 Timer timer, long rawRealtime, int which) {
2880 if (timer != null) {
2881 // Convert from microseconds to milliseconds with rounding
2882 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2883 / 1000;
2884 final int count = timer.getCountLocked(which);
2885 if (totalTime != 0) {
2886 dumpLine(pw, uid, category, type, totalTime, count);
2887 }
2888 }
2889 }
2890
2891 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002892 * Checks if the ControllerActivityCounter has any data worth dumping.
2893 */
2894 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2895 if (counter == null) {
2896 return false;
2897 }
2898
2899 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2900 || counter.getRxTimeCounter().getCountLocked(which) != 0
2901 || counter.getPowerCounter().getCountLocked(which) != 0) {
2902 return true;
2903 }
2904
2905 for (LongCounter c : counter.getTxTimeCounters()) {
2906 if (c.getCountLocked(which) != 0) {
2907 return true;
2908 }
2909 }
2910 return false;
2911 }
2912
2913 /**
2914 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2915 * The order of the arguments in the final check in line is:
2916 *
2917 * idle, rx, power, tx...
2918 *
2919 * where tx... is one or more transmit level times.
2920 */
2921 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2922 String type,
2923 ControllerActivityCounter counter,
2924 int which) {
2925 if (!controllerActivityHasData(counter, which)) {
2926 return;
2927 }
2928
2929 dumpLineHeader(pw, uid, category, type);
2930 pw.print(",");
2931 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2932 pw.print(",");
2933 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2934 pw.print(",");
2935 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2936 for (LongCounter c : counter.getTxTimeCounters()) {
2937 pw.print(",");
2938 pw.print(c.getCountLocked(which));
2939 }
2940 pw.println();
2941 }
2942
2943 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2944 String prefix, String controllerName,
2945 ControllerActivityCounter counter,
2946 int which) {
2947 if (controllerActivityHasData(counter, which)) {
2948 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2949 }
2950 }
2951
2952 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2953 String controllerName,
2954 ControllerActivityCounter counter, int which) {
2955 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2956 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2957 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2958 long totalTxTimeMs = 0;
2959 for (LongCounter txState : counter.getTxTimeCounters()) {
2960 totalTxTimeMs += txState.getCountLocked(which);
2961 }
2962
2963 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2964
2965 sb.setLength(0);
2966 sb.append(prefix);
2967 sb.append(" ");
2968 sb.append(controllerName);
2969 sb.append(" Idle time: ");
2970 formatTimeMs(sb, idleTimeMs);
2971 sb.append("(");
2972 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2973 sb.append(")");
2974 pw.println(sb.toString());
2975
2976 sb.setLength(0);
2977 sb.append(prefix);
2978 sb.append(" ");
2979 sb.append(controllerName);
2980 sb.append(" Rx time: ");
2981 formatTimeMs(sb, rxTimeMs);
2982 sb.append("(");
2983 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
2984 sb.append(")");
2985 pw.println(sb.toString());
2986
2987 sb.setLength(0);
2988 sb.append(prefix);
2989 sb.append(" ");
2990 sb.append(controllerName);
2991 sb.append(" Tx time: ");
2992 formatTimeMs(sb, totalTxTimeMs);
2993 sb.append("(");
2994 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
2995 sb.append(")");
2996 pw.println(sb.toString());
2997
2998 final int numTxLvls = counter.getTxTimeCounters().length;
2999 if (numTxLvls > 1) {
3000 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3001 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3002 sb.setLength(0);
3003 sb.append(prefix);
3004 sb.append(" [");
3005 sb.append(lvl);
3006 sb.append("] ");
3007 formatTimeMs(sb, txLvlTimeMs);
3008 sb.append("(");
3009 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
3010 sb.append(")");
3011 pw.println(sb.toString());
3012 }
3013 }
3014
3015 sb.setLength(0);
3016 sb.append(prefix);
3017 sb.append(" ");
3018 sb.append(controllerName);
3019 sb.append(" Power drain: ").append(
3020 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
3021 sb.append("mAh");
3022 pw.println(sb.toString());
3023 }
3024
3025 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003026 * Temporary for settings.
3027 */
3028 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3029 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3030 }
3031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 /**
3033 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003034 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003036 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003037 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3038 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3040 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3041 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3043 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003044 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3045 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3046 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 final long totalRealtime = computeRealtime(rawRealtime, which);
3048 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003049 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003050 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003051 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003052 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3053 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003054 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003055 rawRealtime, which);
3056 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3057 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003058 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003059 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003060 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003061 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003062 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
3063 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
3064 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003065
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003066 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003067
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003068 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003069 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003070
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003071 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003074 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003075 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003076 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003077 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003078 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003079 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003080 getEstimatedBatteryCapacity(),
3081 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity());
Adam Lesinski67c134f2016-06-10 15:15:08 -07003082
Bookatzc8c44962017-05-11 12:12:54 -07003083
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003084 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003085 long fullWakeLockTimeTotal = 0;
3086 long partialWakeLockTimeTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003087
Evan Millar22ac0432009-03-31 11:33:18 -07003088 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003089 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003090
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003091 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3092 = u.getWakelockStats();
3093 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3094 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003095
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003096 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3097 if (fullWakeTimer != null) {
3098 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3099 which);
3100 }
3101
3102 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3103 if (partialWakeTimer != null) {
3104 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3105 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003106 }
3107 }
3108 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003109
3110 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003111 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3112 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3113 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3114 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3115 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3116 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3117 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3118 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003119 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3120 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003121 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3122 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003123 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3124 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003125
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003126 // Dump Modem controller stats
3127 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3128 getModemControllerActivity(), which);
3129
Adam Lesinskie283d332015-04-16 12:29:25 -07003130 // Dump Wifi controller stats
3131 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3132 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003133 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003134 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003135
3136 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3137 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003138
3139 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003140 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3141 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003143 // Dump misc stats
3144 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003145 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003146 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003147 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003148 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003149 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003150 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3151 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003152 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003153 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3154 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3155 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3156 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003157 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003158
Dianne Hackborn617f8772009-03-31 15:04:46 -07003159 // Dump screen brightness stats
3160 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3161 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003162 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003163 }
3164 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003165
Dianne Hackborn627bba72009-03-24 22:32:56 -07003166 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003167 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3168 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003169 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003170 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003171 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003172 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003173 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003174 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003175 args[i] = getPhoneSignalStrengthCount(i, which);
3176 }
3177 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003178
Dianne Hackborn627bba72009-03-24 22:32:56 -07003179 // Dump network type stats
3180 args = new Object[NUM_DATA_CONNECTION_TYPES];
3181 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003182 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003183 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003184 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3185 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3186 args[i] = getPhoneDataConnectionCount(i, which);
3187 }
3188 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003189
3190 // Dump wifi state stats
3191 args = new Object[NUM_WIFI_STATES];
3192 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003193 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003194 }
3195 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3196 for (int i=0; i<NUM_WIFI_STATES; i++) {
3197 args[i] = getWifiStateCount(i, which);
3198 }
3199 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3200
Dianne Hackborn3251b902014-06-20 14:40:53 -07003201 // Dump wifi suppl state stats
3202 args = new Object[NUM_WIFI_SUPPL_STATES];
3203 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3204 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3205 }
3206 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3207 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3208 args[i] = getWifiSupplStateCount(i, which);
3209 }
3210 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3211
3212 // Dump wifi signal strength stats
3213 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3214 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3215 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3216 }
3217 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3218 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3219 args[i] = getWifiSignalStrengthCount(i, which);
3220 }
3221 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3222
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003223 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003224 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003225 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003226 }
Bookatzc8c44962017-05-11 12:12:54 -07003227
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003228 if (which == STATS_SINCE_UNPLUGGED) {
3229 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3230 getDischargeStartLevel()-getDischargeCurrentLevel(),
3231 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003232 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
3233 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003234 } else {
3235 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3236 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003237 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003238 getDischargeAmountScreenOffSinceCharge(),
3239 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003240 }
Bookatzc8c44962017-05-11 12:12:54 -07003241
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003242 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003243 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003244 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003245 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003246 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003247 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003248 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3249 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003250 }
Evan Millarc64edde2009-04-18 12:26:32 -07003251 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003252 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003253 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003254 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3255 // Not doing the regular wake lock formatting to remain compatible
3256 // with the old checkin format.
3257 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3258 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003259 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003260 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003261 }
3262 }
Evan Millarc64edde2009-04-18 12:26:32 -07003263 }
Bookatzc8c44962017-05-11 12:12:54 -07003264
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003265 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003266 helper.create(this);
3267 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003268 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003269 if (sippers != null && sippers.size() > 0) {
3270 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3271 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003272 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003273 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3274 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3275 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003276 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003277 int uid = 0;
3278 String label;
3279 switch (bs.drainType) {
3280 case IDLE:
3281 label="idle";
3282 break;
3283 case CELL:
3284 label="cell";
3285 break;
3286 case PHONE:
3287 label="phone";
3288 break;
3289 case WIFI:
3290 label="wifi";
3291 break;
3292 case BLUETOOTH:
3293 label="blue";
3294 break;
3295 case SCREEN:
3296 label="scrn";
3297 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003298 case FLASHLIGHT:
3299 label="flashlight";
3300 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003301 case APP:
3302 uid = bs.uidObj.getUid();
3303 label = "uid";
3304 break;
3305 case USER:
3306 uid = UserHandle.getUid(bs.userId, 0);
3307 label = "user";
3308 break;
3309 case UNACCOUNTED:
3310 label = "unacc";
3311 break;
3312 case OVERCOUNTED:
3313 label = "over";
3314 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003315 case CAMERA:
3316 label = "camera";
3317 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003318 default:
3319 label = "???";
3320 }
3321 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07003322 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003323 }
3324 }
3325
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003326 final long[] cpuFreqs = getCpuFreqs();
3327 if (cpuFreqs != null) {
3328 sb.setLength(0);
3329 for (int i = 0; i < cpuFreqs.length; ++i) {
3330 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3331 }
3332 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3333 }
3334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003335 for (int iu = 0; iu < NU; iu++) {
3336 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003337 if (reqUid >= 0 && uid != reqUid) {
3338 continue;
3339 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003340 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003343 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3344 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3345 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3346 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3347 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3348 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3349 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3350 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003351 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003352 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3353 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003354 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003355 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3356 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003357 // Background data transfers
3358 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3359 which);
3360 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3361 which);
3362 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3363 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3364 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3365 which);
3366 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3367 which);
3368 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3369 which);
3370 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3371 which);
3372
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003373 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3374 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003375 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003376 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3377 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3378 || wifiBytesBgTx > 0
3379 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3380 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003381 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3382 wifiBytesRx, wifiBytesTx,
3383 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003384 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003385 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003386 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3387 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3388 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3389 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003390 }
3391
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003392 // Dump modem controller data, per UID.
3393 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3394 u.getModemControllerActivity(), which);
3395
3396 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003397 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3398 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3399 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003400 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3401 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003402 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3403 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3404 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003405 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003406 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003407 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3408 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003409 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3410 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003411 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003412 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003413 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003415 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3416 u.getWifiControllerActivity(), which);
3417
Bookatz867c0d72017-03-07 18:23:42 -08003418 final Timer bleTimer = u.getBluetoothScanTimer();
3419 if (bleTimer != null) {
3420 // Convert from microseconds to milliseconds with rounding
3421 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3422 / 1000;
3423 if (totalTime != 0) {
3424 final int count = bleTimer.getCountLocked(which);
3425 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3426 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
3427 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
3428 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3429 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3430 final long actualTimeBg = bleTimerBg != null ?
3431 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatz956f36bf2017-04-28 09:48:17 -07003432 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3433 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003434 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatz956f36bf2017-04-28 09:48:17 -07003435 countBg, actualTime, actualTimeBg, resultCount);
Bookatz867c0d72017-03-07 18:23:42 -08003436 }
3437 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003438
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003439 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3440 u.getBluetoothControllerActivity(), which);
3441
Dianne Hackborn617f8772009-03-31 15:04:46 -07003442 if (u.hasUserActivity()) {
3443 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3444 boolean hasData = false;
3445 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3446 int val = u.getUserActivityCount(i, which);
3447 args[i] = val;
3448 if (val != 0) hasData = true;
3449 }
3450 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003451 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003452 }
3453 }
Bookatzc8c44962017-05-11 12:12:54 -07003454
3455 if (u.getAggregatedPartialWakelockTimer() != null) {
3456 final Timer timer = u.getAggregatedPartialWakelockTimer();
3457 // Convert from microseconds to milliseconds with rounding
3458 final long totTimeMs = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3459 final Timer bgTimer = timer.getSubTimer();
3460 final long bgTimeMs = bgTimer != null ?
3461 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
3462 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3463 }
3464
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003465 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3466 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3467 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3468 String linePrefix = "";
3469 sb.setLength(0);
3470 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3471 rawRealtime, "f", which, linePrefix);
3472 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
3473 rawRealtime, "p", which, linePrefix);
3474 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3475 rawRealtime, "w", which, linePrefix);
3476
3477 // Only log if we had at lease one wakelock...
3478 if (sb.length() > 0) {
3479 String name = wakelocks.keyAt(iw);
3480 if (name.indexOf(',') >= 0) {
3481 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003482 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003483 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003484 }
3485 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003486
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003487 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3488 for (int isy=syncs.size()-1; isy>=0; isy--) {
3489 final Timer timer = syncs.valueAt(isy);
3490 // Convert from microseconds to milliseconds with rounding
3491 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3492 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003493 final Timer bgTimer = timer.getSubTimer();
3494 final long bgTime = bgTimer != null ?
3495 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
3496 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003497 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003498 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003499 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003500 }
3501 }
3502
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003503 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3504 for (int ij=jobs.size()-1; ij>=0; ij--) {
3505 final Timer timer = jobs.valueAt(ij);
3506 // Convert from microseconds to milliseconds with rounding
3507 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3508 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003509 final Timer bgTimer = timer.getSubTimer();
3510 final long bgTime = bgTimer != null ?
3511 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
3512 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003513 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003514 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003515 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003516 }
3517 }
3518
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003519 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3520 rawRealtime, which);
3521 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3522 rawRealtime, which);
3523 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3524 rawRealtime, which);
3525 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3526 rawRealtime, which);
3527
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003528 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3529 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003530 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003531 final Uid.Sensor se = sensors.valueAt(ise);
3532 final int sensorNumber = sensors.keyAt(ise);
3533 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003534 if (timer != null) {
3535 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003536 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3537 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003538 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003539 final int count = timer.getCountLocked(which);
3540 final Timer bgTimer = se.getSensorBackgroundTime();
3541 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
3542 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
3543 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3544 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3545 final long bgActualTime = bgTimer != null ?
3546 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3547 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3548 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 }
3551 }
3552
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003553 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3554 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003555
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003556 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3557 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003558
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003559 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003560 long totalStateTime = 0;
3561 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003562 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3563 totalStateTime += time;
3564 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003565 }
3566 if (totalStateTime > 0) {
3567 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3568 }
3569
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003570 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3571 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003572 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003573 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003574 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003575 }
3576
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003577 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3578 // If total cpuFreqTimes is null, then we don't need to check for screenOffCpuFreqTimes.
3579 if (cpuFreqTimeMs != null) {
3580 sb.setLength(0);
3581 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3582 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
3583 }
3584 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3585 if (screenOffCpuFreqTimeMs != null) {
3586 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3587 sb.append("," + screenOffCpuFreqTimeMs[i]);
3588 }
3589 } else {
3590 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3591 sb.append(",0");
3592 }
3593 }
3594 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
3595 cpuFreqTimeMs.length, sb.toString());
3596 }
3597
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003598 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3599 = u.getProcessStats();
3600 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3601 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003602
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003603 final long userMillis = ps.getUserTime(which);
3604 final long systemMillis = ps.getSystemTime(which);
3605 final long foregroundMillis = ps.getForegroundTime(which);
3606 final int starts = ps.getStarts(which);
3607 final int numCrashes = ps.getNumCrashes(which);
3608 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003609
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003610 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3611 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003612 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
3613 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 }
3615 }
3616
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003617 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3618 = u.getPackageStats();
3619 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3620 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3621 int wakeups = 0;
3622 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3623 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003624 int count = alarms.valueAt(iwa).getCountLocked(which);
3625 wakeups += count;
3626 String name = alarms.keyAt(iwa).replace(',', '_');
3627 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003628 }
3629 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3630 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3631 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3632 final long startTime = ss.getStartTime(batteryUptime, which);
3633 final int starts = ss.getStarts(which);
3634 final int launches = ss.getLaunches(which);
3635 if (startTime != 0 || starts != 0 || launches != 0) {
3636 dumpLine(pw, uid, category, APK_DATA,
3637 wakeups, // wakeup alarms
3638 packageStats.keyAt(ipkg), // Apk
3639 serviceStats.keyAt(isvc), // service
3640 startTime / 1000, // time spent started, in ms
3641 starts,
3642 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003643 }
3644 }
3645 }
3646 }
3647 }
3648
Dianne Hackborn81038902012-11-26 17:04:09 -08003649 static final class TimerEntry {
3650 final String mName;
3651 final int mId;
3652 final BatteryStats.Timer mTimer;
3653 final long mTime;
3654 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3655 mName = name;
3656 mId = id;
3657 mTimer = timer;
3658 mTime = time;
3659 }
3660 }
3661
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003662 private void printmAh(PrintWriter printer, double power) {
3663 printer.print(BatteryStatsHelper.makemAh(power));
3664 }
3665
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003666 private void printmAh(StringBuilder sb, double power) {
3667 sb.append(BatteryStatsHelper.makemAh(power));
3668 }
3669
Dianne Hackbornd953c532014-08-16 18:17:38 -07003670 /**
3671 * Temporary for settings.
3672 */
3673 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3674 int reqUid) {
3675 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3676 }
3677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003678 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003679 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003680 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3682 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3683 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684
3685 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3686 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3687 final long totalRealtime = computeRealtime(rawRealtime, which);
3688 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003689 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3690 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3691 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003692 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3693 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003694
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003695 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003696
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003697 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003698 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003700 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3701 if (estimatedBatteryCapacity > 0) {
3702 sb.setLength(0);
3703 sb.append(prefix);
3704 sb.append(" Estimated battery capacity: ");
3705 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3706 sb.append(" mAh");
3707 pw.println(sb.toString());
3708 }
3709
Jocelyn Dangc627d102017-04-14 13:15:14 -07003710 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
3711 if (minLearnedBatteryCapacity > 0) {
3712 sb.setLength(0);
3713 sb.append(prefix);
3714 sb.append(" Min learned battery capacity: ");
3715 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
3716 sb.append(" mAh");
3717 pw.println(sb.toString());
3718 }
3719 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
3720 if (maxLearnedBatteryCapacity > 0) {
3721 sb.setLength(0);
3722 sb.append(prefix);
3723 sb.append(" Max learned battery capacity: ");
3724 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
3725 sb.append(" mAh");
3726 pw.println(sb.toString());
3727 }
3728
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003729 sb.setLength(0);
3730 sb.append(prefix);
3731 sb.append(" Time on battery: ");
3732 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3733 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3734 sb.append(") realtime, ");
3735 formatTimeMs(sb, whichBatteryUptime / 1000);
3736 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3737 sb.append(") uptime");
3738 pw.println(sb.toString());
3739 sb.setLength(0);
3740 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003741 sb.append(" Time on battery screen off: ");
3742 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3743 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3744 sb.append(") realtime, ");
3745 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3746 sb.append("(");
3747 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3748 sb.append(") uptime");
3749 pw.println(sb.toString());
3750 sb.setLength(0);
3751 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003752 sb.append(" Total run time: ");
3753 formatTimeMs(sb, totalRealtime / 1000);
3754 sb.append("realtime, ");
3755 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003756 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003757 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003758 if (batteryTimeRemaining >= 0) {
3759 sb.setLength(0);
3760 sb.append(prefix);
3761 sb.append(" Battery time remaining: ");
3762 formatTimeMs(sb, batteryTimeRemaining / 1000);
3763 pw.println(sb.toString());
3764 }
3765 if (chargeTimeRemaining >= 0) {
3766 sb.setLength(0);
3767 sb.append(prefix);
3768 sb.append(" Charge time remaining: ");
3769 formatTimeMs(sb, chargeTimeRemaining / 1000);
3770 pw.println(sb.toString());
3771 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003772
3773 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3774 final long dischargeCount = dischargeCounter.getCountLocked(which);
3775 if (dischargeCount >= 0) {
3776 sb.setLength(0);
3777 sb.append(prefix);
3778 sb.append(" Discharge: ");
3779 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3780 sb.append(" mAh");
3781 pw.println(sb.toString());
3782 }
3783
3784 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3785 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3786 if (dischargeScreenOffCount >= 0) {
3787 sb.setLength(0);
3788 sb.append(prefix);
3789 sb.append(" Screen off discharge: ");
3790 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3791 sb.append(" mAh");
3792 pw.println(sb.toString());
3793 }
3794
3795 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3796 if (dischargeScreenOnCount >= 0) {
3797 sb.setLength(0);
3798 sb.append(prefix);
3799 sb.append(" Screen on discharge: ");
3800 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3801 sb.append(" mAh");
3802 pw.println(sb.toString());
3803 }
3804
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003805 pw.print(" Start clock time: ");
3806 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3807
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003808 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003809 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003810 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003811 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3812 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003813 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003814 rawRealtime, which);
3815 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3816 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003817 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003818 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003819 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3820 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3821 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003822 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003823 sb.append(prefix);
3824 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3825 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003826 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003827 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3828 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003829 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003830 pw.println(sb.toString());
3831 sb.setLength(0);
3832 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003833 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003834 boolean didOne = false;
3835 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003836 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003837 if (time == 0) {
3838 continue;
3839 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003840 sb.append("\n ");
3841 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003842 didOne = true;
3843 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3844 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003845 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003846 sb.append("(");
3847 sb.append(formatRatioLocked(time, screenOnTime));
3848 sb.append(")");
3849 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003850 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003851 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003852 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003853 sb.setLength(0);
3854 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003855 sb.append(" Power save mode enabled: ");
3856 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003857 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003858 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003859 sb.append(")");
3860 pw.println(sb.toString());
3861 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003862 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003863 sb.setLength(0);
3864 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003865 sb.append(" Device light idling: ");
3866 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003867 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003868 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3869 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003870 sb.append("x");
3871 pw.println(sb.toString());
3872 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003873 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003874 sb.setLength(0);
3875 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003876 sb.append(" Idle mode light time: ");
3877 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003878 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003879 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3880 sb.append(") ");
3881 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003882 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003883 sb.append(" -- longest ");
3884 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3885 pw.println(sb.toString());
3886 }
3887 if (deviceIdlingTime != 0) {
3888 sb.setLength(0);
3889 sb.append(prefix);
3890 sb.append(" Device full idling: ");
3891 formatTimeMs(sb, deviceIdlingTime / 1000);
3892 sb.append("(");
3893 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003894 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003895 sb.append("x");
3896 pw.println(sb.toString());
3897 }
3898 if (deviceIdleModeFullTime != 0) {
3899 sb.setLength(0);
3900 sb.append(prefix);
3901 sb.append(" Idle mode full time: ");
3902 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3903 sb.append("(");
3904 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3905 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003906 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003907 sb.append("x");
3908 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003909 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003910 pw.println(sb.toString());
3911 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003912 if (phoneOnTime != 0) {
3913 sb.setLength(0);
3914 sb.append(prefix);
3915 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3916 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003917 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003918 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003919 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003920 if (connChanges != 0) {
3921 pw.print(prefix);
3922 pw.print(" Connectivity changes: "); pw.println(connChanges);
3923 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003924
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003925 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003926 long fullWakeLockTimeTotalMicros = 0;
3927 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003928
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003929 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003930
Evan Millar22ac0432009-03-31 11:33:18 -07003931 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003932 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003933
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003934 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3935 = u.getWakelockStats();
3936 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3937 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003938
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003939 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3940 if (fullWakeTimer != null) {
3941 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3942 rawRealtime, which);
3943 }
3944
3945 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3946 if (partialWakeTimer != null) {
3947 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3948 rawRealtime, which);
3949 if (totalTimeMicros > 0) {
3950 if (reqUid < 0) {
3951 // Only show the ordered list of all wake
3952 // locks if the caller is not asking for data
3953 // about a specific uid.
3954 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3955 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003956 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003957 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003958 }
3959 }
3960 }
3961 }
Bookatzc8c44962017-05-11 12:12:54 -07003962
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003963 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3964 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3965 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3966 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3967 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3968 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3969 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3970 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08003971 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3972 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003973
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003974 if (fullWakeLockTimeTotalMicros != 0) {
3975 sb.setLength(0);
3976 sb.append(prefix);
3977 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3978 (fullWakeLockTimeTotalMicros + 500) / 1000);
3979 pw.println(sb.toString());
3980 }
3981
3982 if (partialWakeLockTimeTotalMicros != 0) {
3983 sb.setLength(0);
3984 sb.append(prefix);
3985 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3986 (partialWakeLockTimeTotalMicros + 500) / 1000);
3987 pw.println(sb.toString());
3988 }
3989
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003990 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003991 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3992 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3993 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3994 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003995 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003996 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003997 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003998 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003999 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004000 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004001 if (time == 0) {
4002 continue;
4003 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004004 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004005 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004006 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08004007 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004008 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004009 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004010 sb.append("(");
4011 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004012 sb.append(") ");
4013 sb.append(getPhoneSignalStrengthCount(i, which));
4014 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004015 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004016 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004017 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004018
4019 sb.setLength(0);
4020 sb.append(prefix);
4021 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004022 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07004023 pw.println(sb.toString());
4024
Dianne Hackborn627bba72009-03-24 22:32:56 -07004025 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004026 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004027 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004028 didOne = false;
4029 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004030 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004031 if (time == 0) {
4032 continue;
4033 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004034 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004035 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004036 didOne = true;
4037 sb.append(DATA_CONNECTION_NAMES[i]);
4038 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004039 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004040 sb.append("(");
4041 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004042 sb.append(") ");
4043 sb.append(getPhoneDataConnectionCount(i, which));
4044 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004045 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004046 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004047 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004048
4049 sb.setLength(0);
4050 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08004051 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004052 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004053 formatTimeMs(sb, mobileActiveTime / 1000);
4054 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4055 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
4056 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004057 pw.println(sb.toString());
4058
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004059 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
4060 if (mobileActiveUnknownTime != 0) {
4061 sb.setLength(0);
4062 sb.append(prefix);
4063 sb.append(" Mobile radio active unknown time: ");
4064 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
4065 sb.append("(");
4066 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
4067 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
4068 sb.append("x");
4069 pw.println(sb.toString());
4070 }
4071
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004072 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
4073 if (mobileActiveAdjustedTime != 0) {
4074 sb.setLength(0);
4075 sb.append(prefix);
4076 sb.append(" Mobile radio active adjusted time: ");
4077 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
4078 sb.append("(");
4079 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
4080 sb.append(")");
4081 pw.println(sb.toString());
4082 }
4083
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004084 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
4085
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004086 pw.print(prefix);
4087 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
4088 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
4089 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
4090 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004091 sb.setLength(0);
4092 sb.append(prefix);
4093 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
4094 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
4095 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
4096 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004097 sb.append(")");
4098 pw.println(sb.toString());
4099
4100 sb.setLength(0);
4101 sb.append(prefix);
4102 sb.append(" Wifi states:");
4103 didOne = false;
4104 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004105 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004106 if (time == 0) {
4107 continue;
4108 }
4109 sb.append("\n ");
4110 didOne = true;
4111 sb.append(WIFI_STATE_NAMES[i]);
4112 sb.append(" ");
4113 formatTimeMs(sb, time/1000);
4114 sb.append("(");
4115 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4116 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004117 sb.append(getWifiStateCount(i, which));
4118 sb.append("x");
4119 }
4120 if (!didOne) sb.append(" (no activity)");
4121 pw.println(sb.toString());
4122
4123 sb.setLength(0);
4124 sb.append(prefix);
4125 sb.append(" Wifi supplicant states:");
4126 didOne = false;
4127 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4128 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4129 if (time == 0) {
4130 continue;
4131 }
4132 sb.append("\n ");
4133 didOne = true;
4134 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4135 sb.append(" ");
4136 formatTimeMs(sb, time/1000);
4137 sb.append("(");
4138 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4139 sb.append(") ");
4140 sb.append(getWifiSupplStateCount(i, which));
4141 sb.append("x");
4142 }
4143 if (!didOne) sb.append(" (no activity)");
4144 pw.println(sb.toString());
4145
4146 sb.setLength(0);
4147 sb.append(prefix);
4148 sb.append(" Wifi signal levels:");
4149 didOne = false;
4150 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
4151 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4152 if (time == 0) {
4153 continue;
4154 }
4155 sb.append("\n ");
4156 sb.append(prefix);
4157 didOne = true;
4158 sb.append("level(");
4159 sb.append(i);
4160 sb.append(") ");
4161 formatTimeMs(sb, time/1000);
4162 sb.append("(");
4163 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4164 sb.append(") ");
4165 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004166 sb.append("x");
4167 }
4168 if (!didOne) sb.append(" (no activity)");
4169 pw.println(sb.toString());
4170
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004171 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004172
Adam Lesinski50e47602015-12-04 17:04:54 -08004173 pw.print(prefix);
4174 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4175 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4176
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004177 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4178 sb.setLength(0);
4179 sb.append(prefix);
4180 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4181 pw.println(sb.toString());
4182
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004183 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4184 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004185
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004186 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004187
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004188 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004189 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004190 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004191 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004192 pw.println(getDischargeStartLevel());
4193 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4194 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004195 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004196 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004197 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004198 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004199 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004200 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004201 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004202 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4203 pw.println(getDischargeAmountScreenOn());
4204 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4205 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004206 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004207 } else {
4208 pw.print(prefix); pw.println(" Device battery use since last full charge");
4209 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
4210 pw.println(getLowDischargeAmountSinceCharge());
4211 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
4212 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004213 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4214 pw.println(getDischargeAmountScreenOnSinceCharge());
4215 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4216 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004217 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004218 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004219
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004220 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004221 helper.create(this);
4222 helper.refreshStats(which, UserHandle.USER_ALL);
4223 List<BatterySipper> sippers = helper.getUsageList();
4224 if (sippers != null && sippers.size() > 0) {
4225 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4226 pw.print(prefix); pw.print(" Capacity: ");
4227 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004228 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004229 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4230 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4231 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4232 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004233 pw.println();
4234 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004235 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004236 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004237 switch (bs.drainType) {
4238 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004239 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004240 break;
4241 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004242 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004243 break;
4244 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004245 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004246 break;
4247 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004248 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004249 break;
4250 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004251 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004252 break;
4253 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004254 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004255 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004256 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004257 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004258 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004259 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004260 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004261 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004262 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004263 break;
4264 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004265 pw.print(" User "); pw.print(bs.userId);
4266 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004267 break;
4268 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004269 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004270 break;
4271 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004272 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004273 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004274 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004275 pw.print(" Camera: ");
4276 break;
4277 default:
4278 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004279 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004280 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004281 printmAh(pw, bs.totalPowerMah);
4282
Adam Lesinski57123002015-06-12 16:12:07 -07004283 if (bs.usagePowerMah != bs.totalPowerMah) {
4284 // If the usage (generic power) isn't the whole amount, we list out
4285 // what components are involved in the calculation.
4286
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004287 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004288 if (bs.usagePowerMah != 0) {
4289 pw.print(" usage=");
4290 printmAh(pw, bs.usagePowerMah);
4291 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004292 if (bs.cpuPowerMah != 0) {
4293 pw.print(" cpu=");
4294 printmAh(pw, bs.cpuPowerMah);
4295 }
4296 if (bs.wakeLockPowerMah != 0) {
4297 pw.print(" wake=");
4298 printmAh(pw, bs.wakeLockPowerMah);
4299 }
4300 if (bs.mobileRadioPowerMah != 0) {
4301 pw.print(" radio=");
4302 printmAh(pw, bs.mobileRadioPowerMah);
4303 }
4304 if (bs.wifiPowerMah != 0) {
4305 pw.print(" wifi=");
4306 printmAh(pw, bs.wifiPowerMah);
4307 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004308 if (bs.bluetoothPowerMah != 0) {
4309 pw.print(" bt=");
4310 printmAh(pw, bs.bluetoothPowerMah);
4311 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004312 if (bs.gpsPowerMah != 0) {
4313 pw.print(" gps=");
4314 printmAh(pw, bs.gpsPowerMah);
4315 }
4316 if (bs.sensorPowerMah != 0) {
4317 pw.print(" sensor=");
4318 printmAh(pw, bs.sensorPowerMah);
4319 }
4320 if (bs.cameraPowerMah != 0) {
4321 pw.print(" camera=");
4322 printmAh(pw, bs.cameraPowerMah);
4323 }
4324 if (bs.flashlightPowerMah != 0) {
4325 pw.print(" flash=");
4326 printmAh(pw, bs.flashlightPowerMah);
4327 }
4328 pw.print(" )");
4329 }
4330 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004331 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004332 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004333 }
4334
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004335 sippers = helper.getMobilemsppList();
4336 if (sippers != null && sippers.size() > 0) {
4337 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004338 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004339 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004340 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004341 sb.setLength(0);
4342 sb.append(prefix); sb.append(" Uid ");
4343 UserHandle.formatUid(sb, bs.uidObj.getUid());
4344 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4345 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4346 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004347 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004348 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004349 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004350 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004351 sb.setLength(0);
4352 sb.append(prefix);
4353 sb.append(" TOTAL TIME: ");
4354 formatTimeMs(sb, totalTime);
4355 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4356 sb.append(")");
4357 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004358 pw.println();
4359 }
4360
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004361 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4362 @Override
4363 public int compare(TimerEntry lhs, TimerEntry rhs) {
4364 long lhsTime = lhs.mTime;
4365 long rhsTime = rhs.mTime;
4366 if (lhsTime < rhsTime) {
4367 return 1;
4368 }
4369 if (lhsTime > rhsTime) {
4370 return -1;
4371 }
4372 return 0;
4373 }
4374 };
4375
4376 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004377 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4378 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004379 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004380 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4381 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4382 : kernelWakelocks.entrySet()) {
4383 final BatteryStats.Timer timer = ent.getValue();
4384 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004385 if (totalTimeMillis > 0) {
4386 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4387 }
4388 }
4389 if (ktimers.size() > 0) {
4390 Collections.sort(ktimers, timerComparator);
4391 pw.print(prefix); pw.println(" All kernel wake locks:");
4392 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004393 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004394 String linePrefix = ": ";
4395 sb.setLength(0);
4396 sb.append(prefix);
4397 sb.append(" Kernel Wake lock ");
4398 sb.append(timer.mName);
4399 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4400 which, linePrefix);
4401 if (!linePrefix.equals(": ")) {
4402 sb.append(" realtime");
4403 // Only print out wake locks that were held
4404 pw.println(sb.toString());
4405 }
4406 }
4407 pw.println();
4408 }
4409 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004410
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004411 if (timers.size() > 0) {
4412 Collections.sort(timers, timerComparator);
4413 pw.print(prefix); pw.println(" All partial wake locks:");
4414 for (int i=0; i<timers.size(); i++) {
4415 TimerEntry timer = timers.get(i);
4416 sb.setLength(0);
4417 sb.append(" Wake lock ");
4418 UserHandle.formatUid(sb, timer.mId);
4419 sb.append(" ");
4420 sb.append(timer.mName);
4421 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4422 sb.append(" realtime");
4423 pw.println(sb.toString());
4424 }
4425 timers.clear();
4426 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004427 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004428
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004429 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004430 if (wakeupReasons.size() > 0) {
4431 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004432 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004433 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004434 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004435 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4436 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004437 }
4438 Collections.sort(reasons, timerComparator);
4439 for (int i=0; i<reasons.size(); i++) {
4440 TimerEntry timer = reasons.get(i);
4441 String linePrefix = ": ";
4442 sb.setLength(0);
4443 sb.append(prefix);
4444 sb.append(" Wakeup reason ");
4445 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004446 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4447 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004448 pw.println(sb.toString());
4449 }
4450 pw.println();
4451 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004452 }
Evan Millar22ac0432009-03-31 11:33:18 -07004453
James Carr2dd7e5e2016-07-20 18:48:39 -07004454 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
4455 pw.println("Memory Stats");
4456 for (int i = 0; i < mMemoryStats.size(); i++) {
4457 sb.setLength(0);
4458 sb.append("Bandwidth ");
4459 sb.append(mMemoryStats.keyAt(i));
4460 sb.append(" Time ");
4461 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4462 pw.println(sb.toString());
4463 }
4464
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004465 final long[] cpuFreqs = getCpuFreqs();
4466 if (cpuFreqs != null) {
4467 sb.setLength(0);
4468 sb.append("CPU freqs:");
4469 for (int i = 0; i < cpuFreqs.length; ++i) {
4470 sb.append(" " + cpuFreqs[i]);
4471 }
4472 pw.println(sb.toString());
4473 }
4474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004475 for (int iu=0; iu<NU; iu++) {
4476 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004477 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004478 continue;
4479 }
Bookatzc8c44962017-05-11 12:12:54 -07004480
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004481 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004482
4483 pw.print(prefix);
4484 pw.print(" ");
4485 UserHandle.formatUid(pw, uid);
4486 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004487 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004488
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004489 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4490 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4491 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4492 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004493 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4494 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4495
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004496 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4497 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004498 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4499 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004500
4501 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4502 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4503
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004504 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4505 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4506 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08004507 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
4508 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4509 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
4510 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004511 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004512
Adam Lesinski5f056f62016-07-14 16:56:08 -07004513 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4514 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4515
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004516 if (mobileRxBytes > 0 || mobileTxBytes > 0
4517 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004518 pw.print(prefix); pw.print(" Mobile network: ");
4519 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004520 pw.print(formatBytesLocked(mobileTxBytes));
4521 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4522 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004524 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4525 sb.setLength(0);
4526 sb.append(prefix); sb.append(" Mobile radio active: ");
4527 formatTimeMs(sb, uidMobileActiveTime / 1000);
4528 sb.append("(");
4529 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4530 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4531 long packets = mobileRxPackets + mobileTxPackets;
4532 if (packets == 0) {
4533 packets = 1;
4534 }
4535 sb.append(" @ ");
4536 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4537 sb.append(" mspp");
4538 pw.println(sb.toString());
4539 }
4540
Adam Lesinski5f056f62016-07-14 16:56:08 -07004541 if (mobileWakeup > 0) {
4542 sb.setLength(0);
4543 sb.append(prefix);
4544 sb.append(" Mobile radio AP wakeups: ");
4545 sb.append(mobileWakeup);
4546 pw.println(sb.toString());
4547 }
4548
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004549 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4550 u.getModemControllerActivity(), which);
4551
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004552 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004553 pw.print(prefix); pw.print(" Wi-Fi network: ");
4554 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004555 pw.print(formatBytesLocked(wifiTxBytes));
4556 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4557 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004558 }
4559
Dianne Hackborn62793e42015-03-09 11:15:41 -07004560 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08004561 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004562 || uidWifiRunningTime != 0) {
4563 sb.setLength(0);
4564 sb.append(prefix); sb.append(" Wifi Running: ");
4565 formatTimeMs(sb, uidWifiRunningTime / 1000);
4566 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4567 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07004568 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004569 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4570 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4571 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08004572 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004573 formatTimeMs(sb, wifiScanTime / 1000);
4574 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004575 whichBatteryRealtime)); sb.append(") ");
4576 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08004577 sb.append("x\n");
4578 // actual and background times are unpooled and since reset (regardless of 'which')
4579 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
4580 formatTimeMs(sb, wifiScanActualTime / 1000);
4581 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
4582 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4583 sb.append(") ");
4584 sb.append(wifiScanCount);
4585 sb.append("x\n");
4586 sb.append(prefix); sb.append(" Background Wifi Scan: ");
4587 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
4588 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
4589 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4590 sb.append(") ");
4591 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07004592 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004593 pw.println(sb.toString());
4594 }
4595
Adam Lesinski5f056f62016-07-14 16:56:08 -07004596 if (wifiWakeup > 0) {
4597 sb.setLength(0);
4598 sb.append(prefix);
4599 sb.append(" WiFi AP wakeups: ");
4600 sb.append(wifiWakeup);
4601 pw.println(sb.toString());
4602 }
4603
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004604 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4605 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004606
Adam Lesinski50e47602015-12-04 17:04:54 -08004607 if (btRxBytes > 0 || btTxBytes > 0) {
4608 pw.print(prefix); pw.print(" Bluetooth network: ");
4609 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4610 pw.print(formatBytesLocked(btTxBytes));
4611 pw.println(" sent");
4612 }
4613
Bookatz867c0d72017-03-07 18:23:42 -08004614 final Timer bleTimer = u.getBluetoothScanTimer();
4615 if (bleTimer != null) {
4616 // Convert from microseconds to milliseconds with rounding
4617 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
4618 / 1000;
4619 if (totalTimeMs != 0) {
4620 final int count = bleTimer.getCountLocked(which);
4621 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
4622 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
4623 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
4624 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4625 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
4626 final long actualTimeMsBg = bleTimerBg != null ?
4627 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatz956f36bf2017-04-28 09:48:17 -07004628 final int resultCount = u.getBluetoothScanResultCounter() != null ?
4629 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004630
4631 sb.setLength(0);
4632 sb.append(prefix);
4633 sb.append(" ");
4634 sb.append("Bluetooth Scan");
4635 sb.append(": ");
4636 if (actualTimeMs != totalTimeMs) {
4637 formatTimeMs(sb, totalTimeMs);
4638 sb.append("blamed realtime, ");
4639 }
4640 formatTimeMs(sb, actualTimeMs); // since reset, regardless of 'which'
4641 sb.append("realtime (");
4642 sb.append(count);
4643 sb.append(" times)");
4644 if (bleTimer.isRunningLocked()) {
4645 sb.append(" (running)");
4646 }
4647 if (actualTimeMsBg != 0 || countBg > 0) {
4648 sb.append(", ");
4649 formatTimeMs(sb, actualTimeMsBg); // since reset, regardless of 'which'
4650 sb.append("background (");
4651 sb.append(countBg);
4652 sb.append(" times)");
4653 }
Bookatz956f36bf2017-04-28 09:48:17 -07004654 sb.append("; Results count ");
4655 sb.append(resultCount);
Bookatz867c0d72017-03-07 18:23:42 -08004656 pw.println(sb.toString());
4657 uidActivity = true;
4658 }
4659 }
4660
4661
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004662
Dianne Hackborn617f8772009-03-31 15:04:46 -07004663 if (u.hasUserActivity()) {
4664 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004665 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004666 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004667 if (val != 0) {
4668 if (!hasData) {
4669 sb.setLength(0);
4670 sb.append(" User activity: ");
4671 hasData = true;
4672 } else {
4673 sb.append(", ");
4674 }
4675 sb.append(val);
4676 sb.append(" ");
4677 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4678 }
4679 }
4680 if (hasData) {
4681 pw.println(sb.toString());
4682 }
4683 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004684
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004685 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4686 = u.getWakelockStats();
4687 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004688 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004689 int countWakelock = 0;
4690 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4691 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4692 String linePrefix = ": ";
4693 sb.setLength(0);
4694 sb.append(prefix);
4695 sb.append(" Wake lock ");
4696 sb.append(wakelocks.keyAt(iw));
4697 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4698 "full", which, linePrefix);
4699 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
4700 "partial", which, linePrefix);
4701 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4702 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004703 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4704 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004705 sb.append(" realtime");
4706 pw.println(sb.toString());
4707 uidActivity = true;
4708 countWakelock++;
4709
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004710 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4711 rawRealtime, which);
4712 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4713 rawRealtime, which);
4714 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4715 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004716 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004717 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004718 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004719 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07004720 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
4721 // pooled and therefore just a lower bound)
4722 long actualTotalPartialWakelock = 0;
4723 long actualBgPartialWakelock = 0;
4724 if (u.getAggregatedPartialWakelockTimer() != null) {
4725 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
4726 // Convert from microseconds to milliseconds with rounding
4727 actualTotalPartialWakelock =
4728 (aggTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4729 final Timer bgAggTimer = aggTimer.getSubTimer();
4730 actualBgPartialWakelock = bgAggTimer != null ?
4731 (bgAggTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
4732 }
4733
4734 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
4735 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
4736 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004737 sb.setLength(0);
4738 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004739 sb.append(" TOTAL wake: ");
4740 boolean needComma = false;
4741 if (totalFullWakelock != 0) {
4742 needComma = true;
4743 formatTimeMs(sb, totalFullWakelock);
4744 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004745 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004746 if (totalPartialWakelock != 0) {
4747 if (needComma) {
4748 sb.append(", ");
4749 }
4750 needComma = true;
4751 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07004752 sb.append("blamed partial");
4753 }
4754 if (actualTotalPartialWakelock != 0) {
4755 if (needComma) {
4756 sb.append(", ");
4757 }
4758 needComma = true;
4759 formatTimeMs(sb, actualTotalPartialWakelock);
4760 sb.append("actual partial");
4761 }
4762 if (actualBgPartialWakelock != 0) {
4763 if (needComma) {
4764 sb.append(", ");
4765 }
4766 needComma = true;
4767 formatTimeMs(sb, actualBgPartialWakelock);
4768 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004769 }
4770 if (totalWindowWakelock != 0) {
4771 if (needComma) {
4772 sb.append(", ");
4773 }
4774 needComma = true;
4775 formatTimeMs(sb, totalWindowWakelock);
4776 sb.append("window");
4777 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004778 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004779 if (needComma) {
4780 sb.append(",");
4781 }
4782 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004783 formatTimeMs(sb, totalDrawWakelock);
4784 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004785 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004786 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004787 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004788 }
4789 }
4790
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004791 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4792 for (int isy=syncs.size()-1; isy>=0; isy--) {
4793 final Timer timer = syncs.valueAt(isy);
4794 // Convert from microseconds to milliseconds with rounding
4795 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4796 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07004797 final Timer bgTimer = timer.getSubTimer();
4798 final long bgTime = bgTimer != null ?
4799 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
4800 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004801 sb.setLength(0);
4802 sb.append(prefix);
4803 sb.append(" Sync ");
4804 sb.append(syncs.keyAt(isy));
4805 sb.append(": ");
4806 if (totalTime != 0) {
4807 formatTimeMs(sb, totalTime);
4808 sb.append("realtime (");
4809 sb.append(count);
4810 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07004811 if (bgTime > 0) {
4812 sb.append(", ");
4813 formatTimeMs(sb, bgTime);
4814 sb.append("background (");
4815 sb.append(bgCount);
4816 sb.append(" times)");
4817 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004818 } else {
4819 sb.append("(not used)");
4820 }
4821 pw.println(sb.toString());
4822 uidActivity = true;
4823 }
4824
4825 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4826 for (int ij=jobs.size()-1; ij>=0; ij--) {
4827 final Timer timer = jobs.valueAt(ij);
4828 // Convert from microseconds to milliseconds with rounding
4829 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4830 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07004831 final Timer bgTimer = timer.getSubTimer();
4832 final long bgTime = bgTimer != null ?
4833 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
4834 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004835 sb.setLength(0);
4836 sb.append(prefix);
4837 sb.append(" Job ");
4838 sb.append(jobs.keyAt(ij));
4839 sb.append(": ");
4840 if (totalTime != 0) {
4841 formatTimeMs(sb, totalTime);
4842 sb.append("realtime (");
4843 sb.append(count);
4844 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07004845 if (bgTime > 0) {
4846 sb.append(", ");
4847 formatTimeMs(sb, bgTime);
4848 sb.append("background (");
4849 sb.append(bgCount);
4850 sb.append(" times)");
4851 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004852 } else {
4853 sb.append("(not used)");
4854 }
4855 pw.println(sb.toString());
4856 uidActivity = true;
4857 }
4858
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004859 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
4860 prefix, "Flashlight");
4861 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
4862 prefix, "Camera");
4863 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
4864 prefix, "Video");
4865 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
4866 prefix, "Audio");
4867
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004868 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4869 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004870 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004871 final Uid.Sensor se = sensors.valueAt(ise);
4872 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004873 sb.setLength(0);
4874 sb.append(prefix);
4875 sb.append(" Sensor ");
4876 int handle = se.getHandle();
4877 if (handle == Uid.Sensor.GPS) {
4878 sb.append("GPS");
4879 } else {
4880 sb.append(handle);
4881 }
4882 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004883
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004884 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004885 if (timer != null) {
4886 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08004887 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
4888 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004889 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08004890 final Timer bgTimer = se.getSensorBackgroundTime();
4891 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
4892 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
4893 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4894 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
4895 final long bgActualTime = bgTimer != null ?
4896 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4897
Dianne Hackborn61659e52014-07-09 16:13:01 -07004898 //timer.logState();
4899 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08004900 if (actualTime != totalTime) {
4901 formatTimeMs(sb, totalTime);
4902 sb.append("blamed realtime, ");
4903 }
4904
4905 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07004906 sb.append("realtime (");
4907 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08004908 sb.append(" times)");
4909
4910 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08004911 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08004912 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
4913 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08004914 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08004915 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08004916 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004917 } else {
4918 sb.append("(not used)");
4919 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004920 } else {
4921 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004922 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004923
4924 pw.println(sb.toString());
4925 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004926 }
4927
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004928 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4929 "Vibrator");
4930 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4931 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004932
Dianne Hackborn61659e52014-07-09 16:13:01 -07004933 long totalStateTime = 0;
4934 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4935 long time = u.getProcessStateTime(ips, rawRealtime, which);
4936 if (time > 0) {
4937 totalStateTime += time;
4938 sb.setLength(0);
4939 sb.append(prefix);
4940 sb.append(" ");
4941 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4942 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08004943 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004944 pw.println(sb.toString());
4945 uidActivity = true;
4946 }
4947 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08004948 if (totalStateTime > 0) {
4949 sb.setLength(0);
4950 sb.append(prefix);
4951 sb.append(" Total running: ");
4952 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4953 pw.println(sb.toString());
4954 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004955
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004956 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4957 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07004958 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004959 sb.setLength(0);
4960 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004961 sb.append(" Total cpu time: u=");
4962 formatTimeMs(sb, userCpuTimeUs / 1000);
4963 sb.append("s=");
4964 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004965 pw.println(sb.toString());
4966 }
4967
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004968 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
4969 if (cpuFreqTimes != null) {
4970 sb.setLength(0);
4971 sb.append(" Total cpu time per freq:");
4972 for (int i = 0; i < cpuFreqTimes.length; ++i) {
4973 sb.append(" " + cpuFreqTimes[i]);
4974 }
4975 pw.println(sb.toString());
4976 }
4977 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
4978 if (screenOffCpuFreqTimes != null) {
4979 sb.setLength(0);
4980 sb.append(" Total screen-off cpu time per freq:");
4981 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
4982 sb.append(" " + screenOffCpuFreqTimes[i]);
4983 }
4984 pw.println(sb.toString());
4985 }
4986
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004987 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4988 = u.getProcessStats();
4989 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4990 final Uid.Proc ps = processStats.valueAt(ipr);
4991 long userTime;
4992 long systemTime;
4993 long foregroundTime;
4994 int starts;
4995 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004996
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004997 userTime = ps.getUserTime(which);
4998 systemTime = ps.getSystemTime(which);
4999 foregroundTime = ps.getForegroundTime(which);
5000 starts = ps.getStarts(which);
5001 final int numCrashes = ps.getNumCrashes(which);
5002 final int numAnrs = ps.getNumAnrs(which);
5003 numExcessive = which == STATS_SINCE_CHARGED
5004 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005005
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005006 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5007 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5008 sb.setLength(0);
5009 sb.append(prefix); sb.append(" Proc ");
5010 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5011 sb.append(prefix); sb.append(" CPU: ");
5012 formatTimeMs(sb, userTime); sb.append("usr + ");
5013 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5014 formatTimeMs(sb, foregroundTime); sb.append("fg");
5015 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5016 sb.append("\n"); sb.append(prefix); sb.append(" ");
5017 boolean hasOne = false;
5018 if (starts != 0) {
5019 hasOne = true;
5020 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005021 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005022 if (numCrashes != 0) {
5023 if (hasOne) {
5024 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005025 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005026 hasOne = true;
5027 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005028 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005029 if (numAnrs != 0) {
5030 if (hasOne) {
5031 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005032 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005033 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005034 }
5035 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005036 pw.println(sb.toString());
5037 for (int e=0; e<numExcessive; e++) {
5038 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5039 if (ew != null) {
5040 pw.print(prefix); pw.print(" * Killed for ");
5041 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
5042 pw.print("wake lock");
5043 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
5044 pw.print("cpu");
5045 } else {
5046 pw.print("unknown");
5047 }
5048 pw.print(" use: ");
5049 TimeUtils.formatDuration(ew.usedTime, pw);
5050 pw.print(" over ");
5051 TimeUtils.formatDuration(ew.overTime, pw);
5052 if (ew.overTime != 0) {
5053 pw.print(" (");
5054 pw.print((ew.usedTime*100)/ew.overTime);
5055 pw.println("%)");
5056 }
5057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005058 }
5059 uidActivity = true;
5060 }
5061 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005062
5063 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5064 = u.getPackageStats();
5065 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5066 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5067 pw.println(":");
5068 boolean apkActivity = false;
5069 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5070 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5071 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5072 pw.print(prefix); pw.print(" Wakeup alarm ");
5073 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5074 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5075 pw.println(" times");
5076 apkActivity = true;
5077 }
5078 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5079 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5080 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5081 final long startTime = ss.getStartTime(batteryUptime, which);
5082 final int starts = ss.getStarts(which);
5083 final int launches = ss.getLaunches(which);
5084 if (startTime != 0 || starts != 0 || launches != 0) {
5085 sb.setLength(0);
5086 sb.append(prefix); sb.append(" Service ");
5087 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5088 sb.append(prefix); sb.append(" Created for: ");
5089 formatTimeMs(sb, startTime / 1000);
5090 sb.append("uptime\n");
5091 sb.append(prefix); sb.append(" Starts: ");
5092 sb.append(starts);
5093 sb.append(", launches: "); sb.append(launches);
5094 pw.println(sb.toString());
5095 apkActivity = true;
5096 }
5097 }
5098 if (!apkActivity) {
5099 pw.print(prefix); pw.println(" (nothing executed)");
5100 }
5101 uidActivity = true;
5102 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005103 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005104 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005105 }
5106 }
5107 }
5108
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005109 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005110 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005111 int diff = oldval ^ newval;
5112 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005113 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005114 for (int i=0; i<descriptions.length; i++) {
5115 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005116 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005117 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005118 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005119 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005120 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005121 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5122 didWake = true;
5123 pw.print("=");
5124 if (longNames) {
5125 UserHandle.formatUid(pw, wakelockTag.uid);
5126 pw.print(":\"");
5127 pw.print(wakelockTag.string);
5128 pw.print("\"");
5129 } else {
5130 pw.print(wakelockTag.poolIdx);
5131 }
5132 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005133 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005134 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005135 pw.print("=");
5136 int val = (newval&bd.mask)>>bd.shift;
5137 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005138 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005139 } else {
5140 pw.print(val);
5141 }
5142 }
5143 }
5144 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005145 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005146 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005147 if (longNames) {
5148 UserHandle.formatUid(pw, wakelockTag.uid);
5149 pw.print(":\"");
5150 pw.print(wakelockTag.string);
5151 pw.print("\"");
5152 } else {
5153 pw.print(wakelockTag.poolIdx);
5154 }
5155 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005156 }
5157
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005158 public void prepareForDumpLocked() {
5159 }
5160
5161 public static class HistoryPrinter {
5162 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005163 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005164 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005165 int oldStatus = -1;
5166 int oldHealth = -1;
5167 int oldPlug = -1;
5168 int oldTemp = -1;
5169 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005170 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005171 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005172
Dianne Hackborn3251b902014-06-20 14:40:53 -07005173 void reset() {
5174 oldState = oldState2 = 0;
5175 oldLevel = -1;
5176 oldStatus = -1;
5177 oldHealth = -1;
5178 oldPlug = -1;
5179 oldTemp = -1;
5180 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005181 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005182 }
5183
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005184 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005185 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005186 if (!checkin) {
5187 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005188 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005189 pw.print(" (");
5190 pw.print(rec.numReadInts);
5191 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005192 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005193 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5194 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005195 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005196 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005197 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005198 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005199 }
5200 lastTime = rec.time;
5201 }
5202 if (rec.cmd == HistoryItem.CMD_START) {
5203 if (checkin) {
5204 pw.print(":");
5205 }
5206 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005207 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005208 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5209 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005210 if (checkin) {
5211 pw.print(":");
5212 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005213 if (rec.cmd == HistoryItem.CMD_RESET) {
5214 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005215 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005216 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005217 pw.print("TIME:");
5218 if (checkin) {
5219 pw.println(rec.currentTime);
5220 } else {
5221 pw.print(" ");
5222 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5223 rec.currentTime).toString());
5224 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005225 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5226 if (checkin) {
5227 pw.print(":");
5228 }
5229 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005230 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5231 if (checkin) {
5232 pw.print(":");
5233 }
5234 pw.println("*OVERFLOW*");
5235 } else {
5236 if (!checkin) {
5237 if (rec.batteryLevel < 10) pw.print("00");
5238 else if (rec.batteryLevel < 100) pw.print("0");
5239 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005240 if (verbose) {
5241 pw.print(" ");
5242 if (rec.states < 0) ;
5243 else if (rec.states < 0x10) pw.print("0000000");
5244 else if (rec.states < 0x100) pw.print("000000");
5245 else if (rec.states < 0x1000) pw.print("00000");
5246 else if (rec.states < 0x10000) pw.print("0000");
5247 else if (rec.states < 0x100000) pw.print("000");
5248 else if (rec.states < 0x1000000) pw.print("00");
5249 else if (rec.states < 0x10000000) pw.print("0");
5250 pw.print(Integer.toHexString(rec.states));
5251 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005252 } else {
5253 if (oldLevel != rec.batteryLevel) {
5254 oldLevel = rec.batteryLevel;
5255 pw.print(",Bl="); pw.print(rec.batteryLevel);
5256 }
5257 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005258 if (oldStatus != rec.batteryStatus) {
5259 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005260 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005261 switch (oldStatus) {
5262 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005263 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005264 break;
5265 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005266 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005267 break;
5268 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005269 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005270 break;
5271 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005272 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005273 break;
5274 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005275 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005276 break;
5277 default:
5278 pw.print(oldStatus);
5279 break;
5280 }
5281 }
5282 if (oldHealth != rec.batteryHealth) {
5283 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005284 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005285 switch (oldHealth) {
5286 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005287 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005288 break;
5289 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005290 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005291 break;
5292 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005293 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005294 break;
5295 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005296 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005297 break;
5298 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005299 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005300 break;
5301 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005302 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005303 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005304 case BatteryManager.BATTERY_HEALTH_COLD:
5305 pw.print(checkin ? "c" : "cold");
5306 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005307 default:
5308 pw.print(oldHealth);
5309 break;
5310 }
5311 }
5312 if (oldPlug != rec.batteryPlugType) {
5313 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005314 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005315 switch (oldPlug) {
5316 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005317 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005318 break;
5319 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005320 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005321 break;
5322 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005323 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005324 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005325 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005326 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005327 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005328 default:
5329 pw.print(oldPlug);
5330 break;
5331 }
5332 }
5333 if (oldTemp != rec.batteryTemperature) {
5334 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005335 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005336 pw.print(oldTemp);
5337 }
5338 if (oldVolt != rec.batteryVoltage) {
5339 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005340 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005341 pw.print(oldVolt);
5342 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005343 final int chargeMAh = rec.batteryChargeUAh / 1000;
5344 if (oldChargeMAh != chargeMAh) {
5345 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005346 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005347 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005348 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005349 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005350 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005351 printBitDescriptions(pw, oldState2, rec.states2, null,
5352 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005353 if (rec.wakeReasonTag != null) {
5354 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005355 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005356 pw.print(rec.wakeReasonTag.poolIdx);
5357 } else {
5358 pw.print(" wake_reason=");
5359 pw.print(rec.wakeReasonTag.uid);
5360 pw.print(":\"");
5361 pw.print(rec.wakeReasonTag.string);
5362 pw.print("\"");
5363 }
5364 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005365 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005366 pw.print(checkin ? "," : " ");
5367 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5368 pw.print("+");
5369 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5370 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005371 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005372 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
5373 : HISTORY_EVENT_NAMES;
5374 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
5375 | HistoryItem.EVENT_FLAG_FINISH);
5376 if (idx >= 0 && idx < eventNames.length) {
5377 pw.print(eventNames[idx]);
5378 } else {
5379 pw.print(checkin ? "Ev" : "event");
5380 pw.print(idx);
5381 }
5382 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005383 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005384 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08005385 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08005386 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
5387 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005388 pw.print(":\"");
5389 pw.print(rec.eventTag.string);
5390 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005391 }
5392 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005393 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005394 if (rec.stepDetails != null) {
5395 if (!checkin) {
5396 pw.print(" Details: cpu=");
5397 pw.print(rec.stepDetails.userTime);
5398 pw.print("u+");
5399 pw.print(rec.stepDetails.systemTime);
5400 pw.print("s");
5401 if (rec.stepDetails.appCpuUid1 >= 0) {
5402 pw.print(" (");
5403 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
5404 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5405 if (rec.stepDetails.appCpuUid2 >= 0) {
5406 pw.print(", ");
5407 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
5408 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5409 }
5410 if (rec.stepDetails.appCpuUid3 >= 0) {
5411 pw.print(", ");
5412 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
5413 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5414 }
5415 pw.print(')');
5416 }
5417 pw.println();
5418 pw.print(" /proc/stat=");
5419 pw.print(rec.stepDetails.statUserTime);
5420 pw.print(" usr, ");
5421 pw.print(rec.stepDetails.statSystemTime);
5422 pw.print(" sys, ");
5423 pw.print(rec.stepDetails.statIOWaitTime);
5424 pw.print(" io, ");
5425 pw.print(rec.stepDetails.statIrqTime);
5426 pw.print(" irq, ");
5427 pw.print(rec.stepDetails.statSoftIrqTime);
5428 pw.print(" sirq, ");
5429 pw.print(rec.stepDetails.statIdlTime);
5430 pw.print(" idle");
5431 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
5432 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
5433 + rec.stepDetails.statSoftIrqTime;
5434 int total = totalRun + rec.stepDetails.statIdlTime;
5435 if (total > 0) {
5436 pw.print(" (");
5437 float perc = ((float)totalRun) / ((float)total) * 100;
5438 pw.print(String.format("%.1f%%", perc));
5439 pw.print(" of ");
5440 StringBuilder sb = new StringBuilder(64);
5441 formatTimeMsNoSpace(sb, total*10);
5442 pw.print(sb);
5443 pw.print(")");
5444 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005445 pw.print(", PlatformIdleStat ");
5446 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005447 pw.println();
5448 } else {
5449 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5450 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
5451 pw.print(rec.stepDetails.userTime);
5452 pw.print(":");
5453 pw.print(rec.stepDetails.systemTime);
5454 if (rec.stepDetails.appCpuUid1 >= 0) {
5455 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
5456 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5457 if (rec.stepDetails.appCpuUid2 >= 0) {
5458 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
5459 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5460 }
5461 if (rec.stepDetails.appCpuUid3 >= 0) {
5462 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
5463 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5464 }
5465 }
5466 pw.println();
5467 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5468 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
5469 pw.print(rec.stepDetails.statUserTime);
5470 pw.print(',');
5471 pw.print(rec.stepDetails.statSystemTime);
5472 pw.print(',');
5473 pw.print(rec.stepDetails.statIOWaitTime);
5474 pw.print(',');
5475 pw.print(rec.stepDetails.statIrqTime);
5476 pw.print(',');
5477 pw.print(rec.stepDetails.statSoftIrqTime);
5478 pw.print(',');
5479 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005480 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005481 if (rec.stepDetails.statPlatformIdleState != null) {
5482 pw.print(rec.stepDetails.statPlatformIdleState);
5483 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005484 pw.println();
5485 }
5486 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005487 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005488 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005489 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005490 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005491
5492 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
5493 UserHandle.formatUid(pw, uid);
5494 pw.print("=");
5495 pw.print(utime);
5496 pw.print("u+");
5497 pw.print(stime);
5498 pw.print("s");
5499 }
5500
5501 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5502 pw.print('/');
5503 pw.print(uid);
5504 pw.print(":");
5505 pw.print(utime);
5506 pw.print(":");
5507 pw.print(stime);
5508 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005509 }
5510
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005511 private void printSizeValue(PrintWriter pw, long size) {
5512 float result = size;
5513 String suffix = "";
5514 if (result >= 10*1024) {
5515 suffix = "KB";
5516 result = result / 1024;
5517 }
5518 if (result >= 10*1024) {
5519 suffix = "MB";
5520 result = result / 1024;
5521 }
5522 if (result >= 10*1024) {
5523 suffix = "GB";
5524 result = result / 1024;
5525 }
5526 if (result >= 10*1024) {
5527 suffix = "TB";
5528 result = result / 1024;
5529 }
5530 if (result >= 10*1024) {
5531 suffix = "PB";
5532 result = result / 1024;
5533 }
5534 pw.print((int)result);
5535 pw.print(suffix);
5536 }
5537
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005538 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5539 String label3, long estimatedTime) {
5540 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005541 return false;
5542 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005543 pw.print(label1);
5544 pw.print(label2);
5545 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005546 StringBuilder sb = new StringBuilder(64);
5547 formatTimeMs(sb, estimatedTime);
5548 pw.print(sb);
5549 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005550 return true;
5551 }
5552
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005553 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5554 LevelStepTracker steps, boolean checkin) {
5555 if (steps == null) {
5556 return false;
5557 }
5558 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005559 if (count <= 0) {
5560 return false;
5561 }
5562 if (!checkin) {
5563 pw.println(header);
5564 }
Kweku Adams030980a2015-04-01 16:07:48 -07005565 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005566 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005567 long duration = steps.getDurationAt(i);
5568 int level = steps.getLevelAt(i);
5569 long initMode = steps.getInitModeAt(i);
5570 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005571 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005572 lineArgs[0] = Long.toString(duration);
5573 lineArgs[1] = Integer.toString(level);
5574 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5575 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5576 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5577 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5578 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5579 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005580 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005581 }
5582 } else {
5583 lineArgs[2] = "";
5584 }
5585 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5586 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5587 } else {
5588 lineArgs[3] = "";
5589 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005590 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005591 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005592 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005593 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005594 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005595 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5596 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005597 pw.print(prefix);
5598 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005599 TimeUtils.formatDuration(duration, pw);
5600 pw.print(" to "); pw.print(level);
5601 boolean haveModes = false;
5602 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5603 pw.print(" (");
5604 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5605 case Display.STATE_OFF: pw.print("screen-off"); break;
5606 case Display.STATE_ON: pw.print("screen-on"); break;
5607 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5608 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005609 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005610 }
5611 haveModes = true;
5612 }
5613 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5614 pw.print(haveModes ? ", " : " (");
5615 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5616 ? "power-save-on" : "power-save-off");
5617 haveModes = true;
5618 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005619 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5620 pw.print(haveModes ? ", " : " (");
5621 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5622 ? "device-idle-on" : "device-idle-off");
5623 haveModes = true;
5624 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005625 if (haveModes) {
5626 pw.print(")");
5627 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005628 pw.println();
5629 }
5630 }
5631 return true;
5632 }
5633
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005634 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005635 public static final int DUMP_DAILY_ONLY = 1<<2;
5636 public static final int DUMP_HISTORY_ONLY = 1<<3;
5637 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5638 public static final int DUMP_VERBOSE = 1<<5;
5639 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005640
Dianne Hackborn37de0982014-05-09 09:32:18 -07005641 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5642 final HistoryPrinter hprinter = new HistoryPrinter();
5643 final HistoryItem rec = new HistoryItem();
5644 long lastTime = -1;
5645 long baseTime = -1;
5646 boolean printed = false;
5647 HistoryEventTracker tracker = null;
5648 while (getNextHistoryLocked(rec)) {
5649 lastTime = rec.time;
5650 if (baseTime < 0) {
5651 baseTime = lastTime;
5652 }
5653 if (rec.time >= histStart) {
5654 if (histStart >= 0 && !printed) {
5655 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005656 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005657 || rec.cmd == HistoryItem.CMD_START
5658 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005659 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005660 hprinter.printNextItem(pw, rec, baseTime, checkin,
5661 (flags&DUMP_VERBOSE) != 0);
5662 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005663 } else if (rec.currentTime != 0) {
5664 printed = true;
5665 byte cmd = rec.cmd;
5666 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005667 hprinter.printNextItem(pw, rec, baseTime, checkin,
5668 (flags&DUMP_VERBOSE) != 0);
5669 rec.cmd = cmd;
5670 }
5671 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005672 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5673 hprinter.printNextItem(pw, rec, baseTime, checkin,
5674 (flags&DUMP_VERBOSE) != 0);
5675 rec.cmd = HistoryItem.CMD_UPDATE;
5676 }
5677 int oldEventCode = rec.eventCode;
5678 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005679 rec.eventTag = new HistoryTag();
5680 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5681 HashMap<String, SparseIntArray> active
5682 = tracker.getStateForEvent(i);
5683 if (active == null) {
5684 continue;
5685 }
5686 for (HashMap.Entry<String, SparseIntArray> ent
5687 : active.entrySet()) {
5688 SparseIntArray uids = ent.getValue();
5689 for (int j=0; j<uids.size(); j++) {
5690 rec.eventCode = i;
5691 rec.eventTag.string = ent.getKey();
5692 rec.eventTag.uid = uids.keyAt(j);
5693 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005694 hprinter.printNextItem(pw, rec, baseTime, checkin,
5695 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005696 rec.wakeReasonTag = null;
5697 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005698 }
5699 }
5700 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005701 rec.eventCode = oldEventCode;
5702 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005703 tracker = null;
5704 }
5705 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005706 hprinter.printNextItem(pw, rec, baseTime, checkin,
5707 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005708 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5709 // This is an attempt to aggregate the previous state and generate
5710 // fake events to reflect that state at the point where we start
5711 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005712 if (tracker == null) {
5713 tracker = new HistoryEventTracker();
5714 }
5715 tracker.updateState(rec.eventCode, rec.eventTag.string,
5716 rec.eventTag.uid, rec.eventTag.poolIdx);
5717 }
5718 }
5719 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005720 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005721 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5722 }
5723 }
5724
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005725 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5726 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5727 if (steps == null) {
5728 return;
5729 }
5730 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5731 if (timeRemaining >= 0) {
5732 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5733 tmpSb.setLength(0);
5734 formatTimeMs(tmpSb, timeRemaining);
5735 pw.print(tmpSb);
5736 pw.print(" (from "); pw.print(tmpOutInt[0]);
5737 pw.println(" steps)");
5738 }
5739 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5740 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5741 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5742 if (estimatedTime > 0) {
5743 pw.print(prefix); pw.print(label); pw.print(" ");
5744 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5745 pw.print(" time: ");
5746 tmpSb.setLength(0);
5747 formatTimeMs(tmpSb, estimatedTime);
5748 pw.print(tmpSb);
5749 pw.print(" (from "); pw.print(tmpOutInt[0]);
5750 pw.println(" steps)");
5751 }
5752 }
5753 }
5754
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005755 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5756 ArrayList<PackageChange> changes) {
5757 if (changes == null) {
5758 return;
5759 }
5760 pw.print(prefix); pw.println("Package changes:");
5761 for (int i=0; i<changes.size(); i++) {
5762 PackageChange pc = changes.get(i);
5763 if (pc.mUpdate) {
5764 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5765 pw.print(" vers="); pw.println(pc.mVersionCode);
5766 } else {
5767 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5768 }
5769 }
5770 }
5771
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005772 /**
5773 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5774 *
5775 * @param pw a Printer to receive the dump output.
5776 */
5777 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005778 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005779 prepareForDumpLocked();
5780
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005781 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005782 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005783
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005784 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005785 final long historyTotalSize = getHistoryTotalSize();
5786 final long historyUsedSize = getHistoryUsedSize();
5787 if (startIteratingHistoryLocked()) {
5788 try {
5789 pw.print("Battery History (");
5790 pw.print((100*historyUsedSize)/historyTotalSize);
5791 pw.print("% used, ");
5792 printSizeValue(pw, historyUsedSize);
5793 pw.print(" used of ");
5794 printSizeValue(pw, historyTotalSize);
5795 pw.print(", ");
5796 pw.print(getHistoryStringPoolSize());
5797 pw.print(" strings using ");
5798 printSizeValue(pw, getHistoryStringPoolBytes());
5799 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005800 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005801 pw.println();
5802 } finally {
5803 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005804 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005805 }
5806
5807 if (startIteratingOldHistoryLocked()) {
5808 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005809 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005810 pw.println("Old battery History:");
5811 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005812 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005813 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005814 if (baseTime < 0) {
5815 baseTime = rec.time;
5816 }
5817 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005818 }
5819 pw.println();
5820 } finally {
5821 finishIteratingOldHistoryLocked();
5822 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005823 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005824 }
5825
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005826 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005827 return;
5828 }
5829
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005830 if (!filtering) {
5831 SparseArray<? extends Uid> uidStats = getUidStats();
5832 final int NU = uidStats.size();
5833 boolean didPid = false;
5834 long nowRealtime = SystemClock.elapsedRealtime();
5835 for (int i=0; i<NU; i++) {
5836 Uid uid = uidStats.valueAt(i);
5837 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
5838 if (pids != null) {
5839 for (int j=0; j<pids.size(); j++) {
5840 Uid.Pid pid = pids.valueAt(j);
5841 if (!didPid) {
5842 pw.println("Per-PID Stats:");
5843 didPid = true;
5844 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005845 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
5846 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005847 pw.print(" PID "); pw.print(pids.keyAt(j));
5848 pw.print(" wake time: ");
5849 TimeUtils.formatDuration(time, pw);
5850 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005851 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005852 }
5853 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005854 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005855 pw.println();
5856 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005857 }
5858
5859 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005860 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
5861 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07005862 long timeRemaining = computeBatteryTimeRemaining(
5863 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005864 if (timeRemaining >= 0) {
5865 pw.print(" Estimated discharge time remaining: ");
5866 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5867 pw.println();
5868 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005869 final LevelStepTracker steps = getDischargeLevelStepTracker();
5870 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5871 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
5872 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5873 STEP_LEVEL_MODE_VALUES[i], null));
5874 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005875 pw.println();
5876 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005877 if (dumpDurationSteps(pw, " ", "Charge step durations:",
5878 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07005879 long timeRemaining = computeChargeTimeRemaining(
5880 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005881 if (timeRemaining >= 0) {
5882 pw.print(" Estimated charge time remaining: ");
5883 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5884 pw.println();
5885 }
5886 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005887 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005888 }
5889 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
5890 pw.println("Daily stats:");
5891 pw.print(" Current start time: ");
5892 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5893 getCurrentDailyStartTime()).toString());
5894 pw.print(" Next min deadline: ");
5895 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5896 getNextMinDailyDeadline()).toString());
5897 pw.print(" Next max deadline: ");
5898 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5899 getNextMaxDailyDeadline()).toString());
5900 StringBuilder sb = new StringBuilder(64);
5901 int[] outInt = new int[1];
5902 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
5903 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005904 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
5905 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005906 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005907 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
5908 dsteps, false)) {
5909 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5910 sb, outInt);
5911 }
5912 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
5913 csteps, false)) {
5914 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5915 sb, outInt);
5916 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005917 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005918 } else {
5919 pw.println(" Current daily steps:");
5920 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5921 sb, outInt);
5922 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5923 sb, outInt);
5924 }
5925 }
5926 DailyItem dit;
5927 int curIndex = 0;
5928 while ((dit=getDailyItemLocked(curIndex)) != null) {
5929 curIndex++;
5930 if ((flags&DUMP_DAILY_ONLY) != 0) {
5931 pw.println();
5932 }
5933 pw.print(" Daily from ");
5934 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
5935 pw.print(" to ");
5936 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
5937 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005938 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005939 if (dumpDurationSteps(pw, " ",
5940 " Discharge step durations:", dit.mDischargeSteps, false)) {
5941 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5942 sb, outInt);
5943 }
5944 if (dumpDurationSteps(pw, " ",
5945 " Charge step durations:", dit.mChargeSteps, false)) {
5946 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5947 sb, outInt);
5948 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005949 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005950 } else {
5951 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5952 sb, outInt);
5953 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5954 sb, outInt);
5955 }
5956 }
5957 pw.println();
5958 }
5959 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005960 pw.println("Statistics since last charge:");
5961 pw.println(" System starts: " + getStartCount()
5962 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005963 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5964 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005965 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005966 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005967 }
5968
5969 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005970 public void dumpCheckinLocked(Context context, PrintWriter pw,
5971 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005972 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005973
5974 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005975 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5976 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005977
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005978 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5979
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005980 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005981 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005982
5983 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005984 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005985 try {
5986 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5987 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5988 pw.print(HISTORY_STRING_POOL); pw.print(',');
5989 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005990 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005991 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005992 pw.print(",\"");
5993 String str = getHistoryTagPoolString(i);
5994 str = str.replace("\\", "\\\\");
5995 str = str.replace("\"", "\\\"");
5996 pw.print(str);
5997 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005998 pw.println();
5999 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006000 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006001 } finally {
6002 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006003 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006004 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006005 }
6006
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006007 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006008 return;
6009 }
6010
Dianne Hackborne4a59512010-12-07 11:08:07 -08006011 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006012 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006013 for (int i=0; i<apps.size(); i++) {
6014 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006015 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6016 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006017 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006018 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6019 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006020 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006021 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006022 }
6023 SparseArray<? extends Uid> uidStats = getUidStats();
6024 final int NU = uidStats.size();
6025 String[] lineArgs = new String[2];
6026 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006027 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6028 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6029 if (pkgs != null && !pkgs.second.value) {
6030 pkgs.second.value = true;
6031 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006032 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006033 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006034 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6035 (Object[])lineArgs);
6036 }
6037 }
6038 }
6039 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006040 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006041 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006042 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006043 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006044 if (timeRemaining >= 0) {
6045 lineArgs[0] = Long.toString(timeRemaining);
6046 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6047 (Object[])lineArgs);
6048 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006049 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006050 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006051 if (timeRemaining >= 0) {
6052 lineArgs[0] = Long.toString(timeRemaining);
6053 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6054 (Object[])lineArgs);
6055 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006056 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6057 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006058 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006059 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006060}