blob: 071f45873c80a7b6c29f008a7ae566ab3922caff [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,
Bookatz5b5ec322017-05-26 09:40:38 -0700220 // full totalTime, 'f', count, current duration, max duration, total duration,
221 // partial totalTime, 'p', count, current duration, max duration, total duration,
222 // bg partial totalTime, 'bp', count, current duration, max duration, total duration,
223 // window totalTime, 'w', count, current duration, max duration, total duration
Bookatz506a8182017-05-01 14:18:42 -0700224 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700225 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700226 // awl line is:
227 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
228 // cumulative partial wakelock duration, cumulative background partial wakelock duration
229 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700230 private static final String SYNC_DATA = "sy";
231 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700232 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700233 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700234 private static final String NETWORK_DATA = "nt";
235 private static final String USER_ACTIVITY_DATA = "ua";
236 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800237 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700238 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700239 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700240 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800241 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
242 private static final String WIFI_CONTROLLER_DATA = "wfcd";
243 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
244 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700245 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700246 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800247 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800248 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
249 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800250 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700251 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700252 private static final String SCREEN_BRIGHTNESS_DATA = "br";
253 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700254 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700255 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
256 private static final String DATA_CONNECTION_TIME_DATA = "dct";
257 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800258 private static final String WIFI_STATE_TIME_DATA = "wst";
259 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700260 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
261 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
262 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
263 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800264 private static final String POWER_USE_SUMMARY_DATA = "pws";
265 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700266 private static final String DISCHARGE_STEP_DATA = "dsd";
267 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700268 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
269 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700270 private static final String FLASHLIGHT_DATA = "fla";
271 private static final String CAMERA_DATA = "cam";
272 private static final String VIDEO_DATA = "vid";
273 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274
Adam Lesinski010bf372016-04-11 12:18:18 -0700275 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
276
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700277 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 private final Formatter mFormatter = new Formatter(mFormatBuilder);
279
280 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700281 * Indicates times spent by the uid at each cpu frequency in all process states.
282 *
283 * Other types might include times spent in foreground, background etc.
284 */
285 private final String UID_TIMES_TYPE_ALL = "A";
286
287 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700288 * State for keeping track of counting information.
289 */
290 public static abstract class Counter {
291
292 /**
293 * Returns the count associated with this Counter for the
294 * selected type of statistics.
295 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700296 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700297 */
Evan Millarc64edde2009-04-18 12:26:32 -0700298 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700299
300 /**
301 * Temporary for debugging.
302 */
303 public abstract void logState(Printer pw, String prefix);
304 }
305
306 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700307 * State for keeping track of long counting information.
308 */
309 public static abstract class LongCounter {
310
311 /**
312 * Returns the count associated with this Counter for the
313 * selected type of statistics.
314 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700315 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700316 */
317 public abstract long getCountLocked(int which);
318
319 /**
320 * Temporary for debugging.
321 */
322 public abstract void logState(Printer pw, String prefix);
323 }
324
325 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700326 * State for keeping track of array of long counting information.
327 */
328 public static abstract class LongCounterArray {
329 /**
330 * Returns the counts associated with this Counter for the
331 * selected type of statistics.
332 *
333 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
334 */
335 public abstract long[] getCountsLocked(int which);
336
337 /**
338 * Temporary for debugging.
339 */
340 public abstract void logState(Printer pw, String prefix);
341 }
342
343 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800344 * Container class that aggregates counters for transmit, receive, and idle state of a
345 * radio controller.
346 */
347 public static abstract class ControllerActivityCounter {
348 /**
349 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
350 * idle state.
351 */
352 public abstract LongCounter getIdleTimeCounter();
353
354 /**
355 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
356 * receive state.
357 */
358 public abstract LongCounter getRxTimeCounter();
359
360 /**
361 * An array of {@link LongCounter}, representing various transmit levels, where each level
362 * may draw a different amount of power. The levels themselves are controller-specific.
363 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
364 * various transmit level states.
365 */
366 public abstract LongCounter[] getTxTimeCounters();
367
368 /**
369 * @return a non-null {@link LongCounter} representing the power consumed by the controller
370 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
371 * yield a value of 0 if the device doesn't support power calculations.
372 */
373 public abstract LongCounter getPowerCounter();
374 }
375
376 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 * State for keeping track of timing information.
378 */
379 public static abstract class Timer {
380
381 /**
382 * Returns the count associated with this Timer for the
383 * selected type of statistics.
384 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700385 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 */
Evan Millarc64edde2009-04-18 12:26:32 -0700387 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388
389 /**
390 * Returns the total time in microseconds associated with this Timer for the
391 * selected type of statistics.
392 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800393 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700394 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 * @return a time in microseconds
396 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800397 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700400 * Returns the total time in microseconds associated with this Timer since the
401 * 'mark' was last set.
402 *
403 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
404 * @return a time in microseconds
405 */
406 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
407
408 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700409 * Returns the max duration if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800410 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700411
412 */
413 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
414 return -1;
415 }
416
417 /**
418 * Returns the current time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800419 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700420 */
421 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
422 return -1;
423 }
424
425 /**
Bookatz867c0d72017-03-07 18:23:42 -0800426 * Returns the current time the timer has been active, if it is being tracked.
427 *
428 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
429 * been on since reset.
430 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
431 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
432 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
433 * the actual total time.
434 * Not all Timer subclasses track the max, total, current durations.
435 */
436 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
437 return -1;
438 }
439
440 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700441 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
442 * used, for example, for tracking background usage. Secondary timers are never pooled.
443 *
444 * Not all Timer subclasses have a secondary timer; those that don't return null.
445 */
446 public Timer getSubTimer() {
447 return null;
448 }
449
450 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700451 * Returns whether the timer is currently running. Some types of timers
452 * (e.g. BatchTimers) don't know whether the event is currently active,
453 * and report false.
454 */
455 public boolean isRunningLocked() {
456 return false;
457 }
458
459 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 * Temporary for debugging.
461 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700462 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 }
464
465 /**
466 * The statistics associated with a particular uid.
467 */
468 public static abstract class Uid {
469
470 /**
471 * Returns a mapping containing wakelock statistics.
472 *
473 * @return a Map from Strings to Uid.Wakelock objects.
474 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700475 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476
477 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700478 * Returns a mapping containing sync statistics.
479 *
480 * @return a Map from Strings to Timer objects.
481 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700482 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700483
484 /**
485 * Returns a mapping containing scheduled job statistics.
486 *
487 * @return a Map from Strings to Timer objects.
488 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700489 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700490
491 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 * The statistics associated with a particular wake lock.
493 */
494 public static abstract class Wakelock {
495 public abstract Timer getWakeTime(int type);
496 }
497
498 /**
Bookatzc8c44962017-05-11 12:12:54 -0700499 * The cumulative time the uid spent holding any partial wakelocks. This will generally
500 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
501 * wakelocks that overlap in time (and therefore over-counts).
502 */
503 public abstract Timer getAggregatedPartialWakelockTimer();
504
505 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 * Returns a mapping containing sensor statistics.
507 *
508 * @return a Map from Integer sensor ids to Uid.Sensor objects.
509 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700510 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511
512 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700513 * Returns a mapping containing active process data.
514 */
515 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700516
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700517 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 * Returns a mapping containing process statistics.
519 *
520 * @return a Map from Strings to Uid.Proc objects.
521 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700522 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523
524 /**
525 * Returns a mapping containing package statistics.
526 *
527 * @return a Map from Strings to Uid.Pkg objects.
528 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700529 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700530
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800531 public abstract ControllerActivityCounter getWifiControllerActivity();
532 public abstract ControllerActivityCounter getBluetoothControllerActivity();
533 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800534
535 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 * {@hide}
537 */
538 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700539
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800540 public abstract void noteWifiRunningLocked(long elapsedRealtime);
541 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
542 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
543 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
544 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
545 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
546 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
547 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
548 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
549 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800550 public abstract void noteActivityResumedLocked(long elapsedRealtime);
551 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800552 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
553 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
554 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700555 public abstract int getWifiScanCount(int which);
Bookatz867c0d72017-03-07 18:23:42 -0800556 public abstract int getWifiScanBackgroundCount(int which);
557 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
558 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800559 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700560 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800561 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700562 public abstract Timer getAudioTurnedOnTimer();
563 public abstract Timer getVideoTurnedOnTimer();
564 public abstract Timer getFlashlightTurnedOnTimer();
565 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700566 public abstract Timer getForegroundActivityTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800567 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800568 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700569 public abstract Counter getBluetoothScanResultCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700570
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700571 public abstract long[] getCpuFreqTimes(int which);
572 public abstract long[] getScreenOffCpuFreqTimes(int which);
573
Dianne Hackborna0200e32016-03-30 18:01:41 -0700574 // Note: the following times are disjoint. They can be added together to find the
575 // total time a uid has had any processes running at all.
576
577 /**
578 * Time this uid has any processes in the top state (or above such as persistent).
579 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800580 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700581 /**
582 * Time this uid has any process with a started out bound foreground service, but
583 * none in the "top" state.
584 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800585 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700586 /**
587 * Time this uid has any process that is top while the device is sleeping, but none
588 * in the "foreground service" or better state.
589 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800590 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700591 /**
592 * Time this uid has any process in an active foreground state, but none in the
593 * "top sleeping" or better state.
594 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800595 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700596 /**
597 * Time this uid has any process in an active background state, but none in the
598 * "foreground" or better state.
599 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800600 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700601 /**
602 * Time this uid has any processes that are sitting around cached, not in one of the
603 * other active states.
604 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800605 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700606 /**
607 * Total number of process states we track.
608 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800609 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700610
611 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800612 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700613 };
614
615 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800616 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700617
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800618 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619
Robert Greenwalta029ea12013-09-25 16:38:12 -0700620 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
621
Dianne Hackborn617f8772009-03-31 15:04:46 -0700622 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700623 * Note that these must match the constants in android.os.PowerManager.
624 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
625 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700626 */
627 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700628 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700629 };
Bookatzc8c44962017-05-11 12:12:54 -0700630
Phil Weaverda80d672016-03-15 16:25:46 -0700631 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700632
Dianne Hackborn617f8772009-03-31 15:04:46 -0700633 public abstract void noteUserActivityLocked(int type);
634 public abstract boolean hasUserActivity();
635 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700636
637 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800638 public abstract long getNetworkActivityBytes(int type, int which);
639 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800640 public abstract long getMobileRadioActiveTime(int which);
641 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700642
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700643 /**
644 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
645 */
646 public abstract long getUserCpuTimeUs(int which);
647
648 /**
649 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
650 */
651 public abstract long getSystemCpuTimeUs(int which);
652
653 /**
Adam Lesinski6832f392015-09-05 18:05:40 -0700654 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a
655 * given CPU cluster.
656 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700657 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700658 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700659 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
660 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700661 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700662 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700663
Adam Lesinski5f056f62016-07-14 16:56:08 -0700664 /**
665 * Returns the number of times this UID woke up the Application Processor to
666 * process a mobile radio packet.
667 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
668 */
669 public abstract long getMobileRadioApWakeupCount(int which);
670
671 /**
672 * Returns the number of times this UID woke up the Application Processor to
673 * process a WiFi packet.
674 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
675 */
676 public abstract long getWifiRadioApWakeupCount(int which);
677
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800679 /*
680 * FIXME: it's not correct to use this magic value because it
681 * could clash with a sensor handle (which are defined by
682 * the sensor HAL, and therefore out of our control
683 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 // Magic sensor number for the GPS.
685 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800690
Bookatz867c0d72017-03-07 18:23:42 -0800691 /** Returns a Timer for sensor usage when app is in the background. */
692 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 }
694
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700695 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800696 public int mWakeNesting;
697 public long mWakeSumMs;
698 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700699 }
700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 /**
702 * The statistics associated with a particular process.
703 */
704 public static abstract class Proc {
705
Dianne Hackborn287952c2010-09-22 22:34:31 -0700706 public static class ExcessivePower {
707 public static final int TYPE_WAKE = 1;
708 public static final int TYPE_CPU = 2;
709
710 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700711 public long overTime;
712 public long usedTime;
713 }
714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800716 * Returns true if this process is still active in the battery stats.
717 */
718 public abstract boolean isActive();
719
720 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700721 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700723 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 */
725 public abstract long getUserTime(int which);
726
727 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700728 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700730 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 */
732 public abstract long getSystemTime(int which);
733
734 /**
735 * Returns the number of times the process has been started.
736 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700737 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 */
739 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700740
741 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800742 * Returns the number of times the process has crashed.
743 *
744 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
745 */
746 public abstract int getNumCrashes(int which);
747
748 /**
749 * Returns the number of times the process has ANRed.
750 *
751 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
752 */
753 public abstract int getNumAnrs(int which);
754
755 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700756 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700757 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700758 * @return foreground cpu time in microseconds
759 */
760 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700761
Dianne Hackborn287952c2010-09-22 22:34:31 -0700762 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700763
Dianne Hackborn287952c2010-09-22 22:34:31 -0700764 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 }
766
767 /**
768 * The statistics associated with a particular package.
769 */
770 public static abstract class Pkg {
771
772 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700773 * Returns information about all wakeup alarms that have been triggered for this
774 * package. The mapping keys are tag names for the alarms, the counter contains
775 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700777 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778
779 /**
780 * Returns a mapping containing service statistics.
781 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700782 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783
784 /**
785 * The statistics associated with a particular service.
786 */
Joe Onoratoabded112016-02-08 16:49:39 -0800787 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788
789 /**
790 * Returns the amount of time spent started.
791 *
792 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700793 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 * @return
795 */
796 public abstract long getStartTime(long batteryUptime, int which);
797
798 /**
799 * Returns the total number of times startService() has been called.
800 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700801 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 */
803 public abstract int getStarts(int which);
804
805 /**
806 * Returns the total number times the service has been launched.
807 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700808 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 */
810 public abstract int getLaunches(int which);
811 }
812 }
813 }
814
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800815 public static final class LevelStepTracker {
816 public long mLastStepTime = -1;
817 public int mNumStepDurations;
818 public final long[] mStepDurations;
819
820 public LevelStepTracker(int maxLevelSteps) {
821 mStepDurations = new long[maxLevelSteps];
822 }
823
824 public LevelStepTracker(int numSteps, long[] steps) {
825 mNumStepDurations = numSteps;
826 mStepDurations = new long[numSteps];
827 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
828 }
829
830 public long getDurationAt(int index) {
831 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
832 }
833
834 public int getLevelAt(int index) {
835 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
836 >> STEP_LEVEL_LEVEL_SHIFT);
837 }
838
839 public int getInitModeAt(int index) {
840 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
841 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
842 }
843
844 public int getModModeAt(int index) {
845 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
846 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
847 }
848
849 private void appendHex(long val, int topOffset, StringBuilder out) {
850 boolean hasData = false;
851 while (topOffset >= 0) {
852 int digit = (int)( (val>>topOffset) & 0xf );
853 topOffset -= 4;
854 if (!hasData && digit == 0) {
855 continue;
856 }
857 hasData = true;
858 if (digit >= 0 && digit <= 9) {
859 out.append((char)('0' + digit));
860 } else {
861 out.append((char)('a' + digit - 10));
862 }
863 }
864 }
865
866 public void encodeEntryAt(int index, StringBuilder out) {
867 long item = mStepDurations[index];
868 long duration = item & STEP_LEVEL_TIME_MASK;
869 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
870 >> STEP_LEVEL_LEVEL_SHIFT);
871 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
872 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
873 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
874 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
875 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
876 case Display.STATE_OFF: out.append('f'); break;
877 case Display.STATE_ON: out.append('o'); break;
878 case Display.STATE_DOZE: out.append('d'); break;
879 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
880 }
881 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
882 out.append('p');
883 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700884 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
885 out.append('i');
886 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800887 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
888 case Display.STATE_OFF: out.append('F'); break;
889 case Display.STATE_ON: out.append('O'); break;
890 case Display.STATE_DOZE: out.append('D'); break;
891 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
892 }
893 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
894 out.append('P');
895 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700896 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
897 out.append('I');
898 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800899 out.append('-');
900 appendHex(level, 4, out);
901 out.append('-');
902 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
903 }
904
905 public void decodeEntryAt(int index, String value) {
906 final int N = value.length();
907 int i = 0;
908 char c;
909 long out = 0;
910 while (i < N && (c=value.charAt(i)) != '-') {
911 i++;
912 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800913 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800914 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800915 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800916 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800917 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800918 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800919 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
920 << STEP_LEVEL_INITIAL_MODE_SHIFT);
921 break;
922 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
923 << STEP_LEVEL_INITIAL_MODE_SHIFT);
924 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700925 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
926 << STEP_LEVEL_INITIAL_MODE_SHIFT);
927 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800928 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
929 break;
930 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
931 break;
932 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
933 break;
934 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
935 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
936 break;
937 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
938 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800939 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700940 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
941 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
942 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800943 }
944 }
945 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800946 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800947 while (i < N && (c=value.charAt(i)) != '-') {
948 i++;
949 level <<= 4;
950 if (c >= '0' && c <= '9') {
951 level += c - '0';
952 } else if (c >= 'a' && c <= 'f') {
953 level += c - 'a' + 10;
954 } else if (c >= 'A' && c <= 'F') {
955 level += c - 'A' + 10;
956 }
957 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800958 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800959 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
960 long duration = 0;
961 while (i < N && (c=value.charAt(i)) != '-') {
962 i++;
963 duration <<= 4;
964 if (c >= '0' && c <= '9') {
965 duration += c - '0';
966 } else if (c >= 'a' && c <= 'f') {
967 duration += c - 'a' + 10;
968 } else if (c >= 'A' && c <= 'F') {
969 duration += c - 'A' + 10;
970 }
971 }
972 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
973 }
974
975 public void init() {
976 mLastStepTime = -1;
977 mNumStepDurations = 0;
978 }
979
980 public void clearTime() {
981 mLastStepTime = -1;
982 }
983
984 public long computeTimePerLevel() {
985 final long[] steps = mStepDurations;
986 final int numSteps = mNumStepDurations;
987
988 // For now we'll do a simple average across all steps.
989 if (numSteps <= 0) {
990 return -1;
991 }
992 long total = 0;
993 for (int i=0; i<numSteps; i++) {
994 total += steps[i] & STEP_LEVEL_TIME_MASK;
995 }
996 return total / numSteps;
997 /*
998 long[] buckets = new long[numSteps];
999 int numBuckets = 0;
1000 int numToAverage = 4;
1001 int i = 0;
1002 while (i < numSteps) {
1003 long totalTime = 0;
1004 int num = 0;
1005 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1006 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1007 num++;
1008 }
1009 buckets[numBuckets] = totalTime / num;
1010 numBuckets++;
1011 numToAverage *= 2;
1012 i += num;
1013 }
1014 if (numBuckets < 1) {
1015 return -1;
1016 }
1017 long averageTime = buckets[numBuckets-1];
1018 for (i=numBuckets-2; i>=0; i--) {
1019 averageTime = (averageTime + buckets[i]) / 2;
1020 }
1021 return averageTime;
1022 */
1023 }
1024
1025 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1026 int[] outNumOfInterest) {
1027 final long[] steps = mStepDurations;
1028 final int count = mNumStepDurations;
1029 if (count <= 0) {
1030 return -1;
1031 }
1032 long total = 0;
1033 int numOfInterest = 0;
1034 for (int i=0; i<count; i++) {
1035 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1036 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1037 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1038 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1039 // If the modes of interest didn't change during this step period...
1040 if ((modMode&modesOfInterest) == 0) {
1041 // And the mode values during this period match those we are measuring...
1042 if ((initMode&modesOfInterest) == modeValues) {
1043 // Then this can be used to estimate the total time!
1044 numOfInterest++;
1045 total += steps[i] & STEP_LEVEL_TIME_MASK;
1046 }
1047 }
1048 }
1049 if (numOfInterest <= 0) {
1050 return -1;
1051 }
1052
1053 if (outNumOfInterest != null) {
1054 outNumOfInterest[0] = numOfInterest;
1055 }
1056
1057 // The estimated time is the average time we spend in each level, multipled
1058 // by 100 -- the total number of battery levels
1059 return (total / numOfInterest) * 100;
1060 }
1061
1062 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1063 int stepCount = mNumStepDurations;
1064 final long lastStepTime = mLastStepTime;
1065 if (lastStepTime >= 0 && numStepLevels > 0) {
1066 final long[] steps = mStepDurations;
1067 long duration = elapsedRealtime - lastStepTime;
1068 for (int i=0; i<numStepLevels; i++) {
1069 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1070 long thisDuration = duration / (numStepLevels-i);
1071 duration -= thisDuration;
1072 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1073 thisDuration = STEP_LEVEL_TIME_MASK;
1074 }
1075 steps[0] = thisDuration | modeBits;
1076 }
1077 stepCount += numStepLevels;
1078 if (stepCount > steps.length) {
1079 stepCount = steps.length;
1080 }
1081 }
1082 mNumStepDurations = stepCount;
1083 mLastStepTime = elapsedRealtime;
1084 }
1085
1086 public void readFromParcel(Parcel in) {
1087 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001088 if (N > mStepDurations.length) {
1089 throw new ParcelFormatException("more step durations than available: " + N);
1090 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001091 mNumStepDurations = N;
1092 for (int i=0; i<N; i++) {
1093 mStepDurations[i] = in.readLong();
1094 }
1095 }
1096
1097 public void writeToParcel(Parcel out) {
1098 final int N = mNumStepDurations;
1099 out.writeInt(N);
1100 for (int i=0; i<N; i++) {
1101 out.writeLong(mStepDurations[i]);
1102 }
1103 }
1104 }
1105
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001106 public static final class PackageChange {
1107 public String mPackageName;
1108 public boolean mUpdate;
1109 public int mVersionCode;
1110 }
1111
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001112 public static final class DailyItem {
1113 public long mStartTime;
1114 public long mEndTime;
1115 public LevelStepTracker mDischargeSteps;
1116 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001117 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001118 }
1119
1120 public abstract DailyItem getDailyItemLocked(int daysAgo);
1121
1122 public abstract long getCurrentDailyStartTime();
1123
1124 public abstract long getNextMinDailyDeadline();
1125
1126 public abstract long getNextMaxDailyDeadline();
1127
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001128 public abstract long[] getCpuFreqs();
1129
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001130 public final static class HistoryTag {
1131 public String string;
1132 public int uid;
1133
1134 public int poolIdx;
1135
1136 public void setTo(HistoryTag o) {
1137 string = o.string;
1138 uid = o.uid;
1139 poolIdx = o.poolIdx;
1140 }
1141
1142 public void setTo(String _string, int _uid) {
1143 string = _string;
1144 uid = _uid;
1145 poolIdx = -1;
1146 }
1147
1148 public void writeToParcel(Parcel dest, int flags) {
1149 dest.writeString(string);
1150 dest.writeInt(uid);
1151 }
1152
1153 public void readFromParcel(Parcel src) {
1154 string = src.readString();
1155 uid = src.readInt();
1156 poolIdx = -1;
1157 }
1158
1159 @Override
1160 public boolean equals(Object o) {
1161 if (this == o) return true;
1162 if (o == null || getClass() != o.getClass()) return false;
1163
1164 HistoryTag that = (HistoryTag) o;
1165
1166 if (uid != that.uid) return false;
1167 if (!string.equals(that.string)) return false;
1168
1169 return true;
1170 }
1171
1172 @Override
1173 public int hashCode() {
1174 int result = string.hashCode();
1175 result = 31 * result + uid;
1176 return result;
1177 }
1178 }
1179
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001180 /**
1181 * Optional detailed information that can go into a history step. This is typically
1182 * generated each time the battery level changes.
1183 */
1184 public final static class HistoryStepDetails {
1185 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1186 public int userTime;
1187 public int systemTime;
1188
1189 // Top three apps using CPU in the last step, with times in 1/100 second.
1190 public int appCpuUid1;
1191 public int appCpuUTime1;
1192 public int appCpuSTime1;
1193 public int appCpuUid2;
1194 public int appCpuUTime2;
1195 public int appCpuSTime2;
1196 public int appCpuUid3;
1197 public int appCpuUTime3;
1198 public int appCpuSTime3;
1199
1200 // Information from /proc/stat
1201 public int statUserTime;
1202 public int statSystemTime;
1203 public int statIOWaitTime;
1204 public int statIrqTime;
1205 public int statSoftIrqTime;
1206 public int statIdlTime;
1207
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001208 // Platform-level low power state stats
1209 public String statPlatformIdleState;
1210
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001211 public HistoryStepDetails() {
1212 clear();
1213 }
1214
1215 public void clear() {
1216 userTime = systemTime = 0;
1217 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
1218 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
1219 = appCpuUTime3 = appCpuSTime3 = 0;
1220 }
1221
1222 public void writeToParcel(Parcel out) {
1223 out.writeInt(userTime);
1224 out.writeInt(systemTime);
1225 out.writeInt(appCpuUid1);
1226 out.writeInt(appCpuUTime1);
1227 out.writeInt(appCpuSTime1);
1228 out.writeInt(appCpuUid2);
1229 out.writeInt(appCpuUTime2);
1230 out.writeInt(appCpuSTime2);
1231 out.writeInt(appCpuUid3);
1232 out.writeInt(appCpuUTime3);
1233 out.writeInt(appCpuSTime3);
1234 out.writeInt(statUserTime);
1235 out.writeInt(statSystemTime);
1236 out.writeInt(statIOWaitTime);
1237 out.writeInt(statIrqTime);
1238 out.writeInt(statSoftIrqTime);
1239 out.writeInt(statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001240 out.writeString(statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001241 }
1242
1243 public void readFromParcel(Parcel in) {
1244 userTime = in.readInt();
1245 systemTime = in.readInt();
1246 appCpuUid1 = in.readInt();
1247 appCpuUTime1 = in.readInt();
1248 appCpuSTime1 = in.readInt();
1249 appCpuUid2 = in.readInt();
1250 appCpuUTime2 = in.readInt();
1251 appCpuSTime2 = in.readInt();
1252 appCpuUid3 = in.readInt();
1253 appCpuUTime3 = in.readInt();
1254 appCpuSTime3 = in.readInt();
1255 statUserTime = in.readInt();
1256 statSystemTime = in.readInt();
1257 statIOWaitTime = in.readInt();
1258 statIrqTime = in.readInt();
1259 statSoftIrqTime = in.readInt();
1260 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001261 statPlatformIdleState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001262 }
1263 }
1264
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001265 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001266 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001267
1268 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001269 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001270
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001271 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001272 public static final byte CMD_NULL = -1;
1273 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001274 public static final byte CMD_CURRENT_TIME = 5;
1275 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001276 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001277 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001278
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001279 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001280
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001281 /**
1282 * Return whether the command code is a delta data update.
1283 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001284 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001285 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001286 }
1287
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001288 public byte batteryLevel;
1289 public byte batteryStatus;
1290 public byte batteryHealth;
1291 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001292
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001293 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001294 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001295
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001296 // The charge of the battery in micro-Ampere-hours.
1297 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001298
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001299 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001300 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001301 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001302 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001303 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1304 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001305 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001306 public static final int STATE_PHONE_STATE_SHIFT = 6;
1307 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001308 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001309 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001310 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001311
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001312 // These states always appear directly in the first int token
1313 // of a delta change; they should be ones that change relatively
1314 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001315 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1316 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001317 public static final int STATE_GPS_ON_FLAG = 1<<29;
1318 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001319 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001320 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001321 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001322 // Do not use, this is used for coulomb delta count.
1323 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001324 // These are on the lower bits used for the command; if they change
1325 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001326 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001327 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001328 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001329 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1330 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1331 // empty slot
1332 // empty slot
1333 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001334
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001335 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001336 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1337
1338 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001339
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001340 public int states;
1341
Dianne Hackborn3251b902014-06-20 14:40:53 -07001342 // Constants from WIFI_SUPPL_STATE_*
1343 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1344 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1345 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1346 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1347 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1348 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1349
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001350 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001351 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1352 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1353 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001354 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001355 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1356 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1357 public static final int STATE2_CHARGING_FLAG = 1<<24;
1358 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1359 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1360 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001361 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001362
1363 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001364 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001365 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1366
1367 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001368
Dianne Hackborn40c87252014-03-19 16:55:40 -07001369 public int states2;
1370
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001371 // The wake lock that was acquired at this point.
1372 public HistoryTag wakelockTag;
1373
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001374 // Kernel wakeup reason at this point.
1375 public HistoryTag wakeReasonTag;
1376
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001377 // Non-null when there is more detailed information at this step.
1378 public HistoryStepDetails stepDetails;
1379
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001380 public static final int EVENT_FLAG_START = 0x8000;
1381 public static final int EVENT_FLAG_FINISH = 0x4000;
1382
1383 // No event in this item.
1384 public static final int EVENT_NONE = 0x0000;
1385 // Event is about a process that is running.
1386 public static final int EVENT_PROC = 0x0001;
1387 // Event is about an application package that is in the foreground.
1388 public static final int EVENT_FOREGROUND = 0x0002;
1389 // Event is about an application package that is at the top of the screen.
1390 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001391 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001392 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001393 // Events for all additional wake locks aquired/release within a wake block.
1394 // These are not generated by default.
1395 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001396 // Event is about an application executing a scheduled job.
1397 public static final int EVENT_JOB = 0x0006;
1398 // Events for users running.
1399 public static final int EVENT_USER_RUNNING = 0x0007;
1400 // Events for foreground user.
1401 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001402 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001403 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001404 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001405 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001406 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001407 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001408 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001409 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001410 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001411 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001412 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001413 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001414 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001415 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001416 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001417 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001418 // Event for a package being on the temporary whitelist.
1419 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001420 // Event for the screen waking up.
1421 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001422 // Event for the UID that woke up the application processor.
1423 // Used for wakeups coming from WiFi, modem, etc.
1424 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001425 // Event for reporting that a specific partial wake lock has been held for a long duration.
1426 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001427
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001428 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001429 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001430 // Mask to extract out only the type part of the event.
1431 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001432
1433 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1434 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1435 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1436 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1437 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1438 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001439 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1440 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001441 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1442 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001443 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1444 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1445 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1446 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1447 public static final int EVENT_USER_FOREGROUND_START =
1448 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1449 public static final int EVENT_USER_FOREGROUND_FINISH =
1450 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001451 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1452 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001453 public static final int EVENT_TEMP_WHITELIST_START =
1454 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1455 public static final int EVENT_TEMP_WHITELIST_FINISH =
1456 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001457 public static final int EVENT_LONG_WAKE_LOCK_START =
1458 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1459 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1460 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001461
1462 // For CMD_EVENT.
1463 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001464 public HistoryTag eventTag;
1465
Dianne Hackborn9a755432014-05-15 17:05:22 -07001466 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001467 public long currentTime;
1468
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001469 // Meta-data when reading.
1470 public int numReadInts;
1471
1472 // Pre-allocated objects.
1473 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001474 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001475 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001476
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001477 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001478 }
Bookatzc8c44962017-05-11 12:12:54 -07001479
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001480 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001481 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001482 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001483 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001484 }
Bookatzc8c44962017-05-11 12:12:54 -07001485
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001486 public int describeContents() {
1487 return 0;
1488 }
1489
1490 public void writeToParcel(Parcel dest, int flags) {
1491 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001492 int bat = (((int)cmd)&0xff)
1493 | ((((int)batteryLevel)<<8)&0xff00)
1494 | ((((int)batteryStatus)<<16)&0xf0000)
1495 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001496 | ((((int)batteryPlugType)<<24)&0xf000000)
1497 | (wakelockTag != null ? 0x10000000 : 0)
1498 | (wakeReasonTag != null ? 0x20000000 : 0)
1499 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001500 dest.writeInt(bat);
1501 bat = (((int)batteryTemperature)&0xffff)
1502 | ((((int)batteryVoltage)<<16)&0xffff0000);
1503 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001504 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001505 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001506 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001507 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001508 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001509 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001510 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001511 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001512 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001513 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001514 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001515 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001516 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001517 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001518 dest.writeLong(currentTime);
1519 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001520 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001521
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001522 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001523 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001524 int bat = src.readInt();
1525 cmd = (byte)(bat&0xff);
1526 batteryLevel = (byte)((bat>>8)&0xff);
1527 batteryStatus = (byte)((bat>>16)&0xf);
1528 batteryHealth = (byte)((bat>>20)&0xf);
1529 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001530 int bat2 = src.readInt();
1531 batteryTemperature = (short)(bat2&0xffff);
1532 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001533 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001534 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001535 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001536 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001537 wakelockTag = localWakelockTag;
1538 wakelockTag.readFromParcel(src);
1539 } else {
1540 wakelockTag = null;
1541 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001542 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001543 wakeReasonTag = localWakeReasonTag;
1544 wakeReasonTag.readFromParcel(src);
1545 } else {
1546 wakeReasonTag = null;
1547 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001548 if ((bat&0x40000000) != 0) {
1549 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001550 eventTag = localEventTag;
1551 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001552 } else {
1553 eventCode = EVENT_NONE;
1554 eventTag = null;
1555 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001556 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001557 currentTime = src.readLong();
1558 } else {
1559 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001560 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001561 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001562 }
1563
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001564 public void clear() {
1565 time = 0;
1566 cmd = CMD_NULL;
1567 batteryLevel = 0;
1568 batteryStatus = 0;
1569 batteryHealth = 0;
1570 batteryPlugType = 0;
1571 batteryTemperature = 0;
1572 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001573 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001574 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001575 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001576 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001577 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001578 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001579 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001580 }
Bookatzc8c44962017-05-11 12:12:54 -07001581
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001582 public void setTo(HistoryItem o) {
1583 time = o.time;
1584 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001585 setToCommon(o);
1586 }
1587
1588 public void setTo(long time, byte cmd, HistoryItem o) {
1589 this.time = time;
1590 this.cmd = cmd;
1591 setToCommon(o);
1592 }
1593
1594 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001595 batteryLevel = o.batteryLevel;
1596 batteryStatus = o.batteryStatus;
1597 batteryHealth = o.batteryHealth;
1598 batteryPlugType = o.batteryPlugType;
1599 batteryTemperature = o.batteryTemperature;
1600 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001601 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001602 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001603 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001604 if (o.wakelockTag != null) {
1605 wakelockTag = localWakelockTag;
1606 wakelockTag.setTo(o.wakelockTag);
1607 } else {
1608 wakelockTag = null;
1609 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001610 if (o.wakeReasonTag != null) {
1611 wakeReasonTag = localWakeReasonTag;
1612 wakeReasonTag.setTo(o.wakeReasonTag);
1613 } else {
1614 wakeReasonTag = null;
1615 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001616 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001617 if (o.eventTag != null) {
1618 eventTag = localEventTag;
1619 eventTag.setTo(o.eventTag);
1620 } else {
1621 eventTag = null;
1622 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001623 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001624 }
1625
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001626 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001627 return batteryLevel == o.batteryLevel
1628 && batteryStatus == o.batteryStatus
1629 && batteryHealth == o.batteryHealth
1630 && batteryPlugType == o.batteryPlugType
1631 && batteryTemperature == o.batteryTemperature
1632 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001633 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001634 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001635 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001636 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001637 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001638
1639 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001640 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001641 return false;
1642 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001643 if (wakelockTag != o.wakelockTag) {
1644 if (wakelockTag == null || o.wakelockTag == null) {
1645 return false;
1646 }
1647 if (!wakelockTag.equals(o.wakelockTag)) {
1648 return false;
1649 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001650 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001651 if (wakeReasonTag != o.wakeReasonTag) {
1652 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1653 return false;
1654 }
1655 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1656 return false;
1657 }
1658 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001659 if (eventTag != o.eventTag) {
1660 if (eventTag == null || o.eventTag == null) {
1661 return false;
1662 }
1663 if (!eventTag.equals(o.eventTag)) {
1664 return false;
1665 }
1666 }
1667 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001668 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001669 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001670
1671 public final static class HistoryEventTracker {
1672 private final HashMap<String, SparseIntArray>[] mActiveEvents
1673 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1674
1675 public boolean updateState(int code, String name, int uid, int poolIdx) {
1676 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1677 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1678 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1679 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001680 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001681 mActiveEvents[idx] = active;
1682 }
1683 SparseIntArray uids = active.get(name);
1684 if (uids == null) {
1685 uids = new SparseIntArray();
1686 active.put(name, uids);
1687 }
1688 if (uids.indexOfKey(uid) >= 0) {
1689 // Already set, nothing to do!
1690 return false;
1691 }
1692 uids.put(uid, poolIdx);
1693 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1694 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1695 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1696 if (active == null) {
1697 // not currently active, nothing to do.
1698 return false;
1699 }
1700 SparseIntArray uids = active.get(name);
1701 if (uids == null) {
1702 // not currently active, nothing to do.
1703 return false;
1704 }
1705 idx = uids.indexOfKey(uid);
1706 if (idx < 0) {
1707 // not currently active, nothing to do.
1708 return false;
1709 }
1710 uids.removeAt(idx);
1711 if (uids.size() <= 0) {
1712 active.remove(name);
1713 }
1714 }
1715 return true;
1716 }
1717
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001718 public void removeEvents(int code) {
1719 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1720 mActiveEvents[idx] = null;
1721 }
1722
Dianne Hackborn37de0982014-05-09 09:32:18 -07001723 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1724 return mActiveEvents[code];
1725 }
1726 }
1727
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001728 public static final class BitDescription {
1729 public final int mask;
1730 public final int shift;
1731 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001732 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001733 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001734 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001735
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001736 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001737 this.mask = mask;
1738 this.shift = -1;
1739 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001740 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001741 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001742 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001743 }
Bookatzc8c44962017-05-11 12:12:54 -07001744
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001745 public BitDescription(int mask, int shift, String name, String shortName,
1746 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001747 this.mask = mask;
1748 this.shift = shift;
1749 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001750 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001751 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001752 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001753 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001754 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001755
Dianne Hackbornfc064132014-06-02 12:42:12 -07001756 /**
1757 * Don't allow any more batching in to the current history event. This
1758 * is called when printing partial histories, so to ensure that the next
1759 * history event will go in to a new batch after what was printed in the
1760 * last partial history.
1761 */
1762 public abstract void commitCurrentHistoryBatchLocked();
1763
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001764 public abstract int getHistoryTotalSize();
1765
1766 public abstract int getHistoryUsedSize();
1767
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001768 public abstract boolean startIteratingHistoryLocked();
1769
Dianne Hackborn099bc622014-01-22 13:39:16 -08001770 public abstract int getHistoryStringPoolSize();
1771
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001772 public abstract int getHistoryStringPoolBytes();
1773
1774 public abstract String getHistoryTagPoolString(int index);
1775
1776 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001777
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001778 public abstract boolean getNextHistoryLocked(HistoryItem out);
1779
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001780 public abstract void finishIteratingHistoryLocked();
1781
1782 public abstract boolean startIteratingOldHistoryLocked();
1783
1784 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1785
1786 public abstract void finishIteratingOldHistoryLocked();
1787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001788 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001789 * Return the base time offset for the battery history.
1790 */
1791 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001792
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001793 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 * Returns the number of times the device has been started.
1795 */
1796 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001799 * 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 -08001800 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001801 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001802 * {@hide}
1803 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001804 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001805
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001806 /**
1807 * Returns the number of times the screen was turned on.
1808 *
1809 * {@hide}
1810 */
1811 public abstract int getScreenOnCount(int which);
1812
Jeff Browne95c3cd2014-05-02 16:59:26 -07001813 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1814
Dianne Hackborn617f8772009-03-31 15:04:46 -07001815 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1816 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1817 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1818 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1819 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001820
Dianne Hackborn617f8772009-03-31 15:04:46 -07001821 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1822 "dark", "dim", "medium", "light", "bright"
1823 };
Bookatzc8c44962017-05-11 12:12:54 -07001824
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001825 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1826 "0", "1", "2", "3", "4"
1827 };
1828
Dianne Hackborn617f8772009-03-31 15:04:46 -07001829 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001830
Dianne Hackborn617f8772009-03-31 15:04:46 -07001831 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001832 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001833 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001834 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001835 * {@hide}
1836 */
1837 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001838 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001840 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001841 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001842 * running on battery.
1843 *
1844 * {@hide}
1845 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001846 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001847
1848 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001849 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001850 *
1851 * {@hide}
1852 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001853 public abstract int getPowerSaveModeEnabledCount(int which);
1854
1855 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001856 * Constant for device idle mode: not active.
1857 */
1858 public static final int DEVICE_IDLE_MODE_OFF = 0;
1859
1860 /**
1861 * Constant for device idle mode: active in lightweight mode.
1862 */
1863 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1864
1865 /**
1866 * Constant for device idle mode: active in full mode.
1867 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001868 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001869
1870 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001871 * Returns the time in microseconds that device has been in idle mode while
1872 * running on battery.
1873 *
1874 * {@hide}
1875 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001876 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001877
1878 /**
1879 * Returns the number of times that the devie has gone in to idle mode.
1880 *
1881 * {@hide}
1882 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001883 public abstract int getDeviceIdleModeCount(int mode, int which);
1884
1885 /**
1886 * Return the longest duration we spent in a particular device idle mode (fully in the
1887 * mode, not in idle maintenance etc).
1888 */
1889 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001890
1891 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001892 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001893 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001894 * counts all of the time that we consider the device to be idle, whether or not
1895 * it is currently in the actual device idle mode.
1896 *
1897 * {@hide}
1898 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001899 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001900
1901 /**
1902 * Returns the number of times that the devie has started idling.
1903 *
1904 * {@hide}
1905 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001906 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001907
1908 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001909 * Returns the number of times that connectivity state changed.
1910 *
1911 * {@hide}
1912 */
1913 public abstract int getNumConnectivityChange(int which);
1914
1915 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001916 * 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 -08001917 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001918 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001919 * {@hide}
1920 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001921 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001922
Dianne Hackborn627bba72009-03-24 22:32:56 -07001923 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001924 * Returns the number of times a phone call was activated.
1925 *
1926 * {@hide}
1927 */
1928 public abstract int getPhoneOnCount(int which);
1929
1930 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001931 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001932 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001933 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07001934 * {@hide}
1935 */
1936 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001937 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001938
Dianne Hackborn617f8772009-03-31 15:04:46 -07001939 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001940 * Returns the time in microseconds that the phone has been trying to
1941 * acquire a signal.
1942 *
1943 * {@hide}
1944 */
1945 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001946 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001947
1948 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001949 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001950 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001951 * {@hide}
1952 */
1953 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1954
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001955 /**
1956 * Returns the time in microseconds that the mobile network has been active
1957 * (in a high power state).
1958 *
1959 * {@hide}
1960 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001961 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001962
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001963 /**
1964 * Returns the number of times that the mobile network has transitioned to the
1965 * active state.
1966 *
1967 * {@hide}
1968 */
1969 public abstract int getMobileRadioActiveCount(int which);
1970
1971 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001972 * Returns the time in microseconds that is the difference between the mobile radio
1973 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1974 * from the radio.
1975 *
1976 * {@hide}
1977 */
1978 public abstract long getMobileRadioActiveAdjustedTime(int which);
1979
1980 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001981 * Returns the time in microseconds that the mobile network has been active
1982 * (in a high power state) but not being able to blame on an app.
1983 *
1984 * {@hide}
1985 */
1986 public abstract long getMobileRadioActiveUnknownTime(int which);
1987
1988 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001989 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001990 *
1991 * {@hide}
1992 */
1993 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001994
Dianne Hackborn627bba72009-03-24 22:32:56 -07001995 public static final int DATA_CONNECTION_NONE = 0;
1996 public static final int DATA_CONNECTION_GPRS = 1;
1997 public static final int DATA_CONNECTION_EDGE = 2;
1998 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001999 public static final int DATA_CONNECTION_CDMA = 4;
2000 public static final int DATA_CONNECTION_EVDO_0 = 5;
2001 public static final int DATA_CONNECTION_EVDO_A = 6;
2002 public static final int DATA_CONNECTION_1xRTT = 7;
2003 public static final int DATA_CONNECTION_HSDPA = 8;
2004 public static final int DATA_CONNECTION_HSUPA = 9;
2005 public static final int DATA_CONNECTION_HSPA = 10;
2006 public static final int DATA_CONNECTION_IDEN = 11;
2007 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002008 public static final int DATA_CONNECTION_LTE = 13;
2009 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002010 public static final int DATA_CONNECTION_HSPAP = 15;
2011 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002012
Dianne Hackborn627bba72009-03-24 22:32:56 -07002013 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002014 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002015 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002016 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002017 };
Bookatzc8c44962017-05-11 12:12:54 -07002018
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002019 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002020
Dianne Hackborn627bba72009-03-24 22:32:56 -07002021 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002022 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002023 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002024 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002025 * {@hide}
2026 */
2027 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002028 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002031 * Returns the number of times the phone has entered the given data
2032 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002033 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002034 * {@hide}
2035 */
2036 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002037
Dianne Hackborn3251b902014-06-20 14:40:53 -07002038 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2039 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2040 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2041 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2042 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2043 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2044 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2045 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2046 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2047 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2048 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2049 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2050 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2051
2052 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2053
2054 static final String[] WIFI_SUPPL_STATE_NAMES = {
2055 "invalid", "disconn", "disabled", "inactive", "scanning",
2056 "authenticating", "associating", "associated", "4-way-handshake",
2057 "group-handshake", "completed", "dormant", "uninit"
2058 };
2059
2060 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2061 "inv", "dsc", "dis", "inact", "scan",
2062 "auth", "ascing", "asced", "4-way",
2063 "group", "compl", "dorm", "uninit"
2064 };
2065
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002066 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
2067 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002068 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002069 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2070 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002071 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002072 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2073 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2074 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002075 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002076 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002077 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002078 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002079 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2080 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002081 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2082 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2083 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2084 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2085 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2086 new String[] {"in", "out", "emergency", "off"},
2087 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002088 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2089 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2090 SignalStrength.SIGNAL_STRENGTH_NAMES,
2091 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002092 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2093 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2094 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002095 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002096
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002097 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2098 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002099 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002100 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002101 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002102 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002103 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002104 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2105 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2106 new String[] { "off", "light", "full", "???" },
2107 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002108 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2109 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2110 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002111 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2112 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2113 new String[] { "0", "1", "2", "3", "4" },
2114 new String[] { "0", "1", "2", "3", "4" }),
2115 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2116 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2117 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002118 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002119 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002120 };
2121
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002122 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002123 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002124 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2125 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002126 };
2127
2128 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002129 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002130 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002131 "Esw", "Ewa", "Elw", "Eec"
2132 };
2133
2134 @FunctionalInterface
2135 public interface IntToString {
2136 String applyAsString(int val);
2137 }
2138
2139 private static final IntToString sUidToString = UserHandle::formatUid;
2140 private static final IntToString sIntToString = Integer::toString;
2141
2142 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2143 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2144 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2145 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2146 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002147 };
2148
Dianne Hackborn617f8772009-03-31 15:04:46 -07002149 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002150 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002151 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002152 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002153 * {@hide}
2154 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002155 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002156
2157 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002158 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002159 * been in the running state while the device was running on battery.
2160 *
2161 * {@hide}
2162 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002163 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002164
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002165 public static final int WIFI_STATE_OFF = 0;
2166 public static final int WIFI_STATE_OFF_SCANNING = 1;
2167 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2168 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2169 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2170 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2171 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2172 public static final int WIFI_STATE_SOFT_AP = 7;
2173
2174 static final String[] WIFI_STATE_NAMES = {
2175 "off", "scanning", "no_net", "disconn",
2176 "sta", "p2p", "sta_p2p", "soft_ap"
2177 };
2178
2179 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2180
2181 /**
2182 * Returns the time in microseconds that WiFi has been running in the given state.
2183 *
2184 * {@hide}
2185 */
2186 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002187 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002188
2189 /**
2190 * Returns the number of times that WiFi has entered the given state.
2191 *
2192 * {@hide}
2193 */
2194 public abstract int getWifiStateCount(int wifiState, int which);
2195
The Android Open Source Project10592532009-03-18 17:39:46 -07002196 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002197 * Returns the time in microseconds that the wifi supplicant has been
2198 * in a given state.
2199 *
2200 * {@hide}
2201 */
2202 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2203
2204 /**
2205 * Returns the number of times that the wifi supplicant has transitioned
2206 * to a given state.
2207 *
2208 * {@hide}
2209 */
2210 public abstract int getWifiSupplStateCount(int state, int which);
2211
2212 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2213
2214 /**
2215 * Returns the time in microseconds that WIFI has been running with
2216 * the given signal strength.
2217 *
2218 * {@hide}
2219 */
2220 public abstract long getWifiSignalStrengthTime(int strengthBin,
2221 long elapsedRealtimeUs, int which);
2222
2223 /**
2224 * Returns the number of times WIFI has entered the given signal strength.
2225 *
2226 * {@hide}
2227 */
2228 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2229
2230 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002231 * Returns the time in microseconds that the flashlight has been on while the device was
2232 * running on battery.
2233 *
2234 * {@hide}
2235 */
2236 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2237
2238 /**
2239 * Returns the number of times that the flashlight has been turned on while the device was
2240 * running on battery.
2241 *
2242 * {@hide}
2243 */
2244 public abstract long getFlashlightOnCount(int which);
2245
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002246 /**
2247 * Returns the time in microseconds that the camera has been on while the device was
2248 * running on battery.
2249 *
2250 * {@hide}
2251 */
2252 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2253
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002254 /**
2255 * Returns the time in microseconds that bluetooth scans were running while the device was
2256 * on battery.
2257 *
2258 * {@hide}
2259 */
2260 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002261
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002262 public static final int NETWORK_MOBILE_RX_DATA = 0;
2263 public static final int NETWORK_MOBILE_TX_DATA = 1;
2264 public static final int NETWORK_WIFI_RX_DATA = 2;
2265 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002266 public static final int NETWORK_BT_RX_DATA = 4;
2267 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002268 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2269 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2270 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2271 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2272 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002273
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002274 public abstract long getNetworkActivityBytes(int type, int which);
2275 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002276
Adam Lesinskie08af192015-03-25 16:42:59 -07002277 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002278 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002279 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002280 * actual power data.
2281 */
2282 public abstract boolean hasWifiActivityReporting();
2283
2284 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002285 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2286 * in various radio controller states, such as transmit, receive, and idle.
2287 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002288 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002289 public abstract ControllerActivityCounter getWifiControllerActivity();
2290
2291 /**
2292 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2293 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2294 * actual power data.
2295 */
2296 public abstract boolean hasBluetoothActivityReporting();
2297
2298 /**
2299 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2300 * in various radio controller states, such as transmit, receive, and idle.
2301 * @return non-null {@link ControllerActivityCounter}
2302 */
2303 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2304
2305 /**
2306 * Returns true if the BatteryStats object has detailed modem power reports.
2307 * When true, calling {@link #getModemControllerActivity()} will yield the
2308 * actual power data.
2309 */
2310 public abstract boolean hasModemActivityReporting();
2311
2312 /**
2313 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2314 * in various radio controller states, such as transmit, receive, and idle.
2315 * @return non-null {@link ControllerActivityCounter}
2316 */
2317 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002318
The Android Open Source Project10592532009-03-18 17:39:46 -07002319 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002320 * Return the wall clock time when battery stats data collection started.
2321 */
2322 public abstract long getStartClockTime();
2323
2324 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002325 * Return platform version tag that we were running in when the battery stats started.
2326 */
2327 public abstract String getStartPlatformVersion();
2328
2329 /**
2330 * Return platform version tag that we were running in when the battery stats ended.
2331 */
2332 public abstract String getEndPlatformVersion();
2333
2334 /**
2335 * Return the internal version code of the parcelled format.
2336 */
2337 public abstract int getParcelVersion();
2338
2339 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002340 * Return whether we are currently running on battery.
2341 */
2342 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 /**
2345 * Returns a SparseArray containing the statistics for each uid.
2346 */
2347 public abstract SparseArray<? extends Uid> getUidStats();
2348
2349 /**
2350 * Returns the current battery uptime in microseconds.
2351 *
2352 * @param curTime the amount of elapsed realtime in microseconds.
2353 */
2354 public abstract long getBatteryUptime(long curTime);
2355
2356 /**
2357 * Returns the current battery realtime in microseconds.
2358 *
2359 * @param curTime the amount of elapsed realtime in microseconds.
2360 */
2361 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002362
The Android Open Source Project10592532009-03-18 17:39:46 -07002363 /**
Evan Millar633a1742009-04-02 16:36:33 -07002364 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002365 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002366 */
Evan Millar633a1742009-04-02 16:36:33 -07002367 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002368
The Android Open Source Project10592532009-03-18 17:39:46 -07002369 /**
Evan Millar633a1742009-04-02 16:36:33 -07002370 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2371 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002372 */
Evan Millar633a1742009-04-02 16:36:33 -07002373 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374
2375 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002376 * Get the amount the battery has discharged since the stats were
2377 * last reset after charging, as a lower-end approximation.
2378 */
2379 public abstract int getLowDischargeAmountSinceCharge();
2380
2381 /**
2382 * Get the amount the battery has discharged since the stats were
2383 * last reset after charging, as an upper-end approximation.
2384 */
2385 public abstract int getHighDischargeAmountSinceCharge();
2386
2387 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002388 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2389 */
2390 public abstract int getDischargeAmount(int which);
2391
2392 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002393 * Get the amount the battery has discharged while the screen was on,
2394 * since the last time power was unplugged.
2395 */
2396 public abstract int getDischargeAmountScreenOn();
2397
2398 /**
2399 * Get the amount the battery has discharged while the screen was on,
2400 * since the last time the device was charged.
2401 */
2402 public abstract int getDischargeAmountScreenOnSinceCharge();
2403
2404 /**
2405 * Get the amount the battery has discharged while the screen was off,
2406 * since the last time power was unplugged.
2407 */
2408 public abstract int getDischargeAmountScreenOff();
2409
2410 /**
2411 * Get the amount the battery has discharged while the screen was off,
2412 * since the last time the device was charged.
2413 */
2414 public abstract int getDischargeAmountScreenOffSinceCharge();
2415
2416 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 * Returns the total, last, or current battery uptime in microseconds.
2418 *
2419 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002420 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 */
2422 public abstract long computeBatteryUptime(long curTime, int which);
2423
2424 /**
2425 * Returns the total, last, or current battery realtime in microseconds.
2426 *
2427 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002428 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 */
2430 public abstract long computeBatteryRealtime(long curTime, int which);
2431
2432 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002433 * Returns the total, last, or current battery screen off uptime in microseconds.
2434 *
2435 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002436 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002437 */
2438 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2439
2440 /**
2441 * Returns the total, last, or current battery screen off realtime in microseconds.
2442 *
2443 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002444 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002445 */
2446 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2447
2448 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 * Returns the total, last, or current uptime in microseconds.
2450 *
2451 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002452 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 */
2454 public abstract long computeUptime(long curTime, int which);
2455
2456 /**
2457 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002458 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002460 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 */
2462 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002463
2464 /**
2465 * Compute an approximation for how much run time (in microseconds) is remaining on
2466 * the battery. Returns -1 if no time can be computed: either there is not
2467 * enough current data to make a decision, or the battery is currently
2468 * charging.
2469 *
2470 * @param curTime The current elepsed realtime in microseconds.
2471 */
2472 public abstract long computeBatteryTimeRemaining(long curTime);
2473
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002474 // The part of a step duration that is the actual time.
2475 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2476
2477 // Bits in a step duration that are the new battery level we are at.
2478 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002479 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002480
2481 // Bits in a step duration that are the initial mode we were in at that step.
2482 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002483 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002484
2485 // Bits in a step duration that indicate which modes changed during that step.
2486 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002487 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002488
2489 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2490 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2491
Santos Cordone94f0502017-02-24 12:31:20 -08002492 // The largest value for screen state that is tracked in battery states. Any values above
2493 // this should be mapped back to one of the tracked values before being tracked here.
2494 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2495
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002496 // Step duration mode: power save is on.
2497 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2498
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002499 // Step duration mode: device is currently in idle mode.
2500 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2501
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002502 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2503 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002504 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2505 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002506 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,
2510 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002511 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2512 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002513 };
2514 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2515 (Display.STATE_OFF-1),
2516 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002517 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002518 (Display.STATE_ON-1),
2519 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2520 (Display.STATE_DOZE-1),
2521 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2522 (Display.STATE_DOZE_SUSPEND-1),
2523 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002524 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002525 };
2526 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2527 "screen off",
2528 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002529 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002530 "screen on",
2531 "screen on power save",
2532 "screen doze",
2533 "screen doze power save",
2534 "screen doze-suspend",
2535 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002536 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002537 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002538
2539 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002540 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2541 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2542 * a coulomb counter.
2543 */
2544 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2545
2546 /**
2547 * Return the counter keeping track of the amount of battery discharge measured in
2548 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2549 * a coulomb counter.
2550 */
2551 public abstract LongCounter getDischargeCoulombCounter();
2552
2553 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002554 * Returns the estimated real battery capacity, which may be less than the capacity
2555 * declared by the PowerProfile.
2556 * @return The estimated battery capacity in mAh.
2557 */
2558 public abstract int getEstimatedBatteryCapacity();
2559
2560 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002561 * @return The minimum learned battery capacity in uAh.
2562 */
2563 public abstract int getMinLearnedBatteryCapacity();
2564
2565 /**
2566 * @return The maximum learned battery capacity in uAh.
2567 */
2568 public abstract int getMaxLearnedBatteryCapacity() ;
2569
2570 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002571 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002572 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002573 public abstract LevelStepTracker getDischargeLevelStepTracker();
2574
2575 /**
2576 * Return the array of daily discharge step durations.
2577 */
2578 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002579
2580 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002581 * Compute an approximation for how much time (in microseconds) remains until the battery
2582 * is fully charged. Returns -1 if no time can be computed: either there is not
2583 * enough current data to make a decision, or the battery is currently
2584 * discharging.
2585 *
2586 * @param curTime The current elepsed realtime in microseconds.
2587 */
2588 public abstract long computeChargeTimeRemaining(long curTime);
2589
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002590 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002591 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002592 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002593 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002594
2595 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002596 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002597 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002598 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002599
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002600 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2601
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002602 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002603
Evan Millarc64edde2009-04-18 12:26:32 -07002604 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002605
James Carr2dd7e5e2016-07-20 18:48:39 -07002606 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2607
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002608 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2609
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002610 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002611 long days = seconds / (60 * 60 * 24);
2612 if (days != 0) {
2613 out.append(days);
2614 out.append("d ");
2615 }
2616 long used = days * 60 * 60 * 24;
2617
2618 long hours = (seconds - used) / (60 * 60);
2619 if (hours != 0 || used != 0) {
2620 out.append(hours);
2621 out.append("h ");
2622 }
2623 used += hours * 60 * 60;
2624
2625 long mins = (seconds-used) / 60;
2626 if (mins != 0 || used != 0) {
2627 out.append(mins);
2628 out.append("m ");
2629 }
2630 used += mins * 60;
2631
2632 if (seconds != 0 || used != 0) {
2633 out.append(seconds-used);
2634 out.append("s ");
2635 }
2636 }
2637
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002638 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002639 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002640 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 sb.append(time - (sec * 1000));
2642 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 }
2644
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002645 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002646 long sec = time / 1000;
2647 formatTimeRaw(sb, sec);
2648 sb.append(time - (sec * 1000));
2649 sb.append("ms");
2650 }
2651
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002652 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002654 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 }
2656 float perc = ((float)num) / ((float)den) * 100;
2657 mFormatBuilder.setLength(0);
2658 mFormatter.format("%.1f%%", perc);
2659 return mFormatBuilder.toString();
2660 }
2661
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002662 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002663 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002664
Evan Millar22ac0432009-03-31 11:33:18 -07002665 if (bytes < BYTES_PER_KB) {
2666 return bytes + "B";
2667 } else if (bytes < BYTES_PER_MB) {
2668 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2669 return mFormatBuilder.toString();
2670 } else if (bytes < BYTES_PER_GB){
2671 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2672 return mFormatBuilder.toString();
2673 } else {
2674 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2675 return mFormatBuilder.toString();
2676 }
2677 }
2678
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002679 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002680 if (timer != null) {
2681 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002682 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002683 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2684 return totalTimeMillis;
2685 }
2686 return 0;
2687 }
2688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002689 /**
2690 *
2691 * @param sb a StringBuilder object.
2692 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002693 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002694 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002695 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 * @param linePrefix a String to be prepended to each line of output.
2697 * @return the line prefix
2698 */
2699 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002700 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002703 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002704
Evan Millarc64edde2009-04-18 12:26:32 -07002705 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002706 if (totalTimeMillis != 0) {
2707 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002708 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002709 if (name != null) {
2710 sb.append(name);
2711 sb.append(' ');
2712 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 sb.append('(');
2714 sb.append(count);
2715 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002716 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2717 if (maxDurationMs >= 0) {
2718 sb.append(" max=");
2719 sb.append(maxDurationMs);
2720 }
Bookatz506a8182017-05-01 14:18:42 -07002721 // Put actual time if it is available and different from totalTimeMillis.
2722 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2723 if (totalDurMs > totalTimeMillis) {
2724 sb.append(" actual=");
2725 sb.append(totalDurMs);
2726 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002727 if (timer.isRunningLocked()) {
2728 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2729 if (currentMs >= 0) {
2730 sb.append(" (running for ");
2731 sb.append(currentMs);
2732 sb.append("ms)");
2733 } else {
2734 sb.append(" (running)");
2735 }
2736 }
2737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 return ", ";
2739 }
2740 }
2741 return linePrefix;
2742 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002743
2744 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002745 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002746 *
2747 * @param pw a PrintWriter object to print to.
2748 * @param sb a StringBuilder object.
2749 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002750 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002751 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2752 * @param prefix a String to be prepended to each line of output.
2753 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002754 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002755 */
2756 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002757 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002758 if (timer != null) {
2759 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002760 final long totalTimeMs = (timer.getTotalTimeLocked(
2761 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002762 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002763 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002764 sb.setLength(0);
2765 sb.append(prefix);
2766 sb.append(" ");
2767 sb.append(type);
2768 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002769 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002770 sb.append("realtime (");
2771 sb.append(count);
2772 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002773 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2774 if (maxDurationMs >= 0) {
2775 sb.append(" max=");
2776 sb.append(maxDurationMs);
2777 }
2778 if (timer.isRunningLocked()) {
2779 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2780 if (currentMs >= 0) {
2781 sb.append(" (running for ");
2782 sb.append(currentMs);
2783 sb.append("ms)");
2784 } else {
2785 sb.append(" (running)");
2786 }
2787 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002788 pw.println(sb.toString());
2789 return true;
2790 }
2791 }
2792 return false;
2793 }
Bookatzc8c44962017-05-11 12:12:54 -07002794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 /**
2796 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002797 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 * @param sb a StringBuilder object.
2799 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002800 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002802 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 * @param linePrefix a String to be prepended to each line of output.
2804 * @return the line prefix
2805 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002806 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2807 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 long totalTimeMicros = 0;
2809 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07002810 long max = 0;
2811 long current = 0;
2812 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002813 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002814 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07002815 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002816 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2817 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07002818 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 }
2820 sb.append(linePrefix);
2821 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2822 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002823 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002825 sb.append(',');
2826 sb.append(current);
2827 sb.append(',');
2828 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07002829 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
2830 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
2831 // totalDuration independent of totalTimeMicros (since they are not pooled).
2832 if (name != null) {
2833 sb.append(',');
2834 sb.append(totalDuration);
2835 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 return ",";
2837 }
Bookatz506a8182017-05-01 14:18:42 -07002838
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002839 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2840 String type) {
2841 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2842 pw.print(',');
2843 pw.print(uid);
2844 pw.print(',');
2845 pw.print(category);
2846 pw.print(',');
2847 pw.print(type);
2848 }
2849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 /**
2851 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07002852 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 * @param pw the PageWriter to dump log to
2854 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2855 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2856 * @param args type-dependent data arguments
2857 */
Bookatzc8c44962017-05-11 12:12:54 -07002858 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002860 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002861 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002862 pw.print(',');
2863 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002865 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002867
2868 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002869 * Dump a given timer stat for terse checkin mode.
2870 *
2871 * @param pw the PageWriter to dump log to
2872 * @param uid the UID to log
2873 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2874 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2875 * @param timer a {@link Timer} to dump stats for
2876 * @param rawRealtime the current elapsed realtime of the system in microseconds
2877 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2878 */
2879 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2880 Timer timer, long rawRealtime, int which) {
2881 if (timer != null) {
2882 // Convert from microseconds to milliseconds with rounding
2883 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2884 / 1000;
2885 final int count = timer.getCountLocked(which);
2886 if (totalTime != 0) {
2887 dumpLine(pw, uid, category, type, totalTime, count);
2888 }
2889 }
2890 }
2891
2892 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002893 * Checks if the ControllerActivityCounter has any data worth dumping.
2894 */
2895 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2896 if (counter == null) {
2897 return false;
2898 }
2899
2900 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2901 || counter.getRxTimeCounter().getCountLocked(which) != 0
2902 || counter.getPowerCounter().getCountLocked(which) != 0) {
2903 return true;
2904 }
2905
2906 for (LongCounter c : counter.getTxTimeCounters()) {
2907 if (c.getCountLocked(which) != 0) {
2908 return true;
2909 }
2910 }
2911 return false;
2912 }
2913
2914 /**
2915 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2916 * The order of the arguments in the final check in line is:
2917 *
2918 * idle, rx, power, tx...
2919 *
2920 * where tx... is one or more transmit level times.
2921 */
2922 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2923 String type,
2924 ControllerActivityCounter counter,
2925 int which) {
2926 if (!controllerActivityHasData(counter, which)) {
2927 return;
2928 }
2929
2930 dumpLineHeader(pw, uid, category, type);
2931 pw.print(",");
2932 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2933 pw.print(",");
2934 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2935 pw.print(",");
2936 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2937 for (LongCounter c : counter.getTxTimeCounters()) {
2938 pw.print(",");
2939 pw.print(c.getCountLocked(which));
2940 }
2941 pw.println();
2942 }
2943
2944 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2945 String prefix, String controllerName,
2946 ControllerActivityCounter counter,
2947 int which) {
2948 if (controllerActivityHasData(counter, which)) {
2949 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2950 }
2951 }
2952
2953 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2954 String controllerName,
2955 ControllerActivityCounter counter, int which) {
2956 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2957 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2958 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2959 long totalTxTimeMs = 0;
2960 for (LongCounter txState : counter.getTxTimeCounters()) {
2961 totalTxTimeMs += txState.getCountLocked(which);
2962 }
2963
2964 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2965
2966 sb.setLength(0);
2967 sb.append(prefix);
2968 sb.append(" ");
2969 sb.append(controllerName);
2970 sb.append(" Idle time: ");
2971 formatTimeMs(sb, idleTimeMs);
2972 sb.append("(");
2973 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2974 sb.append(")");
2975 pw.println(sb.toString());
2976
2977 sb.setLength(0);
2978 sb.append(prefix);
2979 sb.append(" ");
2980 sb.append(controllerName);
2981 sb.append(" Rx time: ");
2982 formatTimeMs(sb, rxTimeMs);
2983 sb.append("(");
2984 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
2985 sb.append(")");
2986 pw.println(sb.toString());
2987
2988 sb.setLength(0);
2989 sb.append(prefix);
2990 sb.append(" ");
2991 sb.append(controllerName);
2992 sb.append(" Tx time: ");
2993 formatTimeMs(sb, totalTxTimeMs);
2994 sb.append("(");
2995 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
2996 sb.append(")");
2997 pw.println(sb.toString());
2998
2999 final int numTxLvls = counter.getTxTimeCounters().length;
3000 if (numTxLvls > 1) {
3001 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3002 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3003 sb.setLength(0);
3004 sb.append(prefix);
3005 sb.append(" [");
3006 sb.append(lvl);
3007 sb.append("] ");
3008 formatTimeMs(sb, txLvlTimeMs);
3009 sb.append("(");
3010 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
3011 sb.append(")");
3012 pw.println(sb.toString());
3013 }
3014 }
3015
3016 sb.setLength(0);
3017 sb.append(prefix);
3018 sb.append(" ");
3019 sb.append(controllerName);
3020 sb.append(" Power drain: ").append(
3021 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
3022 sb.append("mAh");
3023 pw.println(sb.toString());
3024 }
3025
3026 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003027 * Temporary for settings.
3028 */
3029 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3030 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3031 }
3032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003033 /**
3034 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003035 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003036 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003037 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003038 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3039 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3041 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3042 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003043 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3044 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003045 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3046 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3047 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003048 final long totalRealtime = computeRealtime(rawRealtime, which);
3049 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003050 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003051 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003052 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003053 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3054 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003055 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003056 rawRealtime, which);
3057 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3058 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003059 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003060 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003061 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003062 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003063 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
3064 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
3065 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003066
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003067 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003068
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003069 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003070 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003071
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003072 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003074 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003075 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003076 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003077 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003078 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003079 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003080 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003081 getEstimatedBatteryCapacity(),
3082 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity());
Adam Lesinski67c134f2016-06-10 15:15:08 -07003083
Bookatzc8c44962017-05-11 12:12:54 -07003084
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003085 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003086 long fullWakeLockTimeTotal = 0;
3087 long partialWakeLockTimeTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003088
Evan Millar22ac0432009-03-31 11:33:18 -07003089 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003090 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003091
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003092 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3093 = u.getWakelockStats();
3094 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3095 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003096
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003097 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3098 if (fullWakeTimer != null) {
3099 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3100 which);
3101 }
3102
3103 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3104 if (partialWakeTimer != null) {
3105 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3106 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003107 }
3108 }
3109 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003110
3111 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003112 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3113 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3114 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3115 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3116 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3117 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3118 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3119 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003120 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3121 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003122 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3123 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003124 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3125 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003126
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003127 // Dump Modem controller stats
3128 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3129 getModemControllerActivity(), which);
3130
Adam Lesinskie283d332015-04-16 12:29:25 -07003131 // Dump Wifi controller stats
3132 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3133 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003134 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003135 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003136
3137 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3138 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003139
3140 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003141 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3142 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144 // Dump misc stats
3145 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003146 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003147 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003148 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003149 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003150 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003151 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3152 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003153 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003154 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3155 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3156 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3157 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003158 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003159
Dianne Hackborn617f8772009-03-31 15:04:46 -07003160 // Dump screen brightness stats
3161 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3162 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003163 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003164 }
3165 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003166
Dianne Hackborn627bba72009-03-24 22:32:56 -07003167 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003168 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3169 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003170 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003171 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003172 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003173 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003174 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003175 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003176 args[i] = getPhoneSignalStrengthCount(i, which);
3177 }
3178 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003179
Dianne Hackborn627bba72009-03-24 22:32:56 -07003180 // Dump network type stats
3181 args = new Object[NUM_DATA_CONNECTION_TYPES];
3182 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003183 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003184 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003185 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3186 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3187 args[i] = getPhoneDataConnectionCount(i, which);
3188 }
3189 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003190
3191 // Dump wifi state stats
3192 args = new Object[NUM_WIFI_STATES];
3193 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003194 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003195 }
3196 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3197 for (int i=0; i<NUM_WIFI_STATES; i++) {
3198 args[i] = getWifiStateCount(i, which);
3199 }
3200 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3201
Dianne Hackborn3251b902014-06-20 14:40:53 -07003202 // Dump wifi suppl state stats
3203 args = new Object[NUM_WIFI_SUPPL_STATES];
3204 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3205 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3206 }
3207 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3208 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3209 args[i] = getWifiSupplStateCount(i, which);
3210 }
3211 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3212
3213 // Dump wifi signal strength stats
3214 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3215 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3216 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3217 }
3218 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3219 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3220 args[i] = getWifiSignalStrengthCount(i, which);
3221 }
3222 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3223
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003224 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003225 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003226 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003227 }
Bookatzc8c44962017-05-11 12:12:54 -07003228
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003229 if (which == STATS_SINCE_UNPLUGGED) {
3230 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3231 getDischargeStartLevel()-getDischargeCurrentLevel(),
3232 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003233 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
3234 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003235 } else {
3236 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3237 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003238 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003239 getDischargeAmountScreenOffSinceCharge(),
3240 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003241 }
Bookatzc8c44962017-05-11 12:12:54 -07003242
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003243 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003244 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003245 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003246 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003247 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003248 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003249 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3250 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003251 }
Evan Millarc64edde2009-04-18 12:26:32 -07003252 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003253 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003254 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003255 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3256 // Not doing the regular wake lock formatting to remain compatible
3257 // with the old checkin format.
3258 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3259 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003260 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003261 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003262 }
3263 }
Evan Millarc64edde2009-04-18 12:26:32 -07003264 }
Bookatzc8c44962017-05-11 12:12:54 -07003265
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003266 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003267 helper.create(this);
3268 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003269 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003270 if (sippers != null && sippers.size() > 0) {
3271 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3272 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003273 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003274 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3275 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3276 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003277 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003278 int uid = 0;
3279 String label;
3280 switch (bs.drainType) {
3281 case IDLE:
3282 label="idle";
3283 break;
3284 case CELL:
3285 label="cell";
3286 break;
3287 case PHONE:
3288 label="phone";
3289 break;
3290 case WIFI:
3291 label="wifi";
3292 break;
3293 case BLUETOOTH:
3294 label="blue";
3295 break;
3296 case SCREEN:
3297 label="scrn";
3298 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003299 case FLASHLIGHT:
3300 label="flashlight";
3301 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003302 case APP:
3303 uid = bs.uidObj.getUid();
3304 label = "uid";
3305 break;
3306 case USER:
3307 uid = UserHandle.getUid(bs.userId, 0);
3308 label = "user";
3309 break;
3310 case UNACCOUNTED:
3311 label = "unacc";
3312 break;
3313 case OVERCOUNTED:
3314 label = "over";
3315 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003316 case CAMERA:
3317 label = "camera";
3318 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003319 default:
3320 label = "???";
3321 }
3322 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07003323 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003324 }
3325 }
3326
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003327 final long[] cpuFreqs = getCpuFreqs();
3328 if (cpuFreqs != null) {
3329 sb.setLength(0);
3330 for (int i = 0; i < cpuFreqs.length; ++i) {
3331 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3332 }
3333 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3334 }
3335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 for (int iu = 0; iu < NU; iu++) {
3337 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003338 if (reqUid >= 0 && uid != reqUid) {
3339 continue;
3340 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003341 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003344 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3345 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3346 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3347 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3348 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3349 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3350 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3351 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003352 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003353 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3354 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003355 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003356 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3357 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003358 // Background data transfers
3359 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3360 which);
3361 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3362 which);
3363 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3364 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3365 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3366 which);
3367 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3368 which);
3369 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3370 which);
3371 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3372 which);
3373
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003374 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3375 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003376 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003377 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3378 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3379 || wifiBytesBgTx > 0
3380 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3381 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003382 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3383 wifiBytesRx, wifiBytesTx,
3384 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003385 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003386 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003387 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3388 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3389 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3390 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003391 }
3392
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003393 // Dump modem controller data, per UID.
3394 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3395 u.getModemControllerActivity(), which);
3396
3397 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003398 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3399 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3400 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003401 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3402 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003403 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3404 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3405 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003406 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003407 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003408 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3409 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003410 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3411 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003412 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003413 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003414 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003416 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3417 u.getWifiControllerActivity(), which);
3418
Bookatz867c0d72017-03-07 18:23:42 -08003419 final Timer bleTimer = u.getBluetoothScanTimer();
3420 if (bleTimer != null) {
3421 // Convert from microseconds to milliseconds with rounding
3422 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3423 / 1000;
3424 if (totalTime != 0) {
3425 final int count = bleTimer.getCountLocked(which);
3426 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3427 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
3428 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
3429 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3430 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3431 final long actualTimeBg = bleTimerBg != null ?
3432 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatz956f36bf2017-04-28 09:48:17 -07003433 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3434 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003435 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatz956f36bf2017-04-28 09:48:17 -07003436 countBg, actualTime, actualTimeBg, resultCount);
Bookatz867c0d72017-03-07 18:23:42 -08003437 }
3438 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003439
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003440 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3441 u.getBluetoothControllerActivity(), which);
3442
Dianne Hackborn617f8772009-03-31 15:04:46 -07003443 if (u.hasUserActivity()) {
3444 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3445 boolean hasData = false;
3446 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3447 int val = u.getUserActivityCount(i, which);
3448 args[i] = val;
3449 if (val != 0) hasData = true;
3450 }
3451 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003452 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003453 }
3454 }
Bookatzc8c44962017-05-11 12:12:54 -07003455
3456 if (u.getAggregatedPartialWakelockTimer() != null) {
3457 final Timer timer = u.getAggregatedPartialWakelockTimer();
3458 // Convert from microseconds to milliseconds with rounding
3459 final long totTimeMs = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3460 final Timer bgTimer = timer.getSubTimer();
3461 final long bgTimeMs = bgTimer != null ?
3462 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
3463 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3464 }
3465
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003466 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3467 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3468 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3469 String linePrefix = "";
3470 sb.setLength(0);
3471 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3472 rawRealtime, "f", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003473 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3474 linePrefix = printWakeLockCheckin(sb, pTimer,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003475 rawRealtime, "p", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07003476 linePrefix = printWakeLockCheckin(sb, pTimer != null ? pTimer.getSubTimer() : null,
3477 rawRealtime, "bp", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003478 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3479 rawRealtime, "w", which, linePrefix);
3480
3481 // Only log if we had at lease one wakelock...
3482 if (sb.length() > 0) {
3483 String name = wakelocks.keyAt(iw);
3484 if (name.indexOf(',') >= 0) {
3485 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003487 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003488 }
3489 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003490
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003491 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3492 for (int isy=syncs.size()-1; isy>=0; isy--) {
3493 final Timer timer = syncs.valueAt(isy);
3494 // Convert from microseconds to milliseconds with rounding
3495 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3496 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003497 final Timer bgTimer = timer.getSubTimer();
3498 final long bgTime = bgTimer != null ?
3499 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
3500 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003501 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003502 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003503 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003504 }
3505 }
3506
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003507 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3508 for (int ij=jobs.size()-1; ij>=0; ij--) {
3509 final Timer timer = jobs.valueAt(ij);
3510 // Convert from microseconds to milliseconds with rounding
3511 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3512 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003513 final Timer bgTimer = timer.getSubTimer();
3514 final long bgTime = bgTimer != null ?
3515 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
3516 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003517 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003518 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003519 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003520 }
3521 }
3522
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003523 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3524 rawRealtime, which);
3525 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3526 rawRealtime, which);
3527 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3528 rawRealtime, which);
3529 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3530 rawRealtime, which);
3531
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003532 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3533 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003534 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003535 final Uid.Sensor se = sensors.valueAt(ise);
3536 final int sensorNumber = sensors.keyAt(ise);
3537 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003538 if (timer != null) {
3539 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003540 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3541 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003542 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003543 final int count = timer.getCountLocked(which);
3544 final Timer bgTimer = se.getSensorBackgroundTime();
3545 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
3546 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
3547 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3548 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3549 final long bgActualTime = bgTimer != null ?
3550 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3551 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3552 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003553 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 }
3555 }
3556
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003557 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3558 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003559
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003560 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3561 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003562
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003563 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003564 long totalStateTime = 0;
3565 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003566 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3567 totalStateTime += time;
3568 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003569 }
3570 if (totalStateTime > 0) {
3571 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3572 }
3573
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003574 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3575 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003576 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003577 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003578 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003579 }
3580
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003581 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3582 // If total cpuFreqTimes is null, then we don't need to check for screenOffCpuFreqTimes.
3583 if (cpuFreqTimeMs != null) {
3584 sb.setLength(0);
3585 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3586 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
3587 }
3588 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3589 if (screenOffCpuFreqTimeMs != null) {
3590 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3591 sb.append("," + screenOffCpuFreqTimeMs[i]);
3592 }
3593 } else {
3594 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3595 sb.append(",0");
3596 }
3597 }
3598 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
3599 cpuFreqTimeMs.length, sb.toString());
3600 }
3601
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003602 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3603 = u.getProcessStats();
3604 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3605 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003606
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003607 final long userMillis = ps.getUserTime(which);
3608 final long systemMillis = ps.getSystemTime(which);
3609 final long foregroundMillis = ps.getForegroundTime(which);
3610 final int starts = ps.getStarts(which);
3611 final int numCrashes = ps.getNumCrashes(which);
3612 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003613
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003614 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3615 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003616 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
3617 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 }
3619 }
3620
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003621 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3622 = u.getPackageStats();
3623 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3624 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3625 int wakeups = 0;
3626 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3627 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003628 int count = alarms.valueAt(iwa).getCountLocked(which);
3629 wakeups += count;
3630 String name = alarms.keyAt(iwa).replace(',', '_');
3631 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003632 }
3633 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3634 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3635 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3636 final long startTime = ss.getStartTime(batteryUptime, which);
3637 final int starts = ss.getStarts(which);
3638 final int launches = ss.getLaunches(which);
3639 if (startTime != 0 || starts != 0 || launches != 0) {
3640 dumpLine(pw, uid, category, APK_DATA,
3641 wakeups, // wakeup alarms
3642 packageStats.keyAt(ipkg), // Apk
3643 serviceStats.keyAt(isvc), // service
3644 startTime / 1000, // time spent started, in ms
3645 starts,
3646 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003647 }
3648 }
3649 }
3650 }
3651 }
3652
Dianne Hackborn81038902012-11-26 17:04:09 -08003653 static final class TimerEntry {
3654 final String mName;
3655 final int mId;
3656 final BatteryStats.Timer mTimer;
3657 final long mTime;
3658 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3659 mName = name;
3660 mId = id;
3661 mTimer = timer;
3662 mTime = time;
3663 }
3664 }
3665
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003666 private void printmAh(PrintWriter printer, double power) {
3667 printer.print(BatteryStatsHelper.makemAh(power));
3668 }
3669
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003670 private void printmAh(StringBuilder sb, double power) {
3671 sb.append(BatteryStatsHelper.makemAh(power));
3672 }
3673
Dianne Hackbornd953c532014-08-16 18:17:38 -07003674 /**
3675 * Temporary for settings.
3676 */
3677 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3678 int reqUid) {
3679 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3680 }
3681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003683 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003684 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003685 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3686 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3687 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688
3689 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3690 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3691 final long totalRealtime = computeRealtime(rawRealtime, which);
3692 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003693 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3694 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3695 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003696 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3697 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003698
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003699 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003700
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003701 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003702 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003704 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3705 if (estimatedBatteryCapacity > 0) {
3706 sb.setLength(0);
3707 sb.append(prefix);
3708 sb.append(" Estimated battery capacity: ");
3709 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3710 sb.append(" mAh");
3711 pw.println(sb.toString());
3712 }
3713
Jocelyn Dangc627d102017-04-14 13:15:14 -07003714 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
3715 if (minLearnedBatteryCapacity > 0) {
3716 sb.setLength(0);
3717 sb.append(prefix);
3718 sb.append(" Min learned battery capacity: ");
3719 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
3720 sb.append(" mAh");
3721 pw.println(sb.toString());
3722 }
3723 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
3724 if (maxLearnedBatteryCapacity > 0) {
3725 sb.setLength(0);
3726 sb.append(prefix);
3727 sb.append(" Max learned battery capacity: ");
3728 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
3729 sb.append(" mAh");
3730 pw.println(sb.toString());
3731 }
3732
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003733 sb.setLength(0);
3734 sb.append(prefix);
3735 sb.append(" Time on battery: ");
3736 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3737 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3738 sb.append(") realtime, ");
3739 formatTimeMs(sb, whichBatteryUptime / 1000);
3740 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3741 sb.append(") uptime");
3742 pw.println(sb.toString());
3743 sb.setLength(0);
3744 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003745 sb.append(" Time on battery screen off: ");
3746 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3747 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3748 sb.append(") realtime, ");
3749 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3750 sb.append("(");
3751 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3752 sb.append(") uptime");
3753 pw.println(sb.toString());
3754 sb.setLength(0);
3755 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003756 sb.append(" Total run time: ");
3757 formatTimeMs(sb, totalRealtime / 1000);
3758 sb.append("realtime, ");
3759 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003760 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003761 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003762 if (batteryTimeRemaining >= 0) {
3763 sb.setLength(0);
3764 sb.append(prefix);
3765 sb.append(" Battery time remaining: ");
3766 formatTimeMs(sb, batteryTimeRemaining / 1000);
3767 pw.println(sb.toString());
3768 }
3769 if (chargeTimeRemaining >= 0) {
3770 sb.setLength(0);
3771 sb.append(prefix);
3772 sb.append(" Charge time remaining: ");
3773 formatTimeMs(sb, chargeTimeRemaining / 1000);
3774 pw.println(sb.toString());
3775 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003776
3777 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3778 final long dischargeCount = dischargeCounter.getCountLocked(which);
3779 if (dischargeCount >= 0) {
3780 sb.setLength(0);
3781 sb.append(prefix);
3782 sb.append(" Discharge: ");
3783 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3784 sb.append(" mAh");
3785 pw.println(sb.toString());
3786 }
3787
3788 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3789 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3790 if (dischargeScreenOffCount >= 0) {
3791 sb.setLength(0);
3792 sb.append(prefix);
3793 sb.append(" Screen off discharge: ");
3794 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3795 sb.append(" mAh");
3796 pw.println(sb.toString());
3797 }
3798
3799 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3800 if (dischargeScreenOnCount >= 0) {
3801 sb.setLength(0);
3802 sb.append(prefix);
3803 sb.append(" Screen on discharge: ");
3804 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3805 sb.append(" mAh");
3806 pw.println(sb.toString());
3807 }
3808
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003809 pw.print(" Start clock time: ");
3810 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3811
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003812 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003813 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003814 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003815 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3816 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003817 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003818 rawRealtime, which);
3819 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3820 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003821 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003822 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003823 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3824 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3825 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003826 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003827 sb.append(prefix);
3828 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3829 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003830 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003831 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3832 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003833 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003834 pw.println(sb.toString());
3835 sb.setLength(0);
3836 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003837 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003838 boolean didOne = false;
3839 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003840 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003841 if (time == 0) {
3842 continue;
3843 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003844 sb.append("\n ");
3845 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003846 didOne = true;
3847 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3848 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003849 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003850 sb.append("(");
3851 sb.append(formatRatioLocked(time, screenOnTime));
3852 sb.append(")");
3853 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003854 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003855 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003856 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003857 sb.setLength(0);
3858 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003859 sb.append(" Power save mode enabled: ");
3860 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003861 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003862 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003863 sb.append(")");
3864 pw.println(sb.toString());
3865 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003866 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003867 sb.setLength(0);
3868 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003869 sb.append(" Device light idling: ");
3870 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003871 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003872 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3873 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003874 sb.append("x");
3875 pw.println(sb.toString());
3876 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003877 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003878 sb.setLength(0);
3879 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003880 sb.append(" Idle mode light time: ");
3881 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003882 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003883 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3884 sb.append(") ");
3885 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003886 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003887 sb.append(" -- longest ");
3888 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3889 pw.println(sb.toString());
3890 }
3891 if (deviceIdlingTime != 0) {
3892 sb.setLength(0);
3893 sb.append(prefix);
3894 sb.append(" Device full idling: ");
3895 formatTimeMs(sb, deviceIdlingTime / 1000);
3896 sb.append("(");
3897 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003898 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003899 sb.append("x");
3900 pw.println(sb.toString());
3901 }
3902 if (deviceIdleModeFullTime != 0) {
3903 sb.setLength(0);
3904 sb.append(prefix);
3905 sb.append(" Idle mode full time: ");
3906 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3907 sb.append("(");
3908 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3909 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003910 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003911 sb.append("x");
3912 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003913 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003914 pw.println(sb.toString());
3915 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003916 if (phoneOnTime != 0) {
3917 sb.setLength(0);
3918 sb.append(prefix);
3919 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3920 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003921 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003922 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003923 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003924 if (connChanges != 0) {
3925 pw.print(prefix);
3926 pw.print(" Connectivity changes: "); pw.println(connChanges);
3927 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003928
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003929 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003930 long fullWakeLockTimeTotalMicros = 0;
3931 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003932
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003933 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003934
Evan Millar22ac0432009-03-31 11:33:18 -07003935 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003936 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003937
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003938 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3939 = u.getWakelockStats();
3940 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3941 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003942
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003943 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3944 if (fullWakeTimer != null) {
3945 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3946 rawRealtime, which);
3947 }
3948
3949 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3950 if (partialWakeTimer != null) {
3951 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3952 rawRealtime, which);
3953 if (totalTimeMicros > 0) {
3954 if (reqUid < 0) {
3955 // Only show the ordered list of all wake
3956 // locks if the caller is not asking for data
3957 // about a specific uid.
3958 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3959 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003960 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003961 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003962 }
3963 }
3964 }
3965 }
Bookatzc8c44962017-05-11 12:12:54 -07003966
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003967 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3968 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3969 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3970 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3971 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3972 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3973 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3974 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08003975 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3976 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003977
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003978 if (fullWakeLockTimeTotalMicros != 0) {
3979 sb.setLength(0);
3980 sb.append(prefix);
3981 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3982 (fullWakeLockTimeTotalMicros + 500) / 1000);
3983 pw.println(sb.toString());
3984 }
3985
3986 if (partialWakeLockTimeTotalMicros != 0) {
3987 sb.setLength(0);
3988 sb.append(prefix);
3989 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3990 (partialWakeLockTimeTotalMicros + 500) / 1000);
3991 pw.println(sb.toString());
3992 }
3993
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003994 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003995 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3996 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3997 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3998 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003999 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004000 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004001 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004002 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08004003 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004004 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004005 if (time == 0) {
4006 continue;
4007 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004008 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004009 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004010 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08004011 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004012 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004013 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004014 sb.append("(");
4015 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004016 sb.append(") ");
4017 sb.append(getPhoneSignalStrengthCount(i, which));
4018 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004019 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004020 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004021 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004022
4023 sb.setLength(0);
4024 sb.append(prefix);
4025 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004026 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07004027 pw.println(sb.toString());
4028
Dianne Hackborn627bba72009-03-24 22:32:56 -07004029 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004030 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004031 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004032 didOne = false;
4033 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004034 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004035 if (time == 0) {
4036 continue;
4037 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004038 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004039 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004040 didOne = true;
4041 sb.append(DATA_CONNECTION_NAMES[i]);
4042 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004043 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004044 sb.append("(");
4045 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004046 sb.append(") ");
4047 sb.append(getPhoneDataConnectionCount(i, which));
4048 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004049 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004050 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004051 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004052
4053 sb.setLength(0);
4054 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08004055 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004056 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004057 formatTimeMs(sb, mobileActiveTime / 1000);
4058 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4059 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
4060 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004061 pw.println(sb.toString());
4062
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004063 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
4064 if (mobileActiveUnknownTime != 0) {
4065 sb.setLength(0);
4066 sb.append(prefix);
4067 sb.append(" Mobile radio active unknown time: ");
4068 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
4069 sb.append("(");
4070 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
4071 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
4072 sb.append("x");
4073 pw.println(sb.toString());
4074 }
4075
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004076 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
4077 if (mobileActiveAdjustedTime != 0) {
4078 sb.setLength(0);
4079 sb.append(prefix);
4080 sb.append(" Mobile radio active adjusted time: ");
4081 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
4082 sb.append("(");
4083 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
4084 sb.append(")");
4085 pw.println(sb.toString());
4086 }
4087
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004088 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
4089
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004090 pw.print(prefix);
4091 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
4092 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
4093 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
4094 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004095 sb.setLength(0);
4096 sb.append(prefix);
4097 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
4098 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
4099 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
4100 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004101 sb.append(")");
4102 pw.println(sb.toString());
4103
4104 sb.setLength(0);
4105 sb.append(prefix);
4106 sb.append(" Wifi states:");
4107 didOne = false;
4108 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004109 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004110 if (time == 0) {
4111 continue;
4112 }
4113 sb.append("\n ");
4114 didOne = true;
4115 sb.append(WIFI_STATE_NAMES[i]);
4116 sb.append(" ");
4117 formatTimeMs(sb, time/1000);
4118 sb.append("(");
4119 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4120 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004121 sb.append(getWifiStateCount(i, which));
4122 sb.append("x");
4123 }
4124 if (!didOne) sb.append(" (no activity)");
4125 pw.println(sb.toString());
4126
4127 sb.setLength(0);
4128 sb.append(prefix);
4129 sb.append(" Wifi supplicant states:");
4130 didOne = false;
4131 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4132 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4133 if (time == 0) {
4134 continue;
4135 }
4136 sb.append("\n ");
4137 didOne = true;
4138 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4139 sb.append(" ");
4140 formatTimeMs(sb, time/1000);
4141 sb.append("(");
4142 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4143 sb.append(") ");
4144 sb.append(getWifiSupplStateCount(i, which));
4145 sb.append("x");
4146 }
4147 if (!didOne) sb.append(" (no activity)");
4148 pw.println(sb.toString());
4149
4150 sb.setLength(0);
4151 sb.append(prefix);
4152 sb.append(" Wifi signal levels:");
4153 didOne = false;
4154 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
4155 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4156 if (time == 0) {
4157 continue;
4158 }
4159 sb.append("\n ");
4160 sb.append(prefix);
4161 didOne = true;
4162 sb.append("level(");
4163 sb.append(i);
4164 sb.append(") ");
4165 formatTimeMs(sb, time/1000);
4166 sb.append("(");
4167 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4168 sb.append(") ");
4169 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004170 sb.append("x");
4171 }
4172 if (!didOne) sb.append(" (no activity)");
4173 pw.println(sb.toString());
4174
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004175 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004176
Adam Lesinski50e47602015-12-04 17:04:54 -08004177 pw.print(prefix);
4178 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4179 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4180
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004181 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4182 sb.setLength(0);
4183 sb.append(prefix);
4184 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4185 pw.println(sb.toString());
4186
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004187 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4188 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004189
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004190 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004191
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004192 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004193 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004194 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004195 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004196 pw.println(getDischargeStartLevel());
4197 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4198 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004199 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004200 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004201 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004202 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004203 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004204 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004205 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004206 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4207 pw.println(getDischargeAmountScreenOn());
4208 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4209 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004210 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004211 } else {
4212 pw.print(prefix); pw.println(" Device battery use since last full charge");
4213 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
4214 pw.println(getLowDischargeAmountSinceCharge());
4215 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
4216 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004217 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4218 pw.println(getDischargeAmountScreenOnSinceCharge());
4219 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4220 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004221 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004222 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004223
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004224 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004225 helper.create(this);
4226 helper.refreshStats(which, UserHandle.USER_ALL);
4227 List<BatterySipper> sippers = helper.getUsageList();
4228 if (sippers != null && sippers.size() > 0) {
4229 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4230 pw.print(prefix); pw.print(" Capacity: ");
4231 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004232 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004233 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4234 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4235 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4236 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004237 pw.println();
4238 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004239 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004240 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004241 switch (bs.drainType) {
4242 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004243 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004244 break;
4245 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004246 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004247 break;
4248 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004249 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004250 break;
4251 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004252 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004253 break;
4254 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004255 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004256 break;
4257 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004258 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004259 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004260 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004261 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004262 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004263 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004264 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004265 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004266 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004267 break;
4268 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004269 pw.print(" User "); pw.print(bs.userId);
4270 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004271 break;
4272 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004273 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004274 break;
4275 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004276 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004277 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004278 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004279 pw.print(" Camera: ");
4280 break;
4281 default:
4282 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004283 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004284 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004285 printmAh(pw, bs.totalPowerMah);
4286
Adam Lesinski57123002015-06-12 16:12:07 -07004287 if (bs.usagePowerMah != bs.totalPowerMah) {
4288 // If the usage (generic power) isn't the whole amount, we list out
4289 // what components are involved in the calculation.
4290
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004291 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004292 if (bs.usagePowerMah != 0) {
4293 pw.print(" usage=");
4294 printmAh(pw, bs.usagePowerMah);
4295 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004296 if (bs.cpuPowerMah != 0) {
4297 pw.print(" cpu=");
4298 printmAh(pw, bs.cpuPowerMah);
4299 }
4300 if (bs.wakeLockPowerMah != 0) {
4301 pw.print(" wake=");
4302 printmAh(pw, bs.wakeLockPowerMah);
4303 }
4304 if (bs.mobileRadioPowerMah != 0) {
4305 pw.print(" radio=");
4306 printmAh(pw, bs.mobileRadioPowerMah);
4307 }
4308 if (bs.wifiPowerMah != 0) {
4309 pw.print(" wifi=");
4310 printmAh(pw, bs.wifiPowerMah);
4311 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004312 if (bs.bluetoothPowerMah != 0) {
4313 pw.print(" bt=");
4314 printmAh(pw, bs.bluetoothPowerMah);
4315 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004316 if (bs.gpsPowerMah != 0) {
4317 pw.print(" gps=");
4318 printmAh(pw, bs.gpsPowerMah);
4319 }
4320 if (bs.sensorPowerMah != 0) {
4321 pw.print(" sensor=");
4322 printmAh(pw, bs.sensorPowerMah);
4323 }
4324 if (bs.cameraPowerMah != 0) {
4325 pw.print(" camera=");
4326 printmAh(pw, bs.cameraPowerMah);
4327 }
4328 if (bs.flashlightPowerMah != 0) {
4329 pw.print(" flash=");
4330 printmAh(pw, bs.flashlightPowerMah);
4331 }
4332 pw.print(" )");
4333 }
4334 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004335 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004336 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004337 }
4338
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004339 sippers = helper.getMobilemsppList();
4340 if (sippers != null && sippers.size() > 0) {
4341 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004342 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004343 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004344 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004345 sb.setLength(0);
4346 sb.append(prefix); sb.append(" Uid ");
4347 UserHandle.formatUid(sb, bs.uidObj.getUid());
4348 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4349 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4350 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004351 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004352 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004353 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004354 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004355 sb.setLength(0);
4356 sb.append(prefix);
4357 sb.append(" TOTAL TIME: ");
4358 formatTimeMs(sb, totalTime);
4359 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4360 sb.append(")");
4361 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004362 pw.println();
4363 }
4364
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004365 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4366 @Override
4367 public int compare(TimerEntry lhs, TimerEntry rhs) {
4368 long lhsTime = lhs.mTime;
4369 long rhsTime = rhs.mTime;
4370 if (lhsTime < rhsTime) {
4371 return 1;
4372 }
4373 if (lhsTime > rhsTime) {
4374 return -1;
4375 }
4376 return 0;
4377 }
4378 };
4379
4380 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004381 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4382 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004383 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004384 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4385 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4386 : kernelWakelocks.entrySet()) {
4387 final BatteryStats.Timer timer = ent.getValue();
4388 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004389 if (totalTimeMillis > 0) {
4390 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4391 }
4392 }
4393 if (ktimers.size() > 0) {
4394 Collections.sort(ktimers, timerComparator);
4395 pw.print(prefix); pw.println(" All kernel wake locks:");
4396 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004397 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004398 String linePrefix = ": ";
4399 sb.setLength(0);
4400 sb.append(prefix);
4401 sb.append(" Kernel Wake lock ");
4402 sb.append(timer.mName);
4403 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4404 which, linePrefix);
4405 if (!linePrefix.equals(": ")) {
4406 sb.append(" realtime");
4407 // Only print out wake locks that were held
4408 pw.println(sb.toString());
4409 }
4410 }
4411 pw.println();
4412 }
4413 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004414
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004415 if (timers.size() > 0) {
4416 Collections.sort(timers, timerComparator);
4417 pw.print(prefix); pw.println(" All partial wake locks:");
4418 for (int i=0; i<timers.size(); i++) {
4419 TimerEntry timer = timers.get(i);
4420 sb.setLength(0);
4421 sb.append(" Wake lock ");
4422 UserHandle.formatUid(sb, timer.mId);
4423 sb.append(" ");
4424 sb.append(timer.mName);
4425 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4426 sb.append(" realtime");
4427 pw.println(sb.toString());
4428 }
4429 timers.clear();
4430 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004431 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004432
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004433 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004434 if (wakeupReasons.size() > 0) {
4435 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004436 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004437 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004438 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004439 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4440 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004441 }
4442 Collections.sort(reasons, timerComparator);
4443 for (int i=0; i<reasons.size(); i++) {
4444 TimerEntry timer = reasons.get(i);
4445 String linePrefix = ": ";
4446 sb.setLength(0);
4447 sb.append(prefix);
4448 sb.append(" Wakeup reason ");
4449 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004450 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4451 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004452 pw.println(sb.toString());
4453 }
4454 pw.println();
4455 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004456 }
Evan Millar22ac0432009-03-31 11:33:18 -07004457
James Carr2dd7e5e2016-07-20 18:48:39 -07004458 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
4459 pw.println("Memory Stats");
4460 for (int i = 0; i < mMemoryStats.size(); i++) {
4461 sb.setLength(0);
4462 sb.append("Bandwidth ");
4463 sb.append(mMemoryStats.keyAt(i));
4464 sb.append(" Time ");
4465 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4466 pw.println(sb.toString());
4467 }
4468
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004469 final long[] cpuFreqs = getCpuFreqs();
4470 if (cpuFreqs != null) {
4471 sb.setLength(0);
4472 sb.append("CPU freqs:");
4473 for (int i = 0; i < cpuFreqs.length; ++i) {
4474 sb.append(" " + cpuFreqs[i]);
4475 }
4476 pw.println(sb.toString());
4477 }
4478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 for (int iu=0; iu<NU; iu++) {
4480 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004481 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004482 continue;
4483 }
Bookatzc8c44962017-05-11 12:12:54 -07004484
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004485 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004486
4487 pw.print(prefix);
4488 pw.print(" ");
4489 UserHandle.formatUid(pw, uid);
4490 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004491 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004492
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004493 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4494 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4495 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4496 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004497 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4498 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4499
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004500 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4501 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004502 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4503 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004504
4505 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4506 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4507
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004508 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4509 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4510 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08004511 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
4512 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4513 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
4514 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004515 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004516
Adam Lesinski5f056f62016-07-14 16:56:08 -07004517 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4518 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4519
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004520 if (mobileRxBytes > 0 || mobileTxBytes > 0
4521 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004522 pw.print(prefix); pw.print(" Mobile network: ");
4523 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004524 pw.print(formatBytesLocked(mobileTxBytes));
4525 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4526 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004527 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004528 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4529 sb.setLength(0);
4530 sb.append(prefix); sb.append(" Mobile radio active: ");
4531 formatTimeMs(sb, uidMobileActiveTime / 1000);
4532 sb.append("(");
4533 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4534 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4535 long packets = mobileRxPackets + mobileTxPackets;
4536 if (packets == 0) {
4537 packets = 1;
4538 }
4539 sb.append(" @ ");
4540 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4541 sb.append(" mspp");
4542 pw.println(sb.toString());
4543 }
4544
Adam Lesinski5f056f62016-07-14 16:56:08 -07004545 if (mobileWakeup > 0) {
4546 sb.setLength(0);
4547 sb.append(prefix);
4548 sb.append(" Mobile radio AP wakeups: ");
4549 sb.append(mobileWakeup);
4550 pw.println(sb.toString());
4551 }
4552
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004553 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4554 u.getModemControllerActivity(), which);
4555
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004556 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004557 pw.print(prefix); pw.print(" Wi-Fi network: ");
4558 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004559 pw.print(formatBytesLocked(wifiTxBytes));
4560 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4561 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004562 }
4563
Dianne Hackborn62793e42015-03-09 11:15:41 -07004564 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08004565 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004566 || uidWifiRunningTime != 0) {
4567 sb.setLength(0);
4568 sb.append(prefix); sb.append(" Wifi Running: ");
4569 formatTimeMs(sb, uidWifiRunningTime / 1000);
4570 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4571 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07004572 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004573 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4574 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4575 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08004576 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004577 formatTimeMs(sb, wifiScanTime / 1000);
4578 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004579 whichBatteryRealtime)); sb.append(") ");
4580 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08004581 sb.append("x\n");
4582 // actual and background times are unpooled and since reset (regardless of 'which')
4583 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
4584 formatTimeMs(sb, wifiScanActualTime / 1000);
4585 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
4586 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4587 sb.append(") ");
4588 sb.append(wifiScanCount);
4589 sb.append("x\n");
4590 sb.append(prefix); sb.append(" Background Wifi Scan: ");
4591 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
4592 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
4593 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4594 sb.append(") ");
4595 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07004596 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004597 pw.println(sb.toString());
4598 }
4599
Adam Lesinski5f056f62016-07-14 16:56:08 -07004600 if (wifiWakeup > 0) {
4601 sb.setLength(0);
4602 sb.append(prefix);
4603 sb.append(" WiFi AP wakeups: ");
4604 sb.append(wifiWakeup);
4605 pw.println(sb.toString());
4606 }
4607
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004608 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4609 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004610
Adam Lesinski50e47602015-12-04 17:04:54 -08004611 if (btRxBytes > 0 || btTxBytes > 0) {
4612 pw.print(prefix); pw.print(" Bluetooth network: ");
4613 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4614 pw.print(formatBytesLocked(btTxBytes));
4615 pw.println(" sent");
4616 }
4617
Bookatz867c0d72017-03-07 18:23:42 -08004618 final Timer bleTimer = u.getBluetoothScanTimer();
4619 if (bleTimer != null) {
4620 // Convert from microseconds to milliseconds with rounding
4621 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
4622 / 1000;
4623 if (totalTimeMs != 0) {
4624 final int count = bleTimer.getCountLocked(which);
4625 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
4626 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
4627 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
4628 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4629 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
4630 final long actualTimeMsBg = bleTimerBg != null ?
4631 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatz956f36bf2017-04-28 09:48:17 -07004632 final int resultCount = u.getBluetoothScanResultCounter() != null ?
4633 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004634
4635 sb.setLength(0);
4636 sb.append(prefix);
4637 sb.append(" ");
4638 sb.append("Bluetooth Scan");
4639 sb.append(": ");
4640 if (actualTimeMs != totalTimeMs) {
4641 formatTimeMs(sb, totalTimeMs);
4642 sb.append("blamed realtime, ");
4643 }
4644 formatTimeMs(sb, actualTimeMs); // since reset, regardless of 'which'
4645 sb.append("realtime (");
4646 sb.append(count);
4647 sb.append(" times)");
4648 if (bleTimer.isRunningLocked()) {
4649 sb.append(" (running)");
4650 }
4651 if (actualTimeMsBg != 0 || countBg > 0) {
4652 sb.append(", ");
4653 formatTimeMs(sb, actualTimeMsBg); // since reset, regardless of 'which'
4654 sb.append("background (");
4655 sb.append(countBg);
4656 sb.append(" times)");
4657 }
Bookatz956f36bf2017-04-28 09:48:17 -07004658 sb.append("; Results count ");
4659 sb.append(resultCount);
Bookatz867c0d72017-03-07 18:23:42 -08004660 pw.println(sb.toString());
4661 uidActivity = true;
4662 }
4663 }
4664
4665
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004666
Dianne Hackborn617f8772009-03-31 15:04:46 -07004667 if (u.hasUserActivity()) {
4668 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004669 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004670 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004671 if (val != 0) {
4672 if (!hasData) {
4673 sb.setLength(0);
4674 sb.append(" User activity: ");
4675 hasData = true;
4676 } else {
4677 sb.append(", ");
4678 }
4679 sb.append(val);
4680 sb.append(" ");
4681 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4682 }
4683 }
4684 if (hasData) {
4685 pw.println(sb.toString());
4686 }
4687 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004689 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4690 = u.getWakelockStats();
4691 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004692 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004693 int countWakelock = 0;
4694 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4695 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4696 String linePrefix = ": ";
4697 sb.setLength(0);
4698 sb.append(prefix);
4699 sb.append(" Wake lock ");
4700 sb.append(wakelocks.keyAt(iw));
4701 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4702 "full", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004703 final Timer pTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
4704 linePrefix = printWakeLock(sb, pTimer, rawRealtime,
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004705 "partial", which, linePrefix);
Bookatz5b5ec322017-05-26 09:40:38 -07004706 linePrefix = printWakeLock(sb, pTimer != null ? pTimer.getSubTimer() : null,
4707 rawRealtime, "background partial", which, linePrefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004708 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4709 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004710 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4711 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004712 sb.append(" realtime");
4713 pw.println(sb.toString());
4714 uidActivity = true;
4715 countWakelock++;
4716
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004717 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4718 rawRealtime, which);
4719 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4720 rawRealtime, which);
4721 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4722 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004723 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004724 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004725 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004726 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07004727 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
4728 // pooled and therefore just a lower bound)
4729 long actualTotalPartialWakelock = 0;
4730 long actualBgPartialWakelock = 0;
4731 if (u.getAggregatedPartialWakelockTimer() != null) {
4732 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
4733 // Convert from microseconds to milliseconds with rounding
4734 actualTotalPartialWakelock =
4735 (aggTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4736 final Timer bgAggTimer = aggTimer.getSubTimer();
4737 actualBgPartialWakelock = bgAggTimer != null ?
4738 (bgAggTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
4739 }
4740
4741 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
4742 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
4743 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004744 sb.setLength(0);
4745 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004746 sb.append(" TOTAL wake: ");
4747 boolean needComma = false;
4748 if (totalFullWakelock != 0) {
4749 needComma = true;
4750 formatTimeMs(sb, totalFullWakelock);
4751 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004752 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004753 if (totalPartialWakelock != 0) {
4754 if (needComma) {
4755 sb.append(", ");
4756 }
4757 needComma = true;
4758 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07004759 sb.append("blamed partial");
4760 }
4761 if (actualTotalPartialWakelock != 0) {
4762 if (needComma) {
4763 sb.append(", ");
4764 }
4765 needComma = true;
4766 formatTimeMs(sb, actualTotalPartialWakelock);
4767 sb.append("actual partial");
4768 }
4769 if (actualBgPartialWakelock != 0) {
4770 if (needComma) {
4771 sb.append(", ");
4772 }
4773 needComma = true;
4774 formatTimeMs(sb, actualBgPartialWakelock);
4775 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004776 }
4777 if (totalWindowWakelock != 0) {
4778 if (needComma) {
4779 sb.append(", ");
4780 }
4781 needComma = true;
4782 formatTimeMs(sb, totalWindowWakelock);
4783 sb.append("window");
4784 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004785 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004786 if (needComma) {
4787 sb.append(",");
4788 }
4789 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004790 formatTimeMs(sb, totalDrawWakelock);
4791 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004792 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004793 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004794 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004795 }
4796 }
4797
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004798 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4799 for (int isy=syncs.size()-1; isy>=0; isy--) {
4800 final Timer timer = syncs.valueAt(isy);
4801 // Convert from microseconds to milliseconds with rounding
4802 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4803 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07004804 final Timer bgTimer = timer.getSubTimer();
4805 final long bgTime = bgTimer != null ?
4806 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
4807 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004808 sb.setLength(0);
4809 sb.append(prefix);
4810 sb.append(" Sync ");
4811 sb.append(syncs.keyAt(isy));
4812 sb.append(": ");
4813 if (totalTime != 0) {
4814 formatTimeMs(sb, totalTime);
4815 sb.append("realtime (");
4816 sb.append(count);
4817 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07004818 if (bgTime > 0) {
4819 sb.append(", ");
4820 formatTimeMs(sb, bgTime);
4821 sb.append("background (");
4822 sb.append(bgCount);
4823 sb.append(" times)");
4824 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004825 } else {
4826 sb.append("(not used)");
4827 }
4828 pw.println(sb.toString());
4829 uidActivity = true;
4830 }
4831
4832 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4833 for (int ij=jobs.size()-1; ij>=0; ij--) {
4834 final Timer timer = jobs.valueAt(ij);
4835 // Convert from microseconds to milliseconds with rounding
4836 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4837 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07004838 final Timer bgTimer = timer.getSubTimer();
4839 final long bgTime = bgTimer != null ?
4840 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
4841 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004842 sb.setLength(0);
4843 sb.append(prefix);
4844 sb.append(" Job ");
4845 sb.append(jobs.keyAt(ij));
4846 sb.append(": ");
4847 if (totalTime != 0) {
4848 formatTimeMs(sb, totalTime);
4849 sb.append("realtime (");
4850 sb.append(count);
4851 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07004852 if (bgTime > 0) {
4853 sb.append(", ");
4854 formatTimeMs(sb, bgTime);
4855 sb.append("background (");
4856 sb.append(bgCount);
4857 sb.append(" times)");
4858 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004859 } else {
4860 sb.append("(not used)");
4861 }
4862 pw.println(sb.toString());
4863 uidActivity = true;
4864 }
4865
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004866 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
4867 prefix, "Flashlight");
4868 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
4869 prefix, "Camera");
4870 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
4871 prefix, "Video");
4872 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
4873 prefix, "Audio");
4874
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004875 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4876 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004877 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004878 final Uid.Sensor se = sensors.valueAt(ise);
4879 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004880 sb.setLength(0);
4881 sb.append(prefix);
4882 sb.append(" Sensor ");
4883 int handle = se.getHandle();
4884 if (handle == Uid.Sensor.GPS) {
4885 sb.append("GPS");
4886 } else {
4887 sb.append(handle);
4888 }
4889 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004890
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004891 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004892 if (timer != null) {
4893 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08004894 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
4895 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004896 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08004897 final Timer bgTimer = se.getSensorBackgroundTime();
4898 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
4899 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
4900 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4901 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
4902 final long bgActualTime = bgTimer != null ?
4903 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4904
Dianne Hackborn61659e52014-07-09 16:13:01 -07004905 //timer.logState();
4906 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08004907 if (actualTime != totalTime) {
4908 formatTimeMs(sb, totalTime);
4909 sb.append("blamed realtime, ");
4910 }
4911
4912 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07004913 sb.append("realtime (");
4914 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08004915 sb.append(" times)");
4916
4917 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08004918 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08004919 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
4920 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08004921 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08004922 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08004923 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004924 } else {
4925 sb.append("(not used)");
4926 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004927 } else {
4928 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004929 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004930
4931 pw.println(sb.toString());
4932 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004933 }
4934
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004935 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4936 "Vibrator");
4937 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4938 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004939
Dianne Hackborn61659e52014-07-09 16:13:01 -07004940 long totalStateTime = 0;
4941 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4942 long time = u.getProcessStateTime(ips, rawRealtime, which);
4943 if (time > 0) {
4944 totalStateTime += time;
4945 sb.setLength(0);
4946 sb.append(prefix);
4947 sb.append(" ");
4948 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4949 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08004950 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004951 pw.println(sb.toString());
4952 uidActivity = true;
4953 }
4954 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08004955 if (totalStateTime > 0) {
4956 sb.setLength(0);
4957 sb.append(prefix);
4958 sb.append(" Total running: ");
4959 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4960 pw.println(sb.toString());
4961 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004962
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004963 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4964 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07004965 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004966 sb.setLength(0);
4967 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004968 sb.append(" Total cpu time: u=");
4969 formatTimeMs(sb, userCpuTimeUs / 1000);
4970 sb.append("s=");
4971 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004972 pw.println(sb.toString());
4973 }
4974
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004975 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
4976 if (cpuFreqTimes != null) {
4977 sb.setLength(0);
4978 sb.append(" Total cpu time per freq:");
4979 for (int i = 0; i < cpuFreqTimes.length; ++i) {
4980 sb.append(" " + cpuFreqTimes[i]);
4981 }
4982 pw.println(sb.toString());
4983 }
4984 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
4985 if (screenOffCpuFreqTimes != null) {
4986 sb.setLength(0);
4987 sb.append(" Total screen-off cpu time per freq:");
4988 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
4989 sb.append(" " + screenOffCpuFreqTimes[i]);
4990 }
4991 pw.println(sb.toString());
4992 }
4993
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004994 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4995 = u.getProcessStats();
4996 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4997 final Uid.Proc ps = processStats.valueAt(ipr);
4998 long userTime;
4999 long systemTime;
5000 long foregroundTime;
5001 int starts;
5002 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005003
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005004 userTime = ps.getUserTime(which);
5005 systemTime = ps.getSystemTime(which);
5006 foregroundTime = ps.getForegroundTime(which);
5007 starts = ps.getStarts(which);
5008 final int numCrashes = ps.getNumCrashes(which);
5009 final int numAnrs = ps.getNumAnrs(which);
5010 numExcessive = which == STATS_SINCE_CHARGED
5011 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005012
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005013 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5014 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5015 sb.setLength(0);
5016 sb.append(prefix); sb.append(" Proc ");
5017 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5018 sb.append(prefix); sb.append(" CPU: ");
5019 formatTimeMs(sb, userTime); sb.append("usr + ");
5020 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5021 formatTimeMs(sb, foregroundTime); sb.append("fg");
5022 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5023 sb.append("\n"); sb.append(prefix); sb.append(" ");
5024 boolean hasOne = false;
5025 if (starts != 0) {
5026 hasOne = true;
5027 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005028 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005029 if (numCrashes != 0) {
5030 if (hasOne) {
5031 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005032 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005033 hasOne = true;
5034 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005035 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005036 if (numAnrs != 0) {
5037 if (hasOne) {
5038 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005039 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005040 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005041 }
5042 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005043 pw.println(sb.toString());
5044 for (int e=0; e<numExcessive; e++) {
5045 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5046 if (ew != null) {
5047 pw.print(prefix); pw.print(" * Killed for ");
5048 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
5049 pw.print("wake lock");
5050 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
5051 pw.print("cpu");
5052 } else {
5053 pw.print("unknown");
5054 }
5055 pw.print(" use: ");
5056 TimeUtils.formatDuration(ew.usedTime, pw);
5057 pw.print(" over ");
5058 TimeUtils.formatDuration(ew.overTime, pw);
5059 if (ew.overTime != 0) {
5060 pw.print(" (");
5061 pw.print((ew.usedTime*100)/ew.overTime);
5062 pw.println("%)");
5063 }
5064 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005065 }
5066 uidActivity = true;
5067 }
5068 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005069
5070 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5071 = u.getPackageStats();
5072 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5073 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5074 pw.println(":");
5075 boolean apkActivity = false;
5076 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5077 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5078 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5079 pw.print(prefix); pw.print(" Wakeup alarm ");
5080 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5081 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5082 pw.println(" times");
5083 apkActivity = true;
5084 }
5085 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5086 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5087 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5088 final long startTime = ss.getStartTime(batteryUptime, which);
5089 final int starts = ss.getStarts(which);
5090 final int launches = ss.getLaunches(which);
5091 if (startTime != 0 || starts != 0 || launches != 0) {
5092 sb.setLength(0);
5093 sb.append(prefix); sb.append(" Service ");
5094 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5095 sb.append(prefix); sb.append(" Created for: ");
5096 formatTimeMs(sb, startTime / 1000);
5097 sb.append("uptime\n");
5098 sb.append(prefix); sb.append(" Starts: ");
5099 sb.append(starts);
5100 sb.append(", launches: "); sb.append(launches);
5101 pw.println(sb.toString());
5102 apkActivity = true;
5103 }
5104 }
5105 if (!apkActivity) {
5106 pw.print(prefix); pw.println(" (nothing executed)");
5107 }
5108 uidActivity = true;
5109 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005110 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005111 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005112 }
5113 }
5114 }
5115
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005116 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005117 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005118 int diff = oldval ^ newval;
5119 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005120 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005121 for (int i=0; i<descriptions.length; i++) {
5122 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005123 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005124 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005125 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005126 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005127 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005128 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5129 didWake = true;
5130 pw.print("=");
5131 if (longNames) {
5132 UserHandle.formatUid(pw, wakelockTag.uid);
5133 pw.print(":\"");
5134 pw.print(wakelockTag.string);
5135 pw.print("\"");
5136 } else {
5137 pw.print(wakelockTag.poolIdx);
5138 }
5139 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005140 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005141 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005142 pw.print("=");
5143 int val = (newval&bd.mask)>>bd.shift;
5144 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005145 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005146 } else {
5147 pw.print(val);
5148 }
5149 }
5150 }
5151 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005152 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005153 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005154 if (longNames) {
5155 UserHandle.formatUid(pw, wakelockTag.uid);
5156 pw.print(":\"");
5157 pw.print(wakelockTag.string);
5158 pw.print("\"");
5159 } else {
5160 pw.print(wakelockTag.poolIdx);
5161 }
5162 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005163 }
5164
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005165 public void prepareForDumpLocked() {
5166 }
5167
5168 public static class HistoryPrinter {
5169 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005170 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005171 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005172 int oldStatus = -1;
5173 int oldHealth = -1;
5174 int oldPlug = -1;
5175 int oldTemp = -1;
5176 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005177 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005178 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005179
Dianne Hackborn3251b902014-06-20 14:40:53 -07005180 void reset() {
5181 oldState = oldState2 = 0;
5182 oldLevel = -1;
5183 oldStatus = -1;
5184 oldHealth = -1;
5185 oldPlug = -1;
5186 oldTemp = -1;
5187 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005188 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005189 }
5190
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005191 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005192 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005193 if (!checkin) {
5194 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005195 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005196 pw.print(" (");
5197 pw.print(rec.numReadInts);
5198 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005199 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005200 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5201 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005202 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005203 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005204 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005205 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005206 }
5207 lastTime = rec.time;
5208 }
5209 if (rec.cmd == HistoryItem.CMD_START) {
5210 if (checkin) {
5211 pw.print(":");
5212 }
5213 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005214 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005215 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5216 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005217 if (checkin) {
5218 pw.print(":");
5219 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005220 if (rec.cmd == HistoryItem.CMD_RESET) {
5221 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005222 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005223 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005224 pw.print("TIME:");
5225 if (checkin) {
5226 pw.println(rec.currentTime);
5227 } else {
5228 pw.print(" ");
5229 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5230 rec.currentTime).toString());
5231 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005232 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5233 if (checkin) {
5234 pw.print(":");
5235 }
5236 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005237 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5238 if (checkin) {
5239 pw.print(":");
5240 }
5241 pw.println("*OVERFLOW*");
5242 } else {
5243 if (!checkin) {
5244 if (rec.batteryLevel < 10) pw.print("00");
5245 else if (rec.batteryLevel < 100) pw.print("0");
5246 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005247 if (verbose) {
5248 pw.print(" ");
5249 if (rec.states < 0) ;
5250 else if (rec.states < 0x10) pw.print("0000000");
5251 else if (rec.states < 0x100) pw.print("000000");
5252 else if (rec.states < 0x1000) pw.print("00000");
5253 else if (rec.states < 0x10000) pw.print("0000");
5254 else if (rec.states < 0x100000) pw.print("000");
5255 else if (rec.states < 0x1000000) pw.print("00");
5256 else if (rec.states < 0x10000000) pw.print("0");
5257 pw.print(Integer.toHexString(rec.states));
5258 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005259 } else {
5260 if (oldLevel != rec.batteryLevel) {
5261 oldLevel = rec.batteryLevel;
5262 pw.print(",Bl="); pw.print(rec.batteryLevel);
5263 }
5264 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005265 if (oldStatus != rec.batteryStatus) {
5266 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005267 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005268 switch (oldStatus) {
5269 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005270 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005271 break;
5272 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005273 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005274 break;
5275 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005276 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005277 break;
5278 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005279 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005280 break;
5281 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005282 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005283 break;
5284 default:
5285 pw.print(oldStatus);
5286 break;
5287 }
5288 }
5289 if (oldHealth != rec.batteryHealth) {
5290 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005291 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005292 switch (oldHealth) {
5293 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005294 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005295 break;
5296 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005297 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005298 break;
5299 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005300 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005301 break;
5302 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005303 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005304 break;
5305 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005306 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005307 break;
5308 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005309 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005310 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005311 case BatteryManager.BATTERY_HEALTH_COLD:
5312 pw.print(checkin ? "c" : "cold");
5313 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005314 default:
5315 pw.print(oldHealth);
5316 break;
5317 }
5318 }
5319 if (oldPlug != rec.batteryPlugType) {
5320 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005321 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005322 switch (oldPlug) {
5323 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005324 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005325 break;
5326 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005327 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005328 break;
5329 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005330 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005331 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005332 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005333 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005334 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005335 default:
5336 pw.print(oldPlug);
5337 break;
5338 }
5339 }
5340 if (oldTemp != rec.batteryTemperature) {
5341 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005342 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005343 pw.print(oldTemp);
5344 }
5345 if (oldVolt != rec.batteryVoltage) {
5346 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005347 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005348 pw.print(oldVolt);
5349 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005350 final int chargeMAh = rec.batteryChargeUAh / 1000;
5351 if (oldChargeMAh != chargeMAh) {
5352 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005353 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005354 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005355 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005356 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005357 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005358 printBitDescriptions(pw, oldState2, rec.states2, null,
5359 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005360 if (rec.wakeReasonTag != null) {
5361 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005362 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005363 pw.print(rec.wakeReasonTag.poolIdx);
5364 } else {
5365 pw.print(" wake_reason=");
5366 pw.print(rec.wakeReasonTag.uid);
5367 pw.print(":\"");
5368 pw.print(rec.wakeReasonTag.string);
5369 pw.print("\"");
5370 }
5371 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005372 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005373 pw.print(checkin ? "," : " ");
5374 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5375 pw.print("+");
5376 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5377 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005378 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005379 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
5380 : HISTORY_EVENT_NAMES;
5381 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
5382 | HistoryItem.EVENT_FLAG_FINISH);
5383 if (idx >= 0 && idx < eventNames.length) {
5384 pw.print(eventNames[idx]);
5385 } else {
5386 pw.print(checkin ? "Ev" : "event");
5387 pw.print(idx);
5388 }
5389 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005390 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005391 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08005392 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08005393 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
5394 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005395 pw.print(":\"");
5396 pw.print(rec.eventTag.string);
5397 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005398 }
5399 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005400 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005401 if (rec.stepDetails != null) {
5402 if (!checkin) {
5403 pw.print(" Details: cpu=");
5404 pw.print(rec.stepDetails.userTime);
5405 pw.print("u+");
5406 pw.print(rec.stepDetails.systemTime);
5407 pw.print("s");
5408 if (rec.stepDetails.appCpuUid1 >= 0) {
5409 pw.print(" (");
5410 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
5411 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5412 if (rec.stepDetails.appCpuUid2 >= 0) {
5413 pw.print(", ");
5414 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
5415 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5416 }
5417 if (rec.stepDetails.appCpuUid3 >= 0) {
5418 pw.print(", ");
5419 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
5420 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5421 }
5422 pw.print(')');
5423 }
5424 pw.println();
5425 pw.print(" /proc/stat=");
5426 pw.print(rec.stepDetails.statUserTime);
5427 pw.print(" usr, ");
5428 pw.print(rec.stepDetails.statSystemTime);
5429 pw.print(" sys, ");
5430 pw.print(rec.stepDetails.statIOWaitTime);
5431 pw.print(" io, ");
5432 pw.print(rec.stepDetails.statIrqTime);
5433 pw.print(" irq, ");
5434 pw.print(rec.stepDetails.statSoftIrqTime);
5435 pw.print(" sirq, ");
5436 pw.print(rec.stepDetails.statIdlTime);
5437 pw.print(" idle");
5438 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
5439 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
5440 + rec.stepDetails.statSoftIrqTime;
5441 int total = totalRun + rec.stepDetails.statIdlTime;
5442 if (total > 0) {
5443 pw.print(" (");
5444 float perc = ((float)totalRun) / ((float)total) * 100;
5445 pw.print(String.format("%.1f%%", perc));
5446 pw.print(" of ");
5447 StringBuilder sb = new StringBuilder(64);
5448 formatTimeMsNoSpace(sb, total*10);
5449 pw.print(sb);
5450 pw.print(")");
5451 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005452 pw.print(", PlatformIdleStat ");
5453 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005454 pw.println();
5455 } else {
5456 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5457 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
5458 pw.print(rec.stepDetails.userTime);
5459 pw.print(":");
5460 pw.print(rec.stepDetails.systemTime);
5461 if (rec.stepDetails.appCpuUid1 >= 0) {
5462 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
5463 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5464 if (rec.stepDetails.appCpuUid2 >= 0) {
5465 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
5466 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5467 }
5468 if (rec.stepDetails.appCpuUid3 >= 0) {
5469 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
5470 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5471 }
5472 }
5473 pw.println();
5474 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5475 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
5476 pw.print(rec.stepDetails.statUserTime);
5477 pw.print(',');
5478 pw.print(rec.stepDetails.statSystemTime);
5479 pw.print(',');
5480 pw.print(rec.stepDetails.statIOWaitTime);
5481 pw.print(',');
5482 pw.print(rec.stepDetails.statIrqTime);
5483 pw.print(',');
5484 pw.print(rec.stepDetails.statSoftIrqTime);
5485 pw.print(',');
5486 pw.print(rec.stepDetails.statIdlTime);
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005487 pw.print(',');
Adam Lesinski8568d8f2016-07-15 18:13:23 -07005488 if (rec.stepDetails.statPlatformIdleState != null) {
5489 pw.print(rec.stepDetails.statPlatformIdleState);
5490 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005491 pw.println();
5492 }
5493 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005494 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005495 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005496 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005497 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005498
5499 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
5500 UserHandle.formatUid(pw, uid);
5501 pw.print("=");
5502 pw.print(utime);
5503 pw.print("u+");
5504 pw.print(stime);
5505 pw.print("s");
5506 }
5507
5508 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5509 pw.print('/');
5510 pw.print(uid);
5511 pw.print(":");
5512 pw.print(utime);
5513 pw.print(":");
5514 pw.print(stime);
5515 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005516 }
5517
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005518 private void printSizeValue(PrintWriter pw, long size) {
5519 float result = size;
5520 String suffix = "";
5521 if (result >= 10*1024) {
5522 suffix = "KB";
5523 result = result / 1024;
5524 }
5525 if (result >= 10*1024) {
5526 suffix = "MB";
5527 result = result / 1024;
5528 }
5529 if (result >= 10*1024) {
5530 suffix = "GB";
5531 result = result / 1024;
5532 }
5533 if (result >= 10*1024) {
5534 suffix = "TB";
5535 result = result / 1024;
5536 }
5537 if (result >= 10*1024) {
5538 suffix = "PB";
5539 result = result / 1024;
5540 }
5541 pw.print((int)result);
5542 pw.print(suffix);
5543 }
5544
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005545 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5546 String label3, long estimatedTime) {
5547 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005548 return false;
5549 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005550 pw.print(label1);
5551 pw.print(label2);
5552 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005553 StringBuilder sb = new StringBuilder(64);
5554 formatTimeMs(sb, estimatedTime);
5555 pw.print(sb);
5556 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005557 return true;
5558 }
5559
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005560 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5561 LevelStepTracker steps, boolean checkin) {
5562 if (steps == null) {
5563 return false;
5564 }
5565 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005566 if (count <= 0) {
5567 return false;
5568 }
5569 if (!checkin) {
5570 pw.println(header);
5571 }
Kweku Adams030980a2015-04-01 16:07:48 -07005572 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005573 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005574 long duration = steps.getDurationAt(i);
5575 int level = steps.getLevelAt(i);
5576 long initMode = steps.getInitModeAt(i);
5577 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005578 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005579 lineArgs[0] = Long.toString(duration);
5580 lineArgs[1] = Integer.toString(level);
5581 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5582 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5583 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5584 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5585 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5586 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005587 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005588 }
5589 } else {
5590 lineArgs[2] = "";
5591 }
5592 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5593 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5594 } else {
5595 lineArgs[3] = "";
5596 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005597 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005598 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005599 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005600 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005601 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005602 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5603 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005604 pw.print(prefix);
5605 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005606 TimeUtils.formatDuration(duration, pw);
5607 pw.print(" to "); pw.print(level);
5608 boolean haveModes = false;
5609 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5610 pw.print(" (");
5611 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5612 case Display.STATE_OFF: pw.print("screen-off"); break;
5613 case Display.STATE_ON: pw.print("screen-on"); break;
5614 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5615 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005616 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005617 }
5618 haveModes = true;
5619 }
5620 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5621 pw.print(haveModes ? ", " : " (");
5622 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5623 ? "power-save-on" : "power-save-off");
5624 haveModes = true;
5625 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005626 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5627 pw.print(haveModes ? ", " : " (");
5628 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5629 ? "device-idle-on" : "device-idle-off");
5630 haveModes = true;
5631 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005632 if (haveModes) {
5633 pw.print(")");
5634 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005635 pw.println();
5636 }
5637 }
5638 return true;
5639 }
5640
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005641 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005642 public static final int DUMP_DAILY_ONLY = 1<<2;
5643 public static final int DUMP_HISTORY_ONLY = 1<<3;
5644 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5645 public static final int DUMP_VERBOSE = 1<<5;
5646 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005647
Dianne Hackborn37de0982014-05-09 09:32:18 -07005648 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5649 final HistoryPrinter hprinter = new HistoryPrinter();
5650 final HistoryItem rec = new HistoryItem();
5651 long lastTime = -1;
5652 long baseTime = -1;
5653 boolean printed = false;
5654 HistoryEventTracker tracker = null;
5655 while (getNextHistoryLocked(rec)) {
5656 lastTime = rec.time;
5657 if (baseTime < 0) {
5658 baseTime = lastTime;
5659 }
5660 if (rec.time >= histStart) {
5661 if (histStart >= 0 && !printed) {
5662 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005663 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005664 || rec.cmd == HistoryItem.CMD_START
5665 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005666 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005667 hprinter.printNextItem(pw, rec, baseTime, checkin,
5668 (flags&DUMP_VERBOSE) != 0);
5669 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005670 } else if (rec.currentTime != 0) {
5671 printed = true;
5672 byte cmd = rec.cmd;
5673 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005674 hprinter.printNextItem(pw, rec, baseTime, checkin,
5675 (flags&DUMP_VERBOSE) != 0);
5676 rec.cmd = cmd;
5677 }
5678 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005679 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5680 hprinter.printNextItem(pw, rec, baseTime, checkin,
5681 (flags&DUMP_VERBOSE) != 0);
5682 rec.cmd = HistoryItem.CMD_UPDATE;
5683 }
5684 int oldEventCode = rec.eventCode;
5685 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005686 rec.eventTag = new HistoryTag();
5687 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5688 HashMap<String, SparseIntArray> active
5689 = tracker.getStateForEvent(i);
5690 if (active == null) {
5691 continue;
5692 }
5693 for (HashMap.Entry<String, SparseIntArray> ent
5694 : active.entrySet()) {
5695 SparseIntArray uids = ent.getValue();
5696 for (int j=0; j<uids.size(); j++) {
5697 rec.eventCode = i;
5698 rec.eventTag.string = ent.getKey();
5699 rec.eventTag.uid = uids.keyAt(j);
5700 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005701 hprinter.printNextItem(pw, rec, baseTime, checkin,
5702 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005703 rec.wakeReasonTag = null;
5704 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005705 }
5706 }
5707 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005708 rec.eventCode = oldEventCode;
5709 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005710 tracker = null;
5711 }
5712 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005713 hprinter.printNextItem(pw, rec, baseTime, checkin,
5714 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005715 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5716 // This is an attempt to aggregate the previous state and generate
5717 // fake events to reflect that state at the point where we start
5718 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005719 if (tracker == null) {
5720 tracker = new HistoryEventTracker();
5721 }
5722 tracker.updateState(rec.eventCode, rec.eventTag.string,
5723 rec.eventTag.uid, rec.eventTag.poolIdx);
5724 }
5725 }
5726 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005727 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005728 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5729 }
5730 }
5731
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005732 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5733 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5734 if (steps == null) {
5735 return;
5736 }
5737 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5738 if (timeRemaining >= 0) {
5739 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5740 tmpSb.setLength(0);
5741 formatTimeMs(tmpSb, timeRemaining);
5742 pw.print(tmpSb);
5743 pw.print(" (from "); pw.print(tmpOutInt[0]);
5744 pw.println(" steps)");
5745 }
5746 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5747 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5748 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5749 if (estimatedTime > 0) {
5750 pw.print(prefix); pw.print(label); pw.print(" ");
5751 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5752 pw.print(" time: ");
5753 tmpSb.setLength(0);
5754 formatTimeMs(tmpSb, estimatedTime);
5755 pw.print(tmpSb);
5756 pw.print(" (from "); pw.print(tmpOutInt[0]);
5757 pw.println(" steps)");
5758 }
5759 }
5760 }
5761
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005762 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5763 ArrayList<PackageChange> changes) {
5764 if (changes == null) {
5765 return;
5766 }
5767 pw.print(prefix); pw.println("Package changes:");
5768 for (int i=0; i<changes.size(); i++) {
5769 PackageChange pc = changes.get(i);
5770 if (pc.mUpdate) {
5771 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5772 pw.print(" vers="); pw.println(pc.mVersionCode);
5773 } else {
5774 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5775 }
5776 }
5777 }
5778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005779 /**
5780 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5781 *
5782 * @param pw a Printer to receive the dump output.
5783 */
5784 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005785 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005786 prepareForDumpLocked();
5787
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005788 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005789 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005790
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005791 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005792 final long historyTotalSize = getHistoryTotalSize();
5793 final long historyUsedSize = getHistoryUsedSize();
5794 if (startIteratingHistoryLocked()) {
5795 try {
5796 pw.print("Battery History (");
5797 pw.print((100*historyUsedSize)/historyTotalSize);
5798 pw.print("% used, ");
5799 printSizeValue(pw, historyUsedSize);
5800 pw.print(" used of ");
5801 printSizeValue(pw, historyTotalSize);
5802 pw.print(", ");
5803 pw.print(getHistoryStringPoolSize());
5804 pw.print(" strings using ");
5805 printSizeValue(pw, getHistoryStringPoolBytes());
5806 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005807 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005808 pw.println();
5809 } finally {
5810 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005811 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005812 }
5813
5814 if (startIteratingOldHistoryLocked()) {
5815 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005816 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005817 pw.println("Old battery History:");
5818 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005819 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005820 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005821 if (baseTime < 0) {
5822 baseTime = rec.time;
5823 }
5824 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005825 }
5826 pw.println();
5827 } finally {
5828 finishIteratingOldHistoryLocked();
5829 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005830 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005831 }
5832
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005833 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005834 return;
5835 }
5836
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005837 if (!filtering) {
5838 SparseArray<? extends Uid> uidStats = getUidStats();
5839 final int NU = uidStats.size();
5840 boolean didPid = false;
5841 long nowRealtime = SystemClock.elapsedRealtime();
5842 for (int i=0; i<NU; i++) {
5843 Uid uid = uidStats.valueAt(i);
5844 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
5845 if (pids != null) {
5846 for (int j=0; j<pids.size(); j++) {
5847 Uid.Pid pid = pids.valueAt(j);
5848 if (!didPid) {
5849 pw.println("Per-PID Stats:");
5850 didPid = true;
5851 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005852 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
5853 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005854 pw.print(" PID "); pw.print(pids.keyAt(j));
5855 pw.print(" wake time: ");
5856 TimeUtils.formatDuration(time, pw);
5857 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005858 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005859 }
5860 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005861 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005862 pw.println();
5863 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005864 }
5865
5866 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005867 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
5868 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07005869 long timeRemaining = computeBatteryTimeRemaining(
5870 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005871 if (timeRemaining >= 0) {
5872 pw.print(" Estimated discharge time remaining: ");
5873 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5874 pw.println();
5875 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005876 final LevelStepTracker steps = getDischargeLevelStepTracker();
5877 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5878 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
5879 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5880 STEP_LEVEL_MODE_VALUES[i], null));
5881 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005882 pw.println();
5883 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005884 if (dumpDurationSteps(pw, " ", "Charge step durations:",
5885 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07005886 long timeRemaining = computeChargeTimeRemaining(
5887 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005888 if (timeRemaining >= 0) {
5889 pw.print(" Estimated charge time remaining: ");
5890 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5891 pw.println();
5892 }
5893 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005894 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005895 }
5896 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
5897 pw.println("Daily stats:");
5898 pw.print(" Current start time: ");
5899 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5900 getCurrentDailyStartTime()).toString());
5901 pw.print(" Next min deadline: ");
5902 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5903 getNextMinDailyDeadline()).toString());
5904 pw.print(" Next max deadline: ");
5905 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5906 getNextMaxDailyDeadline()).toString());
5907 StringBuilder sb = new StringBuilder(64);
5908 int[] outInt = new int[1];
5909 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
5910 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005911 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
5912 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005913 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005914 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
5915 dsteps, false)) {
5916 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5917 sb, outInt);
5918 }
5919 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
5920 csteps, false)) {
5921 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5922 sb, outInt);
5923 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005924 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005925 } else {
5926 pw.println(" Current daily steps:");
5927 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5928 sb, outInt);
5929 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5930 sb, outInt);
5931 }
5932 }
5933 DailyItem dit;
5934 int curIndex = 0;
5935 while ((dit=getDailyItemLocked(curIndex)) != null) {
5936 curIndex++;
5937 if ((flags&DUMP_DAILY_ONLY) != 0) {
5938 pw.println();
5939 }
5940 pw.print(" Daily from ");
5941 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
5942 pw.print(" to ");
5943 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
5944 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005945 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005946 if (dumpDurationSteps(pw, " ",
5947 " Discharge step durations:", dit.mDischargeSteps, false)) {
5948 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5949 sb, outInt);
5950 }
5951 if (dumpDurationSteps(pw, " ",
5952 " Charge step durations:", dit.mChargeSteps, false)) {
5953 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5954 sb, outInt);
5955 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005956 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005957 } else {
5958 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5959 sb, outInt);
5960 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5961 sb, outInt);
5962 }
5963 }
5964 pw.println();
5965 }
5966 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005967 pw.println("Statistics since last charge:");
5968 pw.println(" System starts: " + getStartCount()
5969 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005970 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5971 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005972 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005973 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005974 }
5975
5976 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005977 public void dumpCheckinLocked(Context context, PrintWriter pw,
5978 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005979 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005980
5981 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005982 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5983 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005984
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005985 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5986
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005987 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005988 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005989
5990 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005991 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005992 try {
5993 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5994 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5995 pw.print(HISTORY_STRING_POOL); pw.print(',');
5996 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005997 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005998 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005999 pw.print(",\"");
6000 String str = getHistoryTagPoolString(i);
6001 str = str.replace("\\", "\\\\");
6002 str = str.replace("\"", "\\\"");
6003 pw.print(str);
6004 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006005 pw.println();
6006 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006007 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006008 } finally {
6009 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006010 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006011 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006012 }
6013
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006014 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006015 return;
6016 }
6017
Dianne Hackborne4a59512010-12-07 11:08:07 -08006018 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006019 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006020 for (int i=0; i<apps.size(); i++) {
6021 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006022 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6023 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006024 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006025 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6026 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006027 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006028 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006029 }
6030 SparseArray<? extends Uid> uidStats = getUidStats();
6031 final int NU = uidStats.size();
6032 String[] lineArgs = new String[2];
6033 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006034 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6035 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6036 if (pkgs != null && !pkgs.second.value) {
6037 pkgs.second.value = true;
6038 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006039 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006040 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006041 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6042 (Object[])lineArgs);
6043 }
6044 }
6045 }
6046 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006047 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006048 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006049 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006050 long timeRemaining = computeBatteryTimeRemaining(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 */, DISCHARGE_TIME_REMAIN_DATA,
6054 (Object[])lineArgs);
6055 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006056 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006057 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006058 if (timeRemaining >= 0) {
6059 lineArgs[0] = Long.toString(timeRemaining);
6060 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6061 (Object[])lineArgs);
6062 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006063 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6064 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006065 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006066 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006067}