blob: f821f59ff9f93b355bf0b98f8c03a67f22b411de [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.os;
18
19import java.io.PrintWriter;
Dianne Hackborne4a59512010-12-07 11:08:07 -080020import java.util.ArrayList;
Dianne Hackborn81038902012-11-26 17:04:09 -080021import java.util.Collections;
22import java.util.Comparator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import java.util.Formatter;
Dianne Hackborn37de0982014-05-09 09:32:18 -070024import java.util.HashMap;
Dianne Hackborne4a59512010-12-07 11:08:07 -080025import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import java.util.Map;
27
Dianne Hackborna7c837f2014-01-15 16:20:44 -080028import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080029import android.content.pm.ApplicationInfo;
Wink Saville52840902011-02-18 12:40:47 -080030import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080031import android.text.format.DateFormat;
Dianne Hackborn1e725a72015-03-24 18:23:19 -070032import android.util.ArrayMap;
James Carr2dd7e5e2016-07-20 18:48:39 -070033import android.util.LongSparseArray;
Dianne Hackborn9cfba352016-03-24 17:31:28 -070034import android.util.MutableBoolean;
35import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.util.Printer;
37import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070038import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070039import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070040import android.view.Display;
Amith Yamasaniab9ad192016-12-06 12:46:59 -080041
Dianne Hackborna7c837f2014-01-15 16:20:44 -080042import com.android.internal.os.BatterySipper;
43import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
45/**
46 * A class providing access to battery usage statistics, including information on
47 * wakelocks, processes, packages, and services. All times are represented in microseconds
48 * except where indicated otherwise.
49 * @hide
50 */
51public abstract class BatteryStats implements Parcelable {
Joe Onorato92fd23f2016-07-25 11:18:42 -070052 private static final String TAG = "BatteryStats";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053
54 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070055
56 /** @hide */
57 public static final String SERVICE_NAME = "batterystats";
58
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 /**
60 * A constant indicating a partial wake lock timer.
61 */
62 public static final int WAKE_TYPE_PARTIAL = 0;
63
64 /**
65 * A constant indicating a full wake lock timer.
66 */
67 public static final int WAKE_TYPE_FULL = 1;
68
69 /**
70 * A constant indicating a window wake lock timer.
71 */
72 public static final int WAKE_TYPE_WINDOW = 2;
Adam Lesinski9425fe22015-06-19 12:02:13 -070073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 /**
75 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 */
77 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070078
79 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070080 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070081 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070082 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070083
84 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070085 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070086 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070087 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070088
89 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070090 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070091 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070092 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093
Dianne Hackborn62793e42015-03-09 11:15:41 -070094 /**
95 * A constant indicating a wifi multicast timer
96 */
97 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700100 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700101 */
102 public static final int VIDEO_TURNED_ON = 8;
103
104 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800105 * A constant indicating a vibrator on timer
106 */
107 public static final int VIBRATOR_ON = 9;
108
109 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700110 * A constant indicating a foreground activity timer
111 */
112 public static final int FOREGROUND_ACTIVITY = 10;
113
114 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700115 * A constant indicating a wifi batched scan is active
116 */
117 public static final int WIFI_BATCHED_SCAN = 11;
118
119 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700120 * A constant indicating a process state timer
121 */
122 public static final int PROCESS_STATE = 12;
123
124 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700125 * A constant indicating a sync timer
126 */
127 public static final int SYNC = 13;
128
129 /**
130 * A constant indicating a job timer
131 */
132 public static final int JOB = 14;
133
134 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800135 * A constant indicating an audio turn on timer
136 */
137 public static final int AUDIO_TURNED_ON = 15;
138
139 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700140 * A constant indicating a flashlight turn on timer
141 */
142 public static final int FLASHLIGHT_TURNED_ON = 16;
143
144 /**
145 * A constant indicating a camera turn on timer
146 */
147 public static final int CAMERA_TURNED_ON = 17;
148
149 /**
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700150 * A constant indicating a draw wake lock timer.
Adam Lesinski9425fe22015-06-19 12:02:13 -0700151 */
Jeff Brown6a8bd7b2015-06-19 15:07:51 -0700152 public static final int WAKE_TYPE_DRAW = 18;
Adam Lesinski9425fe22015-06-19 12:02:13 -0700153
154 /**
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800155 * A constant indicating a bluetooth scan timer.
156 */
157 public static final int BLUETOOTH_SCAN_ON = 19;
158
159 /**
Bookatzc8c44962017-05-11 12:12:54 -0700160 * A constant indicating an aggregated partial wake lock timer.
161 */
162 public static final int AGGREGATED_WAKE_TYPE_PARTIAL = 20;
163
164 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 * Include all of the data in the stats, including previously saved data.
166 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700167 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168
169 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 * Include only the current run in the stats.
171 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700172 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173
174 /**
175 * Include only the run since the last time the device was unplugged in the stats.
176 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700177 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700178
179 // NOTE: Update this list if you add/change any stats above.
180 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700181 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700182 private static final String[] STAT_NAMES = { "l", "c", "u" };
183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700185 * Current version of checkin data format.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700186 *
187 * New in version 19:
188 * - Wakelock data (wl) gets current and max times.
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800189 * New in version 20:
Bookatz2bffb5b2017-04-13 11:59:33 -0700190 * - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs.
Bookatz506a8182017-05-01 14:18:42 -0700191 * New in version 21:
192 * - Actual (not just apportioned) Wakelock time is also recorded.
Bookatzc8c44962017-05-11 12:12:54 -0700193 * - Aggregated partial wakelock time (per uid, instead of per wakelock) is recorded.
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700194 */
Bookatz506a8182017-05-01 14:18:42 -0700195 static final String CHECKIN_VERSION = "21";
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700196
197 /**
198 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700200 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700201
Evan Millar22ac0432009-03-31 11:33:18 -0700202 private static final long BYTES_PER_KB = 1024;
203 private static final long BYTES_PER_MB = 1048576; // 1024^2
204 private static final long BYTES_PER_GB = 1073741824; //1024^3
Bookatz506a8182017-05-01 14:18:42 -0700205
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700206 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800207 private static final String UID_DATA = "uid";
Joe Onorato1476d322016-05-05 14:46:15 -0700208 private static final String WAKEUP_ALARM_DATA = "wua";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700210 private static final String PROCESS_DATA = "pr";
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700211 private static final String CPU_DATA = "cpu";
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700212 private static final String GLOBAL_CPU_FREQ_DATA = "gcf";
213 private static final String CPU_TIMES_AT_FREQ_DATA = "ctf";
Evan Millare84de8d2009-04-02 22:16:12 -0700214 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800215 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700216 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700217 private static final String STATE_TIME_DATA = "st";
Bookatz506a8182017-05-01 14:18:42 -0700218 // wl line is:
219 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
220 // full totalTime, 'f', count, current duration, max duration, total duration,
221 // partial totalTime, 'p', count, current duration, max duration, total duration,
222 // window totalTime, 'w', count, current duration, max duration, total duration
223 // [Currently, full and window wakelocks have durations current = max = total = -1]
Evan Millare84de8d2009-04-02 22:16:12 -0700224 private static final String WAKELOCK_DATA = "wl";
Bookatzc8c44962017-05-11 12:12:54 -0700225 // awl line is:
226 // BATTERY_STATS_CHECKIN_VERSION, uid, which, "awl",
227 // cumulative partial wakelock duration, cumulative background partial wakelock duration
228 private static final String AGGREGATED_WAKELOCK_DATA = "awl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700229 private static final String SYNC_DATA = "sy";
230 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700231 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700232 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700233 private static final String NETWORK_DATA = "nt";
234 private static final String USER_ACTIVITY_DATA = "ua";
235 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800236 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700237 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700238 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700239 private static final String WIFI_DATA = "wfl";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800240 private static final String GLOBAL_WIFI_CONTROLLER_DATA = "gwfcd";
241 private static final String WIFI_CONTROLLER_DATA = "wfcd";
242 private static final String GLOBAL_BLUETOOTH_CONTROLLER_DATA = "gble";
243 private static final String BLUETOOTH_CONTROLLER_DATA = "ble";
Adam Lesinskid9b99be2016-03-30 16:58:51 -0700244 private static final String BLUETOOTH_MISC_DATA = "blem";
Evan Millare84de8d2009-04-02 22:16:12 -0700245 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800246 private static final String GLOBAL_NETWORK_DATA = "gn";
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800247 private static final String GLOBAL_MODEM_CONTROLLER_DATA = "gmcd";
248 private static final String MODEM_CONTROLLER_DATA = "mcd";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800249 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700250 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700251 private static final String SCREEN_BRIGHTNESS_DATA = "br";
252 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700253 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700254 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
255 private static final String DATA_CONNECTION_TIME_DATA = "dct";
256 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800257 private static final String WIFI_STATE_TIME_DATA = "wst";
258 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700259 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
260 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
261 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
262 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800263 private static final String POWER_USE_SUMMARY_DATA = "pws";
264 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700265 private static final String DISCHARGE_STEP_DATA = "dsd";
266 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700267 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
268 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700269 private static final String FLASHLIGHT_DATA = "fla";
270 private static final String CAMERA_DATA = "cam";
271 private static final String VIDEO_DATA = "vid";
272 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273
Adam Lesinski010bf372016-04-11 12:18:18 -0700274 public static final String RESULT_RECEIVER_CONTROLLER_KEY = "controller_activity";
275
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700276 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 private final Formatter mFormatter = new Formatter(mFormatBuilder);
278
279 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700280 * Indicates times spent by the uid at each cpu frequency in all process states.
281 *
282 * Other types might include times spent in foreground, background etc.
283 */
284 private final String UID_TIMES_TYPE_ALL = "A";
285
286 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700287 * State for keeping track of counting information.
288 */
289 public static abstract class Counter {
290
291 /**
292 * Returns the count associated with this Counter for the
293 * selected type of statistics.
294 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700295 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700296 */
Evan Millarc64edde2009-04-18 12:26:32 -0700297 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700298
299 /**
300 * Temporary for debugging.
301 */
302 public abstract void logState(Printer pw, String prefix);
303 }
304
305 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700306 * State for keeping track of long counting information.
307 */
308 public static abstract class LongCounter {
309
310 /**
311 * Returns the count associated with this Counter for the
312 * selected type of statistics.
313 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700314 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700315 */
316 public abstract long getCountLocked(int which);
317
318 /**
319 * Temporary for debugging.
320 */
321 public abstract void logState(Printer pw, String prefix);
322 }
323
324 /**
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700325 * State for keeping track of array of long counting information.
326 */
327 public static abstract class LongCounterArray {
328 /**
329 * Returns the counts associated with this Counter for the
330 * selected type of statistics.
331 *
332 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
333 */
334 public abstract long[] getCountsLocked(int which);
335
336 /**
337 * Temporary for debugging.
338 */
339 public abstract void logState(Printer pw, String prefix);
340 }
341
342 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800343 * Container class that aggregates counters for transmit, receive, and idle state of a
344 * radio controller.
345 */
346 public static abstract class ControllerActivityCounter {
347 /**
348 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
349 * idle state.
350 */
351 public abstract LongCounter getIdleTimeCounter();
352
353 /**
354 * @return a non-null {@link LongCounter} representing time spent (milliseconds) in the
355 * receive state.
356 */
357 public abstract LongCounter getRxTimeCounter();
358
359 /**
360 * An array of {@link LongCounter}, representing various transmit levels, where each level
361 * may draw a different amount of power. The levels themselves are controller-specific.
362 * @return non-null array of {@link LongCounter}s representing time spent (milliseconds) in
363 * various transmit level states.
364 */
365 public abstract LongCounter[] getTxTimeCounters();
366
367 /**
368 * @return a non-null {@link LongCounter} representing the power consumed by the controller
369 * in all states, measured in milli-ampere-milliseconds (mAms). The counter may always
370 * yield a value of 0 if the device doesn't support power calculations.
371 */
372 public abstract LongCounter getPowerCounter();
373 }
374
375 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 * State for keeping track of timing information.
377 */
378 public static abstract class Timer {
379
380 /**
381 * Returns the count associated with this Timer for the
382 * selected type of statistics.
383 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700384 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 */
Evan Millarc64edde2009-04-18 12:26:32 -0700386 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387
388 /**
389 * Returns the total time in microseconds associated with this Timer for the
390 * selected type of statistics.
391 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800392 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700393 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 * @return a time in microseconds
395 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800396 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700397
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700399 * Returns the total time in microseconds associated with this Timer since the
400 * 'mark' was last set.
401 *
402 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
403 * @return a time in microseconds
404 */
405 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
406
407 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700408 * Returns the max duration if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800409 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700410
411 */
412 public long getMaxDurationMsLocked(long elapsedRealtimeMs) {
413 return -1;
414 }
415
416 /**
417 * Returns the current time the timer has been active, if it is being tracked.
Bookatz867c0d72017-03-07 18:23:42 -0800418 * Not all Timer subclasses track the max, total, current durations.
Joe Onorato92fd23f2016-07-25 11:18:42 -0700419 */
420 public long getCurrentDurationMsLocked(long elapsedRealtimeMs) {
421 return -1;
422 }
423
424 /**
Bookatz867c0d72017-03-07 18:23:42 -0800425 * Returns the current time the timer has been active, if it is being tracked.
426 *
427 * Returns the total cumulative duration (i.e. sum of past durations) that this timer has
428 * been on since reset.
429 * This may differ from getTotalTimeLocked(elapsedRealtimeUs, STATS_SINCE_CHARGED)/1000 since,
430 * depending on the Timer, getTotalTimeLocked may represent the total 'blamed' or 'pooled'
431 * time, rather than the actual time. By contrast, getTotalDurationMsLocked always gives
432 * the actual total time.
433 * Not all Timer subclasses track the max, total, current durations.
434 */
435 public long getTotalDurationMsLocked(long elapsedRealtimeMs) {
436 return -1;
437 }
438
439 /**
Bookatzaa4594a2017-03-24 12:39:56 -0700440 * Returns the secondary Timer held by the Timer, if one exists. This secondary timer may be
441 * used, for example, for tracking background usage. Secondary timers are never pooled.
442 *
443 * Not all Timer subclasses have a secondary timer; those that don't return null.
444 */
445 public Timer getSubTimer() {
446 return null;
447 }
448
449 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -0700450 * Returns whether the timer is currently running. Some types of timers
451 * (e.g. BatchTimers) don't know whether the event is currently active,
452 * and report false.
453 */
454 public boolean isRunningLocked() {
455 return false;
456 }
457
458 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 * Temporary for debugging.
460 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700461 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 }
463
464 /**
465 * The statistics associated with a particular uid.
466 */
467 public static abstract class Uid {
468
469 /**
470 * Returns a mapping containing wakelock statistics.
471 *
472 * @return a Map from Strings to Uid.Wakelock objects.
473 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700474 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475
476 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700477 * Returns a mapping containing sync statistics.
478 *
479 * @return a Map from Strings to Timer objects.
480 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700481 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700482
483 /**
484 * Returns a mapping containing scheduled job statistics.
485 *
486 * @return a Map from Strings to Timer objects.
487 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700488 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700489
490 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 * The statistics associated with a particular wake lock.
492 */
493 public static abstract class Wakelock {
494 public abstract Timer getWakeTime(int type);
495 }
496
497 /**
Bookatzc8c44962017-05-11 12:12:54 -0700498 * The cumulative time the uid spent holding any partial wakelocks. This will generally
499 * differ from summing over the Wakelocks in getWakelockStats since the latter may have
500 * wakelocks that overlap in time (and therefore over-counts).
501 */
502 public abstract Timer getAggregatedPartialWakelockTimer();
503
504 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 * Returns a mapping containing sensor statistics.
506 *
507 * @return a Map from Integer sensor ids to Uid.Sensor objects.
508 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700509 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510
511 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700512 * Returns a mapping containing active process data.
513 */
514 public abstract SparseArray<? extends Pid> getPidStats();
Bookatzc8c44962017-05-11 12:12:54 -0700515
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700516 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 * Returns a mapping containing process statistics.
518 *
519 * @return a Map from Strings to Uid.Proc objects.
520 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700521 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522
523 /**
524 * Returns a mapping containing package statistics.
525 *
526 * @return a Map from Strings to Uid.Pkg objects.
527 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700528 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700529
Adam Lesinski21f76aa2016-01-25 12:27:06 -0800530 public abstract ControllerActivityCounter getWifiControllerActivity();
531 public abstract ControllerActivityCounter getBluetoothControllerActivity();
532 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski50e47602015-12-04 17:04:54 -0800533
534 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 * {@hide}
536 */
537 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700538
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800539 public abstract void noteWifiRunningLocked(long elapsedRealtime);
540 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
541 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
542 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
543 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
544 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
545 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
546 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
547 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
548 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800549 public abstract void noteActivityResumedLocked(long elapsedRealtime);
550 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800551 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
552 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
553 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700554 public abstract int getWifiScanCount(int which);
Bookatz867c0d72017-03-07 18:23:42 -0800555 public abstract int getWifiScanBackgroundCount(int which);
556 public abstract long getWifiScanActualTime(long elapsedRealtimeUs);
557 public abstract long getWifiScanBackgroundTime(long elapsedRealtimeUs);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800558 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700559 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800560 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700561 public abstract Timer getAudioTurnedOnTimer();
562 public abstract Timer getVideoTurnedOnTimer();
563 public abstract Timer getFlashlightTurnedOnTimer();
564 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700565 public abstract Timer getForegroundActivityTimer();
Adam Lesinski9f55cc72016-01-27 20:42:14 -0800566 public abstract Timer getBluetoothScanTimer();
Bookatz867c0d72017-03-07 18:23:42 -0800567 public abstract Timer getBluetoothScanBackgroundTimer();
Bookatz956f36bf2017-04-28 09:48:17 -0700568 public abstract Counter getBluetoothScanResultCounter();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700569
Sudheer Shanka9b735c52017-05-09 18:26:18 -0700570 public abstract long[] getCpuFreqTimes(int which);
571 public abstract long[] getScreenOffCpuFreqTimes(int which);
572
Dianne Hackborna0200e32016-03-30 18:01:41 -0700573 // Note: the following times are disjoint. They can be added together to find the
574 // total time a uid has had any processes running at all.
575
576 /**
577 * Time this uid has any processes in the top state (or above such as persistent).
578 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800579 public static final int PROCESS_STATE_TOP = 0;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700580 /**
581 * Time this uid has any process with a started out bound foreground service, but
582 * none in the "top" state.
583 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800584 public static final int PROCESS_STATE_FOREGROUND_SERVICE = 1;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700585 /**
586 * Time this uid has any process that is top while the device is sleeping, but none
587 * in the "foreground service" or better state.
588 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800589 public static final int PROCESS_STATE_TOP_SLEEPING = 2;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700590 /**
591 * Time this uid has any process in an active foreground state, but none in the
592 * "top sleeping" or better state.
593 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800594 public static final int PROCESS_STATE_FOREGROUND = 3;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700595 /**
596 * Time this uid has any process in an active background state, but none in the
597 * "foreground" or better state.
598 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800599 public static final int PROCESS_STATE_BACKGROUND = 4;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700600 /**
601 * Time this uid has any processes that are sitting around cached, not in one of the
602 * other active states.
603 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800604 public static final int PROCESS_STATE_CACHED = 5;
Dianne Hackborna0200e32016-03-30 18:01:41 -0700605 /**
606 * Total number of process states we track.
607 */
Dianne Hackborna8d10942015-11-19 17:55:19 -0800608 public static final int NUM_PROCESS_STATE = 6;
Dianne Hackborn61659e52014-07-09 16:13:01 -0700609
610 static final String[] PROCESS_STATE_NAMES = {
Dianne Hackborna8d10942015-11-19 17:55:19 -0800611 "Top", "Fg Service", "Top Sleeping", "Foreground", "Background", "Cached"
Dianne Hackborn61659e52014-07-09 16:13:01 -0700612 };
613
614 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
Joe Onorato713fec82016-03-04 10:34:02 -0800615 public abstract Timer getProcessStateTimer(int state);
Dianne Hackborn61659e52014-07-09 16:13:01 -0700616
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800617 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618
Robert Greenwalta029ea12013-09-25 16:38:12 -0700619 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
620
Dianne Hackborn617f8772009-03-31 15:04:46 -0700621 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700622 * Note that these must match the constants in android.os.PowerManager.
623 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
624 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700625 */
626 static final String[] USER_ACTIVITY_TYPES = {
Phil Weaverda80d672016-03-15 16:25:46 -0700627 "other", "button", "touch", "accessibility"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700628 };
Bookatzc8c44962017-05-11 12:12:54 -0700629
Phil Weaverda80d672016-03-15 16:25:46 -0700630 public static final int NUM_USER_ACTIVITY_TYPES = 4;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700631
Dianne Hackborn617f8772009-03-31 15:04:46 -0700632 public abstract void noteUserActivityLocked(int type);
633 public abstract boolean hasUserActivity();
634 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700635
636 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800637 public abstract long getNetworkActivityBytes(int type, int which);
638 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800639 public abstract long getMobileRadioActiveTime(int which);
640 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700641
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700642 /**
643 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
644 */
645 public abstract long getUserCpuTimeUs(int which);
646
647 /**
648 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
649 */
650 public abstract long getSystemCpuTimeUs(int which);
651
652 /**
Adam Lesinski6832f392015-09-05 18:05:40 -0700653 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed for a
654 * given CPU cluster.
655 * @param cluster the index of the CPU cluster.
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -0700656 * @param step the index of the CPU speed. This is not the actual speed of the CPU.
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700657 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn08c47a52015-10-15 12:38:14 -0700658 * @see com.android.internal.os.PowerProfile#getNumCpuClusters()
659 * @see com.android.internal.os.PowerProfile#getNumSpeedStepsInCpuCluster(int)
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700660 */
Adam Lesinski6832f392015-09-05 18:05:40 -0700661 public abstract long getTimeAtCpuSpeed(int cluster, int step, int which);
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700662
Adam Lesinski5f056f62016-07-14 16:56:08 -0700663 /**
664 * Returns the number of times this UID woke up the Application Processor to
665 * process a mobile radio packet.
666 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
667 */
668 public abstract long getMobileRadioApWakeupCount(int which);
669
670 /**
671 * Returns the number of times this UID woke up the Application Processor to
672 * process a WiFi packet.
673 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
674 */
675 public abstract long getWifiRadioApWakeupCount(int which);
676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800678 /*
679 * FIXME: it's not correct to use this magic value because it
680 * could clash with a sensor handle (which are defined by
681 * the sensor HAL, and therefore out of our control
682 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 // Magic sensor number for the GPS.
684 public static final int GPS = -10000;
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800685
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 public abstract int getHandle();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 public abstract Timer getSensorTime();
Amith Yamasaniab9ad192016-12-06 12:46:59 -0800689
Bookatz867c0d72017-03-07 18:23:42 -0800690 /** Returns a Timer for sensor usage when app is in the background. */
691 public abstract Timer getSensorBackgroundTime();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 }
693
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700694 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800695 public int mWakeNesting;
696 public long mWakeSumMs;
697 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700698 }
699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 /**
701 * The statistics associated with a particular process.
702 */
703 public static abstract class Proc {
704
Dianne Hackborn287952c2010-09-22 22:34:31 -0700705 public static class ExcessivePower {
706 public static final int TYPE_WAKE = 1;
707 public static final int TYPE_CPU = 2;
708
709 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700710 public long overTime;
711 public long usedTime;
712 }
713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800715 * Returns true if this process is still active in the battery stats.
716 */
717 public abstract boolean isActive();
718
719 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700720 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800721 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700722 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 */
724 public abstract long getUserTime(int which);
725
726 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700727 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700729 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 */
731 public abstract long getSystemTime(int which);
732
733 /**
734 * Returns the number of times the process has been started.
735 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700736 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 */
738 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700739
740 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800741 * Returns the number of times the process has crashed.
742 *
743 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
744 */
745 public abstract int getNumCrashes(int which);
746
747 /**
748 * Returns the number of times the process has ANRed.
749 *
750 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
751 */
752 public abstract int getNumAnrs(int which);
753
754 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700755 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700756 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700757 * @return foreground cpu time in microseconds
758 */
759 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700760
Dianne Hackborn287952c2010-09-22 22:34:31 -0700761 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700762
Dianne Hackborn287952c2010-09-22 22:34:31 -0700763 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 }
765
766 /**
767 * The statistics associated with a particular package.
768 */
769 public static abstract class Pkg {
770
771 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700772 * Returns information about all wakeup alarms that have been triggered for this
773 * package. The mapping keys are tag names for the alarms, the counter contains
774 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700776 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777
778 /**
779 * Returns a mapping containing service statistics.
780 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700781 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782
783 /**
784 * The statistics associated with a particular service.
785 */
Joe Onoratoabded112016-02-08 16:49:39 -0800786 public static abstract class Serv {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787
788 /**
789 * Returns the amount of time spent started.
790 *
791 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700792 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 * @return
794 */
795 public abstract long getStartTime(long batteryUptime, int which);
796
797 /**
798 * Returns the total number of times startService() has been called.
799 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700800 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 */
802 public abstract int getStarts(int which);
803
804 /**
805 * Returns the total number times the service has been launched.
806 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700807 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 */
809 public abstract int getLaunches(int which);
810 }
811 }
812 }
813
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800814 public static final class LevelStepTracker {
815 public long mLastStepTime = -1;
816 public int mNumStepDurations;
817 public final long[] mStepDurations;
818
819 public LevelStepTracker(int maxLevelSteps) {
820 mStepDurations = new long[maxLevelSteps];
821 }
822
823 public LevelStepTracker(int numSteps, long[] steps) {
824 mNumStepDurations = numSteps;
825 mStepDurations = new long[numSteps];
826 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
827 }
828
829 public long getDurationAt(int index) {
830 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
831 }
832
833 public int getLevelAt(int index) {
834 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
835 >> STEP_LEVEL_LEVEL_SHIFT);
836 }
837
838 public int getInitModeAt(int index) {
839 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
840 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
841 }
842
843 public int getModModeAt(int index) {
844 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
845 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
846 }
847
848 private void appendHex(long val, int topOffset, StringBuilder out) {
849 boolean hasData = false;
850 while (topOffset >= 0) {
851 int digit = (int)( (val>>topOffset) & 0xf );
852 topOffset -= 4;
853 if (!hasData && digit == 0) {
854 continue;
855 }
856 hasData = true;
857 if (digit >= 0 && digit <= 9) {
858 out.append((char)('0' + digit));
859 } else {
860 out.append((char)('a' + digit - 10));
861 }
862 }
863 }
864
865 public void encodeEntryAt(int index, StringBuilder out) {
866 long item = mStepDurations[index];
867 long duration = item & STEP_LEVEL_TIME_MASK;
868 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
869 >> STEP_LEVEL_LEVEL_SHIFT);
870 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
871 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
872 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
873 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
874 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
875 case Display.STATE_OFF: out.append('f'); break;
876 case Display.STATE_ON: out.append('o'); break;
877 case Display.STATE_DOZE: out.append('d'); break;
878 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
879 }
880 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
881 out.append('p');
882 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700883 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
884 out.append('i');
885 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800886 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
887 case Display.STATE_OFF: out.append('F'); break;
888 case Display.STATE_ON: out.append('O'); break;
889 case Display.STATE_DOZE: out.append('D'); break;
890 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
891 }
892 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
893 out.append('P');
894 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700895 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
896 out.append('I');
897 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800898 out.append('-');
899 appendHex(level, 4, out);
900 out.append('-');
901 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
902 }
903
904 public void decodeEntryAt(int index, String value) {
905 final int N = value.length();
906 int i = 0;
907 char c;
908 long out = 0;
909 while (i < N && (c=value.charAt(i)) != '-') {
910 i++;
911 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800912 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800913 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800914 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800915 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800916 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800917 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800918 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
919 << STEP_LEVEL_INITIAL_MODE_SHIFT);
920 break;
921 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
922 << STEP_LEVEL_INITIAL_MODE_SHIFT);
923 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700924 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
925 << STEP_LEVEL_INITIAL_MODE_SHIFT);
926 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800927 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
928 break;
929 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
930 break;
931 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
932 break;
933 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
934 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
935 break;
936 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
937 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800938 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700939 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
940 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
941 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800942 }
943 }
944 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800945 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800946 while (i < N && (c=value.charAt(i)) != '-') {
947 i++;
948 level <<= 4;
949 if (c >= '0' && c <= '9') {
950 level += c - '0';
951 } else if (c >= 'a' && c <= 'f') {
952 level += c - 'a' + 10;
953 } else if (c >= 'A' && c <= 'F') {
954 level += c - 'A' + 10;
955 }
956 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800957 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800958 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
959 long duration = 0;
960 while (i < N && (c=value.charAt(i)) != '-') {
961 i++;
962 duration <<= 4;
963 if (c >= '0' && c <= '9') {
964 duration += c - '0';
965 } else if (c >= 'a' && c <= 'f') {
966 duration += c - 'a' + 10;
967 } else if (c >= 'A' && c <= 'F') {
968 duration += c - 'A' + 10;
969 }
970 }
971 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
972 }
973
974 public void init() {
975 mLastStepTime = -1;
976 mNumStepDurations = 0;
977 }
978
979 public void clearTime() {
980 mLastStepTime = -1;
981 }
982
983 public long computeTimePerLevel() {
984 final long[] steps = mStepDurations;
985 final int numSteps = mNumStepDurations;
986
987 // For now we'll do a simple average across all steps.
988 if (numSteps <= 0) {
989 return -1;
990 }
991 long total = 0;
992 for (int i=0; i<numSteps; i++) {
993 total += steps[i] & STEP_LEVEL_TIME_MASK;
994 }
995 return total / numSteps;
996 /*
997 long[] buckets = new long[numSteps];
998 int numBuckets = 0;
999 int numToAverage = 4;
1000 int i = 0;
1001 while (i < numSteps) {
1002 long totalTime = 0;
1003 int num = 0;
1004 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
1005 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
1006 num++;
1007 }
1008 buckets[numBuckets] = totalTime / num;
1009 numBuckets++;
1010 numToAverage *= 2;
1011 i += num;
1012 }
1013 if (numBuckets < 1) {
1014 return -1;
1015 }
1016 long averageTime = buckets[numBuckets-1];
1017 for (i=numBuckets-2; i>=0; i--) {
1018 averageTime = (averageTime + buckets[i]) / 2;
1019 }
1020 return averageTime;
1021 */
1022 }
1023
1024 public long computeTimeEstimate(long modesOfInterest, long modeValues,
1025 int[] outNumOfInterest) {
1026 final long[] steps = mStepDurations;
1027 final int count = mNumStepDurations;
1028 if (count <= 0) {
1029 return -1;
1030 }
1031 long total = 0;
1032 int numOfInterest = 0;
1033 for (int i=0; i<count; i++) {
1034 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
1035 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
1036 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
1037 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
1038 // If the modes of interest didn't change during this step period...
1039 if ((modMode&modesOfInterest) == 0) {
1040 // And the mode values during this period match those we are measuring...
1041 if ((initMode&modesOfInterest) == modeValues) {
1042 // Then this can be used to estimate the total time!
1043 numOfInterest++;
1044 total += steps[i] & STEP_LEVEL_TIME_MASK;
1045 }
1046 }
1047 }
1048 if (numOfInterest <= 0) {
1049 return -1;
1050 }
1051
1052 if (outNumOfInterest != null) {
1053 outNumOfInterest[0] = numOfInterest;
1054 }
1055
1056 // The estimated time is the average time we spend in each level, multipled
1057 // by 100 -- the total number of battery levels
1058 return (total / numOfInterest) * 100;
1059 }
1060
1061 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
1062 int stepCount = mNumStepDurations;
1063 final long lastStepTime = mLastStepTime;
1064 if (lastStepTime >= 0 && numStepLevels > 0) {
1065 final long[] steps = mStepDurations;
1066 long duration = elapsedRealtime - lastStepTime;
1067 for (int i=0; i<numStepLevels; i++) {
1068 System.arraycopy(steps, 0, steps, 1, steps.length-1);
1069 long thisDuration = duration / (numStepLevels-i);
1070 duration -= thisDuration;
1071 if (thisDuration > STEP_LEVEL_TIME_MASK) {
1072 thisDuration = STEP_LEVEL_TIME_MASK;
1073 }
1074 steps[0] = thisDuration | modeBits;
1075 }
1076 stepCount += numStepLevels;
1077 if (stepCount > steps.length) {
1078 stepCount = steps.length;
1079 }
1080 }
1081 mNumStepDurations = stepCount;
1082 mLastStepTime = elapsedRealtime;
1083 }
1084
1085 public void readFromParcel(Parcel in) {
1086 final int N = in.readInt();
Adam Lesinski9ae9cba2015-07-08 17:09:34 -07001087 if (N > mStepDurations.length) {
1088 throw new ParcelFormatException("more step durations than available: " + N);
1089 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001090 mNumStepDurations = N;
1091 for (int i=0; i<N; i++) {
1092 mStepDurations[i] = in.readLong();
1093 }
1094 }
1095
1096 public void writeToParcel(Parcel out) {
1097 final int N = mNumStepDurations;
1098 out.writeInt(N);
1099 for (int i=0; i<N; i++) {
1100 out.writeLong(mStepDurations[i]);
1101 }
1102 }
1103 }
1104
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001105 public static final class PackageChange {
1106 public String mPackageName;
1107 public boolean mUpdate;
1108 public int mVersionCode;
1109 }
1110
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001111 public static final class DailyItem {
1112 public long mStartTime;
1113 public long mEndTime;
1114 public LevelStepTracker mDischargeSteps;
1115 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001116 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08001117 }
1118
1119 public abstract DailyItem getDailyItemLocked(int daysAgo);
1120
1121 public abstract long getCurrentDailyStartTime();
1122
1123 public abstract long getNextMinDailyDeadline();
1124
1125 public abstract long getNextMaxDailyDeadline();
1126
Sudheer Shanka9b735c52017-05-09 18:26:18 -07001127 public abstract long[] getCpuFreqs();
1128
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001129 public final static class HistoryTag {
1130 public String string;
1131 public int uid;
1132
1133 public int poolIdx;
1134
1135 public void setTo(HistoryTag o) {
1136 string = o.string;
1137 uid = o.uid;
1138 poolIdx = o.poolIdx;
1139 }
1140
1141 public void setTo(String _string, int _uid) {
1142 string = _string;
1143 uid = _uid;
1144 poolIdx = -1;
1145 }
1146
1147 public void writeToParcel(Parcel dest, int flags) {
1148 dest.writeString(string);
1149 dest.writeInt(uid);
1150 }
1151
1152 public void readFromParcel(Parcel src) {
1153 string = src.readString();
1154 uid = src.readInt();
1155 poolIdx = -1;
1156 }
1157
1158 @Override
1159 public boolean equals(Object o) {
1160 if (this == o) return true;
1161 if (o == null || getClass() != o.getClass()) return false;
1162
1163 HistoryTag that = (HistoryTag) o;
1164
1165 if (uid != that.uid) return false;
1166 if (!string.equals(that.string)) return false;
1167
1168 return true;
1169 }
1170
1171 @Override
1172 public int hashCode() {
1173 int result = string.hashCode();
1174 result = 31 * result + uid;
1175 return result;
1176 }
1177 }
1178
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001179 /**
1180 * Optional detailed information that can go into a history step. This is typically
1181 * generated each time the battery level changes.
1182 */
1183 public final static class HistoryStepDetails {
1184 // Time (in 1/100 second) spent in user space and the kernel since the last step.
1185 public int userTime;
1186 public int systemTime;
1187
1188 // Top three apps using CPU in the last step, with times in 1/100 second.
1189 public int appCpuUid1;
1190 public int appCpuUTime1;
1191 public int appCpuSTime1;
1192 public int appCpuUid2;
1193 public int appCpuUTime2;
1194 public int appCpuSTime2;
1195 public int appCpuUid3;
1196 public int appCpuUTime3;
1197 public int appCpuSTime3;
1198
1199 // Information from /proc/stat
1200 public int statUserTime;
1201 public int statSystemTime;
1202 public int statIOWaitTime;
1203 public int statIrqTime;
1204 public int statSoftIrqTime;
1205 public int statIdlTime;
1206
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001207 // Platform-level low power state stats
1208 public String statPlatformIdleState;
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001209 public String statSubsystemPowerState;
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001210
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);
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001241 out.writeString(statSubsystemPowerState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001242 }
1243
1244 public void readFromParcel(Parcel in) {
1245 userTime = in.readInt();
1246 systemTime = in.readInt();
1247 appCpuUid1 = in.readInt();
1248 appCpuUTime1 = in.readInt();
1249 appCpuSTime1 = in.readInt();
1250 appCpuUid2 = in.readInt();
1251 appCpuUTime2 = in.readInt();
1252 appCpuSTime2 = in.readInt();
1253 appCpuUid3 = in.readInt();
1254 appCpuUTime3 = in.readInt();
1255 appCpuSTime3 = in.readInt();
1256 statUserTime = in.readInt();
1257 statSystemTime = in.readInt();
1258 statIOWaitTime = in.readInt();
1259 statIrqTime = in.readInt();
1260 statSoftIrqTime = in.readInt();
1261 statIdlTime = in.readInt();
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07001262 statPlatformIdleState = in.readString();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00001263 statSubsystemPowerState = in.readString();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001264 }
1265 }
1266
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001267 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001268 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001269
1270 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001271 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001272
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001273 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001274 public static final byte CMD_NULL = -1;
1275 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001276 public static final byte CMD_CURRENT_TIME = 5;
1277 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001278 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001279 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001280
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001281 public byte cmd = CMD_NULL;
Bookatzc8c44962017-05-11 12:12:54 -07001282
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001283 /**
1284 * Return whether the command code is a delta data update.
1285 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001286 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001287 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001288 }
1289
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001290 public byte batteryLevel;
1291 public byte batteryStatus;
1292 public byte batteryHealth;
1293 public byte batteryPlugType;
Bookatzc8c44962017-05-11 12:12:54 -07001294
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001295 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001296 public char batteryVoltage;
Adam Lesinski926969b2016-04-28 17:31:12 -07001297
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001298 // The charge of the battery in micro-Ampere-hours.
1299 public int batteryChargeUAh;
Bookatzc8c44962017-05-11 12:12:54 -07001300
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001301 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001302 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001303 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001304 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001305 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1306 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001307 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001308 public static final int STATE_PHONE_STATE_SHIFT = 6;
1309 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001310 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001311 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001312 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001313
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001314 // These states always appear directly in the first int token
1315 // of a delta change; they should be ones that change relatively
1316 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001317 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1318 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001319 public static final int STATE_GPS_ON_FLAG = 1<<29;
1320 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001321 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001322 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001323 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Adam Lesinski926969b2016-04-28 17:31:12 -07001324 // Do not use, this is used for coulomb delta count.
1325 private static final int STATE_RESERVED_0 = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001326 // These are on the lower bits used for the command; if they change
1327 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001328 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001329 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001330 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001331 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1332 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1333 // empty slot
1334 // empty slot
1335 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001336
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001337 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001338 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1339
1340 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001341
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001342 public int states;
1343
Dianne Hackborn3251b902014-06-20 14:40:53 -07001344 // Constants from WIFI_SUPPL_STATE_*
1345 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1346 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1347 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1348 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1349 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1350 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1351
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001352 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001353 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1354 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1355 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001356 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001357 public static final int STATE2_DEVICE_IDLE_SHIFT = 25;
1358 public static final int STATE2_DEVICE_IDLE_MASK = 0x3 << STATE2_DEVICE_IDLE_SHIFT;
1359 public static final int STATE2_CHARGING_FLAG = 1<<24;
1360 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<23;
1361 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<22;
1362 public static final int STATE2_CAMERA_FLAG = 1<<21;
Adam Lesinski9f55cc72016-01-27 20:42:14 -08001363 public static final int STATE2_BLUETOOTH_SCAN_FLAG = 1 << 20;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001364
1365 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001366 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_MASK
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001367 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1368
1369 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001370
Dianne Hackborn40c87252014-03-19 16:55:40 -07001371 public int states2;
1372
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001373 // The wake lock that was acquired at this point.
1374 public HistoryTag wakelockTag;
1375
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001376 // Kernel wakeup reason at this point.
1377 public HistoryTag wakeReasonTag;
1378
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001379 // Non-null when there is more detailed information at this step.
1380 public HistoryStepDetails stepDetails;
1381
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001382 public static final int EVENT_FLAG_START = 0x8000;
1383 public static final int EVENT_FLAG_FINISH = 0x4000;
1384
1385 // No event in this item.
1386 public static final int EVENT_NONE = 0x0000;
1387 // Event is about a process that is running.
1388 public static final int EVENT_PROC = 0x0001;
1389 // Event is about an application package that is in the foreground.
1390 public static final int EVENT_FOREGROUND = 0x0002;
1391 // Event is about an application package that is at the top of the screen.
1392 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001393 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001394 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001395 // Events for all additional wake locks aquired/release within a wake block.
1396 // These are not generated by default.
1397 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001398 // Event is about an application executing a scheduled job.
1399 public static final int EVENT_JOB = 0x0006;
1400 // Events for users running.
1401 public static final int EVENT_USER_RUNNING = 0x0007;
1402 // Events for foreground user.
1403 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001404 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001405 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001406 // Event for becoming active taking us out of idle mode.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001407 public static final int EVENT_ACTIVE = 0x000a;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001408 // Event for a package being installed.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001409 public static final int EVENT_PACKAGE_INSTALLED = 0x000b;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001410 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001411 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000c;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001412 // Event for a package being uninstalled.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001413 public static final int EVENT_ALARM = 0x000d;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001414 // Record that we have decided we need to collect new stats data.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001415 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000e;
Amith Yamasani67768492015-06-09 12:23:58 -07001416 // Event for a package becoming inactive due to being unused for a period of time.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001417 public static final int EVENT_PACKAGE_INACTIVE = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001418 // Event for a package becoming active due to an interaction.
Dianne Hackbornb6683c42015-06-18 17:40:33 -07001419 public static final int EVENT_PACKAGE_ACTIVE = 0x0010;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001420 // Event for a package being on the temporary whitelist.
1421 public static final int EVENT_TEMP_WHITELIST = 0x0011;
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001422 // Event for the screen waking up.
1423 public static final int EVENT_SCREEN_WAKE_UP = 0x0012;
Adam Lesinski5f056f62016-07-14 16:56:08 -07001424 // Event for the UID that woke up the application processor.
1425 // Used for wakeups coming from WiFi, modem, etc.
1426 public static final int EVENT_WAKEUP_AP = 0x0013;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001427 // Event for reporting that a specific partial wake lock has been held for a long duration.
1428 public static final int EVENT_LONG_WAKE_LOCK = 0x0014;
Amith Yamasani67768492015-06-09 12:23:58 -07001429
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001430 // Number of event types.
Adam Lesinski041d9172016-12-12 12:03:56 -08001431 public static final int EVENT_COUNT = 0x0016;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001432 // Mask to extract out only the type part of the event.
1433 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001434
1435 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1436 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1437 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1438 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1439 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1440 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001441 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1442 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001443 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1444 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001445 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1446 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1447 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1448 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1449 public static final int EVENT_USER_FOREGROUND_START =
1450 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1451 public static final int EVENT_USER_FOREGROUND_FINISH =
1452 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001453 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1454 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07001455 public static final int EVENT_TEMP_WHITELIST_START =
1456 EVENT_TEMP_WHITELIST | EVENT_FLAG_START;
1457 public static final int EVENT_TEMP_WHITELIST_FINISH =
1458 EVENT_TEMP_WHITELIST | EVENT_FLAG_FINISH;
Dianne Hackbornd0db6f02016-07-18 14:14:20 -07001459 public static final int EVENT_LONG_WAKE_LOCK_START =
1460 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_START;
1461 public static final int EVENT_LONG_WAKE_LOCK_FINISH =
1462 EVENT_LONG_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001463
1464 // For CMD_EVENT.
1465 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001466 public HistoryTag eventTag;
1467
Dianne Hackborn9a755432014-05-15 17:05:22 -07001468 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001469 public long currentTime;
1470
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001471 // Meta-data when reading.
1472 public int numReadInts;
1473
1474 // Pre-allocated objects.
1475 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001476 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001477 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001478
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001479 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001480 }
Bookatzc8c44962017-05-11 12:12:54 -07001481
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001482 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001483 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001484 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001485 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001486 }
Bookatzc8c44962017-05-11 12:12:54 -07001487
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001488 public int describeContents() {
1489 return 0;
1490 }
1491
1492 public void writeToParcel(Parcel dest, int flags) {
1493 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001494 int bat = (((int)cmd)&0xff)
1495 | ((((int)batteryLevel)<<8)&0xff00)
1496 | ((((int)batteryStatus)<<16)&0xf0000)
1497 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001498 | ((((int)batteryPlugType)<<24)&0xf000000)
1499 | (wakelockTag != null ? 0x10000000 : 0)
1500 | (wakeReasonTag != null ? 0x20000000 : 0)
1501 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001502 dest.writeInt(bat);
1503 bat = (((int)batteryTemperature)&0xffff)
1504 | ((((int)batteryVoltage)<<16)&0xffff0000);
1505 dest.writeInt(bat);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001506 dest.writeInt(batteryChargeUAh);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001507 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001508 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001509 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001510 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001511 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001512 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001513 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001514 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001515 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001516 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001517 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001518 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001519 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001520 dest.writeLong(currentTime);
1521 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001522 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001523
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001524 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001525 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001526 int bat = src.readInt();
1527 cmd = (byte)(bat&0xff);
1528 batteryLevel = (byte)((bat>>8)&0xff);
1529 batteryStatus = (byte)((bat>>16)&0xf);
1530 batteryHealth = (byte)((bat>>20)&0xf);
1531 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001532 int bat2 = src.readInt();
1533 batteryTemperature = (short)(bat2&0xffff);
1534 batteryVoltage = (char)((bat2>>16)&0xffff);
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001535 batteryChargeUAh = src.readInt();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001536 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001537 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001538 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001539 wakelockTag = localWakelockTag;
1540 wakelockTag.readFromParcel(src);
1541 } else {
1542 wakelockTag = null;
1543 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001544 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001545 wakeReasonTag = localWakeReasonTag;
1546 wakeReasonTag.readFromParcel(src);
1547 } else {
1548 wakeReasonTag = null;
1549 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001550 if ((bat&0x40000000) != 0) {
1551 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001552 eventTag = localEventTag;
1553 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001554 } else {
1555 eventCode = EVENT_NONE;
1556 eventTag = null;
1557 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001558 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001559 currentTime = src.readLong();
1560 } else {
1561 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001562 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001563 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001564 }
1565
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001566 public void clear() {
1567 time = 0;
1568 cmd = CMD_NULL;
1569 batteryLevel = 0;
1570 batteryStatus = 0;
1571 batteryHealth = 0;
1572 batteryPlugType = 0;
1573 batteryTemperature = 0;
1574 batteryVoltage = 0;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001575 batteryChargeUAh = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001576 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001577 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001578 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001579 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001580 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001581 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001582 }
Bookatzc8c44962017-05-11 12:12:54 -07001583
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001584 public void setTo(HistoryItem o) {
1585 time = o.time;
1586 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001587 setToCommon(o);
1588 }
1589
1590 public void setTo(long time, byte cmd, HistoryItem o) {
1591 this.time = time;
1592 this.cmd = cmd;
1593 setToCommon(o);
1594 }
1595
1596 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001597 batteryLevel = o.batteryLevel;
1598 batteryStatus = o.batteryStatus;
1599 batteryHealth = o.batteryHealth;
1600 batteryPlugType = o.batteryPlugType;
1601 batteryTemperature = o.batteryTemperature;
1602 batteryVoltage = o.batteryVoltage;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001603 batteryChargeUAh = o.batteryChargeUAh;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001604 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001605 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001606 if (o.wakelockTag != null) {
1607 wakelockTag = localWakelockTag;
1608 wakelockTag.setTo(o.wakelockTag);
1609 } else {
1610 wakelockTag = null;
1611 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001612 if (o.wakeReasonTag != null) {
1613 wakeReasonTag = localWakeReasonTag;
1614 wakeReasonTag.setTo(o.wakeReasonTag);
1615 } else {
1616 wakeReasonTag = null;
1617 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001618 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001619 if (o.eventTag != null) {
1620 eventTag = localEventTag;
1621 eventTag.setTo(o.eventTag);
1622 } else {
1623 eventTag = null;
1624 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001625 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001626 }
1627
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001628 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001629 return batteryLevel == o.batteryLevel
1630 && batteryStatus == o.batteryStatus
1631 && batteryHealth == o.batteryHealth
1632 && batteryPlugType == o.batteryPlugType
1633 && batteryTemperature == o.batteryTemperature
1634 && batteryVoltage == o.batteryVoltage
Adam Lesinskia8018ac2016-05-03 10:18:10 -07001635 && batteryChargeUAh == o.batteryChargeUAh
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001636 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001637 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001638 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001639 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001640
1641 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001642 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001643 return false;
1644 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001645 if (wakelockTag != o.wakelockTag) {
1646 if (wakelockTag == null || o.wakelockTag == null) {
1647 return false;
1648 }
1649 if (!wakelockTag.equals(o.wakelockTag)) {
1650 return false;
1651 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001652 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001653 if (wakeReasonTag != o.wakeReasonTag) {
1654 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1655 return false;
1656 }
1657 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1658 return false;
1659 }
1660 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001661 if (eventTag != o.eventTag) {
1662 if (eventTag == null || o.eventTag == null) {
1663 return false;
1664 }
1665 if (!eventTag.equals(o.eventTag)) {
1666 return false;
1667 }
1668 }
1669 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001670 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001671 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001672
1673 public final static class HistoryEventTracker {
1674 private final HashMap<String, SparseIntArray>[] mActiveEvents
1675 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1676
1677 public boolean updateState(int code, String name, int uid, int poolIdx) {
1678 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1679 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1680 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1681 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001682 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001683 mActiveEvents[idx] = active;
1684 }
1685 SparseIntArray uids = active.get(name);
1686 if (uids == null) {
1687 uids = new SparseIntArray();
1688 active.put(name, uids);
1689 }
1690 if (uids.indexOfKey(uid) >= 0) {
1691 // Already set, nothing to do!
1692 return false;
1693 }
1694 uids.put(uid, poolIdx);
1695 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1696 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1697 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1698 if (active == null) {
1699 // not currently active, nothing to do.
1700 return false;
1701 }
1702 SparseIntArray uids = active.get(name);
1703 if (uids == null) {
1704 // not currently active, nothing to do.
1705 return false;
1706 }
1707 idx = uids.indexOfKey(uid);
1708 if (idx < 0) {
1709 // not currently active, nothing to do.
1710 return false;
1711 }
1712 uids.removeAt(idx);
1713 if (uids.size() <= 0) {
1714 active.remove(name);
1715 }
1716 }
1717 return true;
1718 }
1719
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001720 public void removeEvents(int code) {
1721 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1722 mActiveEvents[idx] = null;
1723 }
1724
Dianne Hackborn37de0982014-05-09 09:32:18 -07001725 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1726 return mActiveEvents[code];
1727 }
1728 }
1729
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001730 public static final class BitDescription {
1731 public final int mask;
1732 public final int shift;
1733 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001734 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001735 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001736 public final String[] shortValues;
Bookatzc8c44962017-05-11 12:12:54 -07001737
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001738 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001739 this.mask = mask;
1740 this.shift = -1;
1741 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001742 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001743 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001744 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001745 }
Bookatzc8c44962017-05-11 12:12:54 -07001746
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001747 public BitDescription(int mask, int shift, String name, String shortName,
1748 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001749 this.mask = mask;
1750 this.shift = shift;
1751 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001752 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001753 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001754 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001755 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001756 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001757
Dianne Hackbornfc064132014-06-02 12:42:12 -07001758 /**
1759 * Don't allow any more batching in to the current history event. This
1760 * is called when printing partial histories, so to ensure that the next
1761 * history event will go in to a new batch after what was printed in the
1762 * last partial history.
1763 */
1764 public abstract void commitCurrentHistoryBatchLocked();
1765
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001766 public abstract int getHistoryTotalSize();
1767
1768 public abstract int getHistoryUsedSize();
1769
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001770 public abstract boolean startIteratingHistoryLocked();
1771
Dianne Hackborn099bc622014-01-22 13:39:16 -08001772 public abstract int getHistoryStringPoolSize();
1773
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001774 public abstract int getHistoryStringPoolBytes();
1775
1776 public abstract String getHistoryTagPoolString(int index);
1777
1778 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001779
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001780 public abstract boolean getNextHistoryLocked(HistoryItem out);
1781
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001782 public abstract void finishIteratingHistoryLocked();
1783
1784 public abstract boolean startIteratingOldHistoryLocked();
1785
1786 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1787
1788 public abstract void finishIteratingOldHistoryLocked();
1789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001791 * Return the base time offset for the battery history.
1792 */
1793 public abstract long getHistoryBaseTime();
Bookatzc8c44962017-05-11 12:12:54 -07001794
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001795 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 * Returns the number of times the device has been started.
1797 */
1798 public abstract int getStartCount();
Bookatzc8c44962017-05-11 12:12:54 -07001799
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001801 * 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 -08001802 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001803 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001804 * {@hide}
1805 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001806 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001807
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001808 /**
1809 * Returns the number of times the screen was turned on.
1810 *
1811 * {@hide}
1812 */
1813 public abstract int getScreenOnCount(int which);
1814
Jeff Browne95c3cd2014-05-02 16:59:26 -07001815 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1816
Dianne Hackborn617f8772009-03-31 15:04:46 -07001817 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1818 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1819 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1820 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1821 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
Bookatzc8c44962017-05-11 12:12:54 -07001822
Dianne Hackborn617f8772009-03-31 15:04:46 -07001823 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1824 "dark", "dim", "medium", "light", "bright"
1825 };
Bookatzc8c44962017-05-11 12:12:54 -07001826
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001827 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1828 "0", "1", "2", "3", "4"
1829 };
1830
Dianne Hackborn617f8772009-03-31 15:04:46 -07001831 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001832
Dianne Hackborn617f8772009-03-31 15:04:46 -07001833 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001834 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001835 * the given brightness
Bookatzc8c44962017-05-11 12:12:54 -07001836 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001837 * {@hide}
1838 */
1839 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001840 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001841
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001842 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001843 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001844 * running on battery.
1845 *
1846 * {@hide}
1847 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001848 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001849
1850 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001851 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001852 *
1853 * {@hide}
1854 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001855 public abstract int getPowerSaveModeEnabledCount(int which);
1856
1857 /**
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001858 * Constant for device idle mode: not active.
1859 */
1860 public static final int DEVICE_IDLE_MODE_OFF = 0;
1861
1862 /**
1863 * Constant for device idle mode: active in lightweight mode.
1864 */
1865 public static final int DEVICE_IDLE_MODE_LIGHT = 1;
1866
1867 /**
1868 * Constant for device idle mode: active in full mode.
1869 */
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07001870 public static final int DEVICE_IDLE_MODE_DEEP = 2;
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001871
1872 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001873 * Returns the time in microseconds that device has been in idle mode while
1874 * running on battery.
1875 *
1876 * {@hide}
1877 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001878 public abstract long getDeviceIdleModeTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001879
1880 /**
1881 * Returns the number of times that the devie has gone in to idle mode.
1882 *
1883 * {@hide}
1884 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001885 public abstract int getDeviceIdleModeCount(int mode, int which);
1886
1887 /**
1888 * Return the longest duration we spent in a particular device idle mode (fully in the
1889 * mode, not in idle maintenance etc).
1890 */
1891 public abstract long getLongestDeviceIdleModeTime(int mode);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001892
1893 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001894 * Returns the time in microseconds that device has been in idling while on
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001895 * battery. This is broader than {@link #getDeviceIdleModeTime} -- it
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001896 * counts all of the time that we consider the device to be idle, whether or not
1897 * it is currently in the actual device idle mode.
1898 *
1899 * {@hide}
1900 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001901 public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001902
1903 /**
1904 * Returns the number of times that the devie has started idling.
1905 *
1906 * {@hide}
1907 */
Dianne Hackborn08c47a52015-10-15 12:38:14 -07001908 public abstract int getDeviceIdlingCount(int mode, int which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001909
1910 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001911 * Returns the number of times that connectivity state changed.
1912 *
1913 * {@hide}
1914 */
1915 public abstract int getNumConnectivityChange(int which);
1916
1917 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001918 * 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 -08001919 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07001920 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 * {@hide}
1922 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001923 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Bookatzc8c44962017-05-11 12:12:54 -07001924
Dianne Hackborn627bba72009-03-24 22:32:56 -07001925 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001926 * Returns the number of times a phone call was activated.
1927 *
1928 * {@hide}
1929 */
1930 public abstract int getPhoneOnCount(int which);
1931
1932 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001933 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001934 * the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001935 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07001936 * {@hide}
1937 */
1938 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001939 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001940
Dianne Hackborn617f8772009-03-31 15:04:46 -07001941 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001942 * Returns the time in microseconds that the phone has been trying to
1943 * acquire a signal.
1944 *
1945 * {@hide}
1946 */
1947 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001948 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001949
1950 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001951 * Returns the number of times the phone has entered the given signal strength.
Bookatzc8c44962017-05-11 12:12:54 -07001952 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07001953 * {@hide}
1954 */
1955 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1956
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001957 /**
1958 * Returns the time in microseconds that the mobile network has been active
1959 * (in a high power state).
1960 *
1961 * {@hide}
1962 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001963 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001964
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001965 /**
1966 * Returns the number of times that the mobile network has transitioned to the
1967 * active state.
1968 *
1969 * {@hide}
1970 */
1971 public abstract int getMobileRadioActiveCount(int which);
1972
1973 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001974 * Returns the time in microseconds that is the difference between the mobile radio
1975 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1976 * from the radio.
1977 *
1978 * {@hide}
1979 */
1980 public abstract long getMobileRadioActiveAdjustedTime(int which);
1981
1982 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001983 * Returns the time in microseconds that the mobile network has been active
1984 * (in a high power state) but not being able to blame on an app.
1985 *
1986 * {@hide}
1987 */
1988 public abstract long getMobileRadioActiveUnknownTime(int which);
1989
1990 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001991 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001992 *
1993 * {@hide}
1994 */
1995 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001996
Dianne Hackborn627bba72009-03-24 22:32:56 -07001997 public static final int DATA_CONNECTION_NONE = 0;
1998 public static final int DATA_CONNECTION_GPRS = 1;
1999 public static final int DATA_CONNECTION_EDGE = 2;
2000 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002001 public static final int DATA_CONNECTION_CDMA = 4;
2002 public static final int DATA_CONNECTION_EVDO_0 = 5;
2003 public static final int DATA_CONNECTION_EVDO_A = 6;
2004 public static final int DATA_CONNECTION_1xRTT = 7;
2005 public static final int DATA_CONNECTION_HSDPA = 8;
2006 public static final int DATA_CONNECTION_HSUPA = 9;
2007 public static final int DATA_CONNECTION_HSPA = 10;
2008 public static final int DATA_CONNECTION_IDEN = 11;
2009 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002010 public static final int DATA_CONNECTION_LTE = 13;
2011 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08002012 public static final int DATA_CONNECTION_HSPAP = 15;
2013 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07002014
Dianne Hackborn627bba72009-03-24 22:32:56 -07002015 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002016 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07002017 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08002018 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07002019 };
Bookatzc8c44962017-05-11 12:12:54 -07002020
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002021 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Bookatzc8c44962017-05-11 12:12:54 -07002022
Dianne Hackborn627bba72009-03-24 22:32:56 -07002023 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002024 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07002025 * the given data connection.
Bookatzc8c44962017-05-11 12:12:54 -07002026 *
Dianne Hackborn627bba72009-03-24 22:32:56 -07002027 * {@hide}
2028 */
2029 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002030 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07002033 * Returns the number of times the phone has entered the given data
2034 * connection type.
Bookatzc8c44962017-05-11 12:12:54 -07002035 *
Dianne Hackborn617f8772009-03-31 15:04:46 -07002036 * {@hide}
2037 */
2038 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002039
Dianne Hackborn3251b902014-06-20 14:40:53 -07002040 public static final int WIFI_SUPPL_STATE_INVALID = 0;
2041 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
2042 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
2043 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
2044 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
2045 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
2046 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
2047 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
2048 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
2049 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
2050 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
2051 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
2052 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
2053
2054 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
2055
2056 static final String[] WIFI_SUPPL_STATE_NAMES = {
2057 "invalid", "disconn", "disabled", "inactive", "scanning",
2058 "authenticating", "associating", "associated", "4-way-handshake",
2059 "group-handshake", "completed", "dormant", "uninit"
2060 };
2061
2062 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
2063 "inv", "dsc", "dis", "inact", "scan",
2064 "auth", "ascing", "asced", "4-way",
2065 "group", "compl", "dorm", "uninit"
2066 };
2067
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002068 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
2069 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002070 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002071 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
2072 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002073 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002074 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
2075 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
2076 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002077 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002078 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002079 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002080 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002081 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
2082 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002083 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
2084 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
2085 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
2086 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
2087 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
2088 new String[] {"in", "out", "emergency", "off"},
2089 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002090 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
2091 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
2092 SignalStrength.SIGNAL_STRENGTH_NAMES,
2093 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08002094 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
2095 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
2096 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002097 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07002098
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002099 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
2100 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002101 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002102 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002103 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002104 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002105 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07002106 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_MASK,
2107 HistoryItem.STATE2_DEVICE_IDLE_SHIFT, "device_idle", "di",
2108 new String[] { "off", "light", "full", "???" },
2109 new String[] { "off", "light", "full", "???" }),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07002110 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
2111 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
2112 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07002113 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
2114 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
2115 new String[] { "0", "1", "2", "3", "4" },
2116 new String[] { "0", "1", "2", "3", "4" }),
2117 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
2118 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
2119 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002120 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002121 new BitDescription(HistoryItem.STATE2_BLUETOOTH_SCAN_FLAG, "ble_scan", "bles"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002122 };
2123
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002124 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002125 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Kweku Adams134c59b2017-03-08 16:48:01 -08002126 "active", "pkginst", "pkgunin", "alarm", "stats", "pkginactive", "pkgactive",
2127 "tmpwhitelist", "screenwake", "wakeupap", "longwake", "est_capacity"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002128 };
2129
2130 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002131 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Dianne Hackborn280a64e2015-07-13 14:48:08 -07002132 "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw",
Adam Lesinski041d9172016-12-12 12:03:56 -08002133 "Esw", "Ewa", "Elw", "Eec"
2134 };
2135
2136 @FunctionalInterface
2137 public interface IntToString {
2138 String applyAsString(int val);
2139 }
2140
2141 private static final IntToString sUidToString = UserHandle::formatUid;
2142 private static final IntToString sIntToString = Integer::toString;
2143
2144 public static final IntToString[] HISTORY_EVENT_INT_FORMATTERS = new IntToString[] {
2145 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2146 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2147 sUidToString, sUidToString, sUidToString, sUidToString, sUidToString, sUidToString,
2148 sUidToString, sUidToString, sUidToString, sIntToString
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08002149 };
2150
Dianne Hackborn617f8772009-03-31 15:04:46 -07002151 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002152 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07002153 * running on battery.
Bookatzc8c44962017-05-11 12:12:54 -07002154 *
The Android Open Source Project10592532009-03-18 17:39:46 -07002155 * {@hide}
2156 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002157 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002158
2159 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07002160 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002161 * been in the running state while the device was running on battery.
2162 *
2163 * {@hide}
2164 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002165 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002166
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002167 public static final int WIFI_STATE_OFF = 0;
2168 public static final int WIFI_STATE_OFF_SCANNING = 1;
2169 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
2170 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
2171 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
2172 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
2173 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
2174 public static final int WIFI_STATE_SOFT_AP = 7;
2175
2176 static final String[] WIFI_STATE_NAMES = {
2177 "off", "scanning", "no_net", "disconn",
2178 "sta", "p2p", "sta_p2p", "soft_ap"
2179 };
2180
2181 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
2182
2183 /**
2184 * Returns the time in microseconds that WiFi has been running in the given state.
2185 *
2186 * {@hide}
2187 */
2188 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002189 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002190
2191 /**
2192 * Returns the number of times that WiFi has entered the given state.
2193 *
2194 * {@hide}
2195 */
2196 public abstract int getWifiStateCount(int wifiState, int which);
2197
The Android Open Source Project10592532009-03-18 17:39:46 -07002198 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07002199 * Returns the time in microseconds that the wifi supplicant has been
2200 * in a given state.
2201 *
2202 * {@hide}
2203 */
2204 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
2205
2206 /**
2207 * Returns the number of times that the wifi supplicant has transitioned
2208 * to a given state.
2209 *
2210 * {@hide}
2211 */
2212 public abstract int getWifiSupplStateCount(int state, int which);
2213
2214 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
2215
2216 /**
2217 * Returns the time in microseconds that WIFI has been running with
2218 * the given signal strength.
2219 *
2220 * {@hide}
2221 */
2222 public abstract long getWifiSignalStrengthTime(int strengthBin,
2223 long elapsedRealtimeUs, int which);
2224
2225 /**
2226 * Returns the number of times WIFI has entered the given signal strength.
2227 *
2228 * {@hide}
2229 */
2230 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
2231
2232 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002233 * Returns the time in microseconds that the flashlight has been on while the device was
2234 * running on battery.
2235 *
2236 * {@hide}
2237 */
2238 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
2239
2240 /**
2241 * Returns the number of times that the flashlight has been turned on while the device was
2242 * running on battery.
2243 *
2244 * {@hide}
2245 */
2246 public abstract long getFlashlightOnCount(int which);
2247
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002248 /**
2249 * Returns the time in microseconds that the camera has been on while the device was
2250 * running on battery.
2251 *
2252 * {@hide}
2253 */
2254 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
2255
Adam Lesinski9f55cc72016-01-27 20:42:14 -08002256 /**
2257 * Returns the time in microseconds that bluetooth scans were running while the device was
2258 * on battery.
2259 *
2260 * {@hide}
2261 */
2262 public abstract long getBluetoothScanTime(long elapsedRealtimeUs, int which);
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002263
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002264 public static final int NETWORK_MOBILE_RX_DATA = 0;
2265 public static final int NETWORK_MOBILE_TX_DATA = 1;
2266 public static final int NETWORK_WIFI_RX_DATA = 2;
2267 public static final int NETWORK_WIFI_TX_DATA = 3;
Adam Lesinski50e47602015-12-04 17:04:54 -08002268 public static final int NETWORK_BT_RX_DATA = 4;
2269 public static final int NETWORK_BT_TX_DATA = 5;
Amith Yamasani59fe8412017-03-03 16:28:52 -08002270 public static final int NETWORK_MOBILE_BG_RX_DATA = 6;
2271 public static final int NETWORK_MOBILE_BG_TX_DATA = 7;
2272 public static final int NETWORK_WIFI_BG_RX_DATA = 8;
2273 public static final int NETWORK_WIFI_BG_TX_DATA = 9;
2274 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_BG_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002275
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002276 public abstract long getNetworkActivityBytes(int type, int which);
2277 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002278
Adam Lesinskie08af192015-03-25 16:42:59 -07002279 /**
Adam Lesinski17390762015-04-10 13:17:47 -07002280 * Returns true if the BatteryStats object has detailed WiFi power reports.
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002281 * When true, calling {@link #getWifiControllerActivity()} will yield the
Adam Lesinski17390762015-04-10 13:17:47 -07002282 * actual power data.
2283 */
2284 public abstract boolean hasWifiActivityReporting();
2285
2286 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002287 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2288 * in various radio controller states, such as transmit, receive, and idle.
2289 * @return non-null {@link ControllerActivityCounter}
Adam Lesinskie08af192015-03-25 16:42:59 -07002290 */
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002291 public abstract ControllerActivityCounter getWifiControllerActivity();
2292
2293 /**
2294 * Returns true if the BatteryStats object has detailed bluetooth power reports.
2295 * When true, calling {@link #getBluetoothControllerActivity()} will yield the
2296 * actual power data.
2297 */
2298 public abstract boolean hasBluetoothActivityReporting();
2299
2300 /**
2301 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2302 * in various radio controller states, such as transmit, receive, and idle.
2303 * @return non-null {@link ControllerActivityCounter}
2304 */
2305 public abstract ControllerActivityCounter getBluetoothControllerActivity();
2306
2307 /**
2308 * Returns true if the BatteryStats object has detailed modem power reports.
2309 * When true, calling {@link #getModemControllerActivity()} will yield the
2310 * actual power data.
2311 */
2312 public abstract boolean hasModemActivityReporting();
2313
2314 /**
2315 * Returns a {@link ControllerActivityCounter} which is an aggregate of the times spent
2316 * in various radio controller states, such as transmit, receive, and idle.
2317 * @return non-null {@link ControllerActivityCounter}
2318 */
2319 public abstract ControllerActivityCounter getModemControllerActivity();
Adam Lesinski33dac552015-03-09 15:24:48 -07002320
The Android Open Source Project10592532009-03-18 17:39:46 -07002321 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002322 * Return the wall clock time when battery stats data collection started.
2323 */
2324 public abstract long getStartClockTime();
2325
2326 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002327 * Return platform version tag that we were running in when the battery stats started.
2328 */
2329 public abstract String getStartPlatformVersion();
2330
2331 /**
2332 * Return platform version tag that we were running in when the battery stats ended.
2333 */
2334 public abstract String getEndPlatformVersion();
2335
2336 /**
2337 * Return the internal version code of the parcelled format.
2338 */
2339 public abstract int getParcelVersion();
2340
2341 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 * Return whether we are currently running on battery.
2343 */
2344 public abstract boolean getIsOnBattery();
Bookatzc8c44962017-05-11 12:12:54 -07002345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346 /**
2347 * Returns a SparseArray containing the statistics for each uid.
2348 */
2349 public abstract SparseArray<? extends Uid> getUidStats();
2350
2351 /**
2352 * Returns the current battery uptime in microseconds.
2353 *
2354 * @param curTime the amount of elapsed realtime in microseconds.
2355 */
2356 public abstract long getBatteryUptime(long curTime);
2357
2358 /**
2359 * Returns the current battery realtime in microseconds.
2360 *
2361 * @param curTime the amount of elapsed realtime in microseconds.
2362 */
2363 public abstract long getBatteryRealtime(long curTime);
Bookatzc8c44962017-05-11 12:12:54 -07002364
The Android Open Source Project10592532009-03-18 17:39:46 -07002365 /**
Evan Millar633a1742009-04-02 16:36:33 -07002366 * Returns the battery percentage level at the last time the device was unplugged from power, or
Bookatzc8c44962017-05-11 12:12:54 -07002367 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002368 */
Evan Millar633a1742009-04-02 16:36:33 -07002369 public abstract int getDischargeStartLevel();
Bookatzc8c44962017-05-11 12:12:54 -07002370
The Android Open Source Project10592532009-03-18 17:39:46 -07002371 /**
Evan Millar633a1742009-04-02 16:36:33 -07002372 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2373 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002374 */
Evan Millar633a1742009-04-02 16:36:33 -07002375 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376
2377 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002378 * Get the amount the battery has discharged since the stats were
2379 * last reset after charging, as a lower-end approximation.
2380 */
2381 public abstract int getLowDischargeAmountSinceCharge();
2382
2383 /**
2384 * Get the amount the battery has discharged since the stats were
2385 * last reset after charging, as an upper-end approximation.
2386 */
2387 public abstract int getHighDischargeAmountSinceCharge();
2388
2389 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002390 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2391 */
2392 public abstract int getDischargeAmount(int which);
2393
2394 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002395 * Get the amount the battery has discharged while the screen was on,
2396 * since the last time power was unplugged.
2397 */
2398 public abstract int getDischargeAmountScreenOn();
2399
2400 /**
2401 * Get the amount the battery has discharged while the screen was on,
2402 * since the last time the device was charged.
2403 */
2404 public abstract int getDischargeAmountScreenOnSinceCharge();
2405
2406 /**
2407 * Get the amount the battery has discharged while the screen was off,
2408 * since the last time power was unplugged.
2409 */
2410 public abstract int getDischargeAmountScreenOff();
2411
2412 /**
2413 * Get the amount the battery has discharged while the screen was off,
2414 * since the last time the device was charged.
2415 */
2416 public abstract int getDischargeAmountScreenOffSinceCharge();
2417
2418 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 * Returns the total, last, or current battery uptime in microseconds.
2420 *
2421 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002422 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 */
2424 public abstract long computeBatteryUptime(long curTime, int which);
2425
2426 /**
2427 * Returns the total, last, or current battery realtime in microseconds.
2428 *
2429 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002430 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 */
2432 public abstract long computeBatteryRealtime(long curTime, int which);
2433
2434 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002435 * Returns the total, last, or current battery screen off uptime in microseconds.
2436 *
2437 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002438 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002439 */
2440 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2441
2442 /**
2443 * Returns the total, last, or current battery screen off realtime in microseconds.
2444 *
2445 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002446 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002447 */
2448 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2449
2450 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 * Returns the total, last, or current uptime in microseconds.
2452 *
2453 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002454 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 */
2456 public abstract long computeUptime(long curTime, int which);
2457
2458 /**
2459 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002460 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002462 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002463 */
2464 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002465
2466 /**
2467 * Compute an approximation for how much run time (in microseconds) is remaining on
2468 * the battery. Returns -1 if no time can be computed: either there is not
2469 * enough current data to make a decision, or the battery is currently
2470 * charging.
2471 *
2472 * @param curTime The current elepsed realtime in microseconds.
2473 */
2474 public abstract long computeBatteryTimeRemaining(long curTime);
2475
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002476 // The part of a step duration that is the actual time.
2477 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2478
2479 // Bits in a step duration that are the new battery level we are at.
2480 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002481 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002482
2483 // Bits in a step duration that are the initial mode we were in at that step.
2484 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002485 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002486
2487 // Bits in a step duration that indicate which modes changed during that step.
2488 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002489 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002490
2491 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2492 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2493
Santos Cordone94f0502017-02-24 12:31:20 -08002494 // The largest value for screen state that is tracked in battery states. Any values above
2495 // this should be mapped back to one of the tracked values before being tracked here.
2496 public static final int MAX_TRACKED_SCREEN_STATE = Display.STATE_DOZE_SUSPEND;
2497
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002498 // Step duration mode: power save is on.
2499 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2500
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002501 // Step duration mode: device is currently in idle mode.
2502 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2503
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002504 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2505 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002506 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2507 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002508 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,
2511 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2512 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002513 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2514 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002515 };
2516 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2517 (Display.STATE_OFF-1),
2518 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002519 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002520 (Display.STATE_ON-1),
2521 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2522 (Display.STATE_DOZE-1),
2523 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2524 (Display.STATE_DOZE_SUSPEND-1),
2525 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002526 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002527 };
2528 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2529 "screen off",
2530 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002531 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002532 "screen on",
2533 "screen on power save",
2534 "screen doze",
2535 "screen doze power save",
2536 "screen doze-suspend",
2537 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002538 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002539 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002540
2541 /**
Adam Lesinski3ee3f632016-06-08 13:55:55 -07002542 * Return the counter keeping track of the amount of battery discharge while the screen was off,
2543 * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
2544 * a coulomb counter.
2545 */
2546 public abstract LongCounter getDischargeScreenOffCoulombCounter();
2547
2548 /**
2549 * Return the counter keeping track of the amount of battery discharge measured in
2550 * micro-Ampere-hours. This will be non-zero only if the device's battery has
2551 * a coulomb counter.
2552 */
2553 public abstract LongCounter getDischargeCoulombCounter();
2554
2555 /**
Adam Lesinskif9b20a92016-06-17 17:30:01 -07002556 * Returns the estimated real battery capacity, which may be less than the capacity
2557 * declared by the PowerProfile.
2558 * @return The estimated battery capacity in mAh.
2559 */
2560 public abstract int getEstimatedBatteryCapacity();
2561
2562 /**
Jocelyn Dangc627d102017-04-14 13:15:14 -07002563 * @return The minimum learned battery capacity in uAh.
2564 */
2565 public abstract int getMinLearnedBatteryCapacity();
2566
2567 /**
2568 * @return The maximum learned battery capacity in uAh.
2569 */
2570 public abstract int getMaxLearnedBatteryCapacity() ;
2571
2572 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002573 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002574 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002575 public abstract LevelStepTracker getDischargeLevelStepTracker();
2576
2577 /**
2578 * Return the array of daily discharge step durations.
2579 */
2580 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002581
2582 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002583 * Compute an approximation for how much time (in microseconds) remains until the battery
2584 * is fully charged. Returns -1 if no time can be computed: either there is not
2585 * enough current data to make a decision, or the battery is currently
2586 * discharging.
2587 *
2588 * @param curTime The current elepsed realtime in microseconds.
2589 */
2590 public abstract long computeChargeTimeRemaining(long curTime);
2591
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002592 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002593 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002594 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002595 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002596
2597 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002598 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002599 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002600 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002601
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002602 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2603
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002604 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002605
Evan Millarc64edde2009-04-18 12:26:32 -07002606 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607
James Carr2dd7e5e2016-07-20 18:48:39 -07002608 public abstract LongSparseArray<? extends Timer> getKernelMemoryStats();
2609
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002610 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2611
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002612 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002613 long days = seconds / (60 * 60 * 24);
2614 if (days != 0) {
2615 out.append(days);
2616 out.append("d ");
2617 }
2618 long used = days * 60 * 60 * 24;
2619
2620 long hours = (seconds - used) / (60 * 60);
2621 if (hours != 0 || used != 0) {
2622 out.append(hours);
2623 out.append("h ");
2624 }
2625 used += hours * 60 * 60;
2626
2627 long mins = (seconds-used) / 60;
2628 if (mins != 0 || used != 0) {
2629 out.append(mins);
2630 out.append("m ");
2631 }
2632 used += mins * 60;
2633
2634 if (seconds != 0 || used != 0) {
2635 out.append(seconds-used);
2636 out.append("s ");
2637 }
2638 }
2639
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002640 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002642 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 sb.append(time - (sec * 1000));
2644 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645 }
2646
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002647 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002648 long sec = time / 1000;
2649 formatTimeRaw(sb, sec);
2650 sb.append(time - (sec * 1000));
2651 sb.append("ms");
2652 }
2653
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002654 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002655 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002656 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002657 }
2658 float perc = ((float)num) / ((float)den) * 100;
2659 mFormatBuilder.setLength(0);
2660 mFormatter.format("%.1f%%", perc);
2661 return mFormatBuilder.toString();
2662 }
2663
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002664 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002665 mFormatBuilder.setLength(0);
Bookatzc8c44962017-05-11 12:12:54 -07002666
Evan Millar22ac0432009-03-31 11:33:18 -07002667 if (bytes < BYTES_PER_KB) {
2668 return bytes + "B";
2669 } else if (bytes < BYTES_PER_MB) {
2670 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2671 return mFormatBuilder.toString();
2672 } else if (bytes < BYTES_PER_GB){
2673 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2674 return mFormatBuilder.toString();
2675 } else {
2676 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2677 return mFormatBuilder.toString();
2678 }
2679 }
2680
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002681 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002682 if (timer != null) {
2683 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002684 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002685 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2686 return totalTimeMillis;
2687 }
2688 return 0;
2689 }
2690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 /**
2692 *
2693 * @param sb a StringBuilder object.
2694 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002695 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002697 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 * @param linePrefix a String to be prepended to each line of output.
2699 * @return the line prefix
2700 */
2701 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002702 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002705 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002706
Evan Millarc64edde2009-04-18 12:26:32 -07002707 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002708 if (totalTimeMillis != 0) {
2709 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002710 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002711 if (name != null) {
2712 sb.append(name);
2713 sb.append(' ');
2714 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715 sb.append('(');
2716 sb.append(count);
2717 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002718 final long maxDurationMs = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
2719 if (maxDurationMs >= 0) {
2720 sb.append(" max=");
2721 sb.append(maxDurationMs);
2722 }
Bookatz506a8182017-05-01 14:18:42 -07002723 // Put actual time if it is available and different from totalTimeMillis.
2724 final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
2725 if (totalDurMs > totalTimeMillis) {
2726 sb.append(" actual=");
2727 sb.append(totalDurMs);
2728 }
Joe Onorato92fd23f2016-07-25 11:18:42 -07002729 if (timer.isRunningLocked()) {
2730 final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2731 if (currentMs >= 0) {
2732 sb.append(" (running for ");
2733 sb.append(currentMs);
2734 sb.append("ms)");
2735 } else {
2736 sb.append(" (running)");
2737 }
2738 }
2739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002740 return ", ";
2741 }
2742 }
2743 return linePrefix;
2744 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002745
2746 /**
Joe Onorato92fd23f2016-07-25 11:18:42 -07002747 * Prints details about a timer, if its total time was greater than 0.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002748 *
2749 * @param pw a PrintWriter object to print to.
2750 * @param sb a StringBuilder object.
2751 * @param timer a Timer object contining the wakelock times.
Bookatz867c0d72017-03-07 18:23:42 -08002752 * @param rawRealtimeUs the current on-battery time in microseconds.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002753 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2754 * @param prefix a String to be prepended to each line of output.
2755 * @param type the name of the timer.
Joe Onorato92fd23f2016-07-25 11:18:42 -07002756 * @return true if anything was printed.
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002757 */
2758 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
Joe Onorato92fd23f2016-07-25 11:18:42 -07002759 long rawRealtimeUs, int which, String prefix, String type) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002760 if (timer != null) {
2761 // Convert from microseconds to milliseconds with rounding
Joe Onorato92fd23f2016-07-25 11:18:42 -07002762 final long totalTimeMs = (timer.getTotalTimeLocked(
2763 rawRealtimeUs, which) + 500) / 1000;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002764 final int count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002765 if (totalTimeMs != 0) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002766 sb.setLength(0);
2767 sb.append(prefix);
2768 sb.append(" ");
2769 sb.append(type);
2770 sb.append(": ");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002771 formatTimeMs(sb, totalTimeMs);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002772 sb.append("realtime (");
2773 sb.append(count);
2774 sb.append(" times)");
Joe Onorato92fd23f2016-07-25 11:18:42 -07002775 final long maxDurationMs = timer.getMaxDurationMsLocked(rawRealtimeUs/1000);
2776 if (maxDurationMs >= 0) {
2777 sb.append(" max=");
2778 sb.append(maxDurationMs);
2779 }
2780 if (timer.isRunningLocked()) {
2781 final long currentMs = timer.getCurrentDurationMsLocked(rawRealtimeUs/1000);
2782 if (currentMs >= 0) {
2783 sb.append(" (running for ");
2784 sb.append(currentMs);
2785 sb.append("ms)");
2786 } else {
2787 sb.append(" (running)");
2788 }
2789 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002790 pw.println(sb.toString());
2791 return true;
2792 }
2793 }
2794 return false;
2795 }
Bookatzc8c44962017-05-11 12:12:54 -07002796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 /**
2798 * Checkin version of wakelock printer. Prints simple comma-separated list.
Bookatzc8c44962017-05-11 12:12:54 -07002799 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 * @param sb a StringBuilder object.
2801 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002802 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002804 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 * @param linePrefix a String to be prepended to each line of output.
2806 * @return the line prefix
2807 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002808 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2809 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 long totalTimeMicros = 0;
2811 int count = 0;
Bookatz941d98f2017-05-02 19:25:18 -07002812 long max = 0;
2813 long current = 0;
2814 long totalDuration = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002815 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002816 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Bookatz506a8182017-05-01 14:18:42 -07002817 count = timer.getCountLocked(which);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002818 current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
2819 max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
Bookatz506a8182017-05-01 14:18:42 -07002820 totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 }
2822 sb.append(linePrefix);
2823 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2824 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002825 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 sb.append(count);
Joe Onorato92fd23f2016-07-25 11:18:42 -07002827 sb.append(',');
2828 sb.append(current);
2829 sb.append(',');
2830 sb.append(max);
Bookatz506a8182017-05-01 14:18:42 -07002831 // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
2832 // not always tracked). Kernel wakelocks (which have name == null) have no notion of
2833 // totalDuration independent of totalTimeMicros (since they are not pooled).
2834 if (name != null) {
2835 sb.append(',');
2836 sb.append(totalDuration);
2837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 return ",";
2839 }
Bookatz506a8182017-05-01 14:18:42 -07002840
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002841 private static final void dumpLineHeader(PrintWriter pw, int uid, String category,
2842 String type) {
2843 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2844 pw.print(',');
2845 pw.print(uid);
2846 pw.print(',');
2847 pw.print(category);
2848 pw.print(',');
2849 pw.print(type);
2850 }
2851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 /**
2853 * Dump a comma-separated line of values for terse checkin mode.
Bookatzc8c44962017-05-11 12:12:54 -07002854 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855 * @param pw the PageWriter to dump log to
2856 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2857 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2858 * @param args type-dependent data arguments
2859 */
Bookatzc8c44962017-05-11 12:12:54 -07002860 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 Object... args ) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002862 dumpLineHeader(pw, uid, category, type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002863 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002864 pw.print(',');
2865 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002867 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002868 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002869
2870 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002871 * Dump a given timer stat for terse checkin mode.
2872 *
2873 * @param pw the PageWriter to dump log to
2874 * @param uid the UID to log
2875 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2876 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2877 * @param timer a {@link Timer} to dump stats for
2878 * @param rawRealtime the current elapsed realtime of the system in microseconds
2879 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2880 */
2881 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2882 Timer timer, long rawRealtime, int which) {
2883 if (timer != null) {
2884 // Convert from microseconds to milliseconds with rounding
2885 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2886 / 1000;
2887 final int count = timer.getCountLocked(which);
2888 if (totalTime != 0) {
2889 dumpLine(pw, uid, category, type, totalTime, count);
2890 }
2891 }
2892 }
2893
2894 /**
Adam Lesinski21f76aa2016-01-25 12:27:06 -08002895 * Checks if the ControllerActivityCounter has any data worth dumping.
2896 */
2897 private static boolean controllerActivityHasData(ControllerActivityCounter counter, int which) {
2898 if (counter == null) {
2899 return false;
2900 }
2901
2902 if (counter.getIdleTimeCounter().getCountLocked(which) != 0
2903 || counter.getRxTimeCounter().getCountLocked(which) != 0
2904 || counter.getPowerCounter().getCountLocked(which) != 0) {
2905 return true;
2906 }
2907
2908 for (LongCounter c : counter.getTxTimeCounters()) {
2909 if (c.getCountLocked(which) != 0) {
2910 return true;
2911 }
2912 }
2913 return false;
2914 }
2915
2916 /**
2917 * Dumps the ControllerActivityCounter if it has any data worth dumping.
2918 * The order of the arguments in the final check in line is:
2919 *
2920 * idle, rx, power, tx...
2921 *
2922 * where tx... is one or more transmit level times.
2923 */
2924 private static final void dumpControllerActivityLine(PrintWriter pw, int uid, String category,
2925 String type,
2926 ControllerActivityCounter counter,
2927 int which) {
2928 if (!controllerActivityHasData(counter, which)) {
2929 return;
2930 }
2931
2932 dumpLineHeader(pw, uid, category, type);
2933 pw.print(",");
2934 pw.print(counter.getIdleTimeCounter().getCountLocked(which));
2935 pw.print(",");
2936 pw.print(counter.getRxTimeCounter().getCountLocked(which));
2937 pw.print(",");
2938 pw.print(counter.getPowerCounter().getCountLocked(which) / (1000 * 60 * 60));
2939 for (LongCounter c : counter.getTxTimeCounters()) {
2940 pw.print(",");
2941 pw.print(c.getCountLocked(which));
2942 }
2943 pw.println();
2944 }
2945
2946 private final void printControllerActivityIfInteresting(PrintWriter pw, StringBuilder sb,
2947 String prefix, String controllerName,
2948 ControllerActivityCounter counter,
2949 int which) {
2950 if (controllerActivityHasData(counter, which)) {
2951 printControllerActivity(pw, sb, prefix, controllerName, counter, which);
2952 }
2953 }
2954
2955 private final void printControllerActivity(PrintWriter pw, StringBuilder sb, String prefix,
2956 String controllerName,
2957 ControllerActivityCounter counter, int which) {
2958 final long idleTimeMs = counter.getIdleTimeCounter().getCountLocked(which);
2959 final long rxTimeMs = counter.getRxTimeCounter().getCountLocked(which);
2960 final long powerDrainMaMs = counter.getPowerCounter().getCountLocked(which);
2961 long totalTxTimeMs = 0;
2962 for (LongCounter txState : counter.getTxTimeCounters()) {
2963 totalTxTimeMs += txState.getCountLocked(which);
2964 }
2965
2966 final long totalTimeMs = idleTimeMs + rxTimeMs + totalTxTimeMs;
2967
2968 sb.setLength(0);
2969 sb.append(prefix);
2970 sb.append(" ");
2971 sb.append(controllerName);
2972 sb.append(" Idle time: ");
2973 formatTimeMs(sb, idleTimeMs);
2974 sb.append("(");
2975 sb.append(formatRatioLocked(idleTimeMs, totalTimeMs));
2976 sb.append(")");
2977 pw.println(sb.toString());
2978
2979 sb.setLength(0);
2980 sb.append(prefix);
2981 sb.append(" ");
2982 sb.append(controllerName);
2983 sb.append(" Rx time: ");
2984 formatTimeMs(sb, rxTimeMs);
2985 sb.append("(");
2986 sb.append(formatRatioLocked(rxTimeMs, totalTimeMs));
2987 sb.append(")");
2988 pw.println(sb.toString());
2989
2990 sb.setLength(0);
2991 sb.append(prefix);
2992 sb.append(" ");
2993 sb.append(controllerName);
2994 sb.append(" Tx time: ");
2995 formatTimeMs(sb, totalTxTimeMs);
2996 sb.append("(");
2997 sb.append(formatRatioLocked(totalTxTimeMs, totalTimeMs));
2998 sb.append(")");
2999 pw.println(sb.toString());
3000
3001 final int numTxLvls = counter.getTxTimeCounters().length;
3002 if (numTxLvls > 1) {
3003 for (int lvl = 0; lvl < numTxLvls; lvl++) {
3004 final long txLvlTimeMs = counter.getTxTimeCounters()[lvl].getCountLocked(which);
3005 sb.setLength(0);
3006 sb.append(prefix);
3007 sb.append(" [");
3008 sb.append(lvl);
3009 sb.append("] ");
3010 formatTimeMs(sb, txLvlTimeMs);
3011 sb.append("(");
3012 sb.append(formatRatioLocked(txLvlTimeMs, totalTxTimeMs));
3013 sb.append(")");
3014 pw.println(sb.toString());
3015 }
3016 }
3017
3018 sb.setLength(0);
3019 sb.append(prefix);
3020 sb.append(" ");
3021 sb.append(controllerName);
3022 sb.append(" Power drain: ").append(
3023 BatteryStatsHelper.makemAh(powerDrainMaMs / (double) (1000*60*60)));
3024 sb.append("mAh");
3025 pw.println(sb.toString());
3026 }
3027
3028 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07003029 * Temporary for settings.
3030 */
3031 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
3032 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3033 }
3034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 /**
3036 * Checkin server version of dump to produce more compact, computer-readable log.
Bookatzc8c44962017-05-11 12:12:54 -07003037 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003038 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003039 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07003040 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
3041 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3043 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3044 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003045 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3046 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003047 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3048 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3049 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003050 final long totalRealtime = computeRealtime(rawRealtime, which);
3051 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003052 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003053 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003054 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003055 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3056 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003057 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003058 rawRealtime, which);
3059 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3060 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003061 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003062 rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003063 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003064 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003065 final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
3066 final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
3067 .getCountLocked(which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003068
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003069 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003070
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003071 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003072 final int NU = uidStats.size();
Bookatzc8c44962017-05-11 12:12:54 -07003073
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003074 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076 // Dump "battery" stat
Jocelyn Dangc627d102017-04-14 13:15:14 -07003077 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003078 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07003079 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003080 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003081 getStartClockTime(),
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003082 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
Jocelyn Dangc627d102017-04-14 13:15:14 -07003083 getEstimatedBatteryCapacity(),
3084 getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity());
Adam Lesinski67c134f2016-06-10 15:15:08 -07003085
Bookatzc8c44962017-05-11 12:12:54 -07003086
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003087 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003088 long fullWakeLockTimeTotal = 0;
3089 long partialWakeLockTimeTotal = 0;
Bookatzc8c44962017-05-11 12:12:54 -07003090
Evan Millar22ac0432009-03-31 11:33:18 -07003091 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003092 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003093
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003094 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3095 = u.getWakelockStats();
3096 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3097 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003098
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003099 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3100 if (fullWakeTimer != null) {
3101 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
3102 which);
3103 }
3104
3105 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3106 if (partialWakeTimer != null) {
3107 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
3108 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003109 }
3110 }
3111 }
Adam Lesinskie283d332015-04-16 12:29:25 -07003112
3113 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003114 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3115 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3116 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3117 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3118 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3119 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3120 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3121 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003122 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3123 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003124 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
3125 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003126 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets,
3127 btRxTotalBytes, btTxTotalBytes);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003128
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003129 // Dump Modem controller stats
3130 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_MODEM_CONTROLLER_DATA,
3131 getModemControllerActivity(), which);
3132
Adam Lesinskie283d332015-04-16 12:29:25 -07003133 // Dump Wifi controller stats
3134 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
3135 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003136 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA, wifiOnTime / 1000,
Adam Lesinski2208e742016-02-19 12:53:31 -08003137 wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */ 0, 0, 0);
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003138
3139 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_WIFI_CONTROLLER_DATA,
3140 getWifiControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003141
3142 // Dump Bluetooth controller stats
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003143 dumpControllerActivityLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_CONTROLLER_DATA,
3144 getBluetoothControllerActivity(), which);
Adam Lesinskie283d332015-04-16 12:29:25 -07003145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 // Dump misc stats
3147 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07003148 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003149 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07003150 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07003151 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003152 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000,
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003153 getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000,
3154 getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which),
Adam Lesinski782327b2015-07-30 16:36:29 -07003155 getMobileRadioActiveCount(which),
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003156 getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000,
3157 getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000,
3158 getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which),
3159 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT),
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003160 getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Bookatzc8c44962017-05-11 12:12:54 -07003161
Dianne Hackborn617f8772009-03-31 15:04:46 -07003162 // Dump screen brightness stats
3163 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
3164 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003165 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07003166 }
3167 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
Bookatzc8c44962017-05-11 12:12:54 -07003168
Dianne Hackborn627bba72009-03-24 22:32:56 -07003169 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08003170 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
3171 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003172 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003173 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003174 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003175 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003176 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08003177 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003178 args[i] = getPhoneSignalStrengthCount(i, which);
3179 }
3180 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003181
Dianne Hackborn627bba72009-03-24 22:32:56 -07003182 // Dump network type stats
3183 args = new Object[NUM_DATA_CONNECTION_TYPES];
3184 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003185 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07003186 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07003187 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
3188 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
3189 args[i] = getPhoneDataConnectionCount(i, which);
3190 }
3191 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003192
3193 // Dump wifi state stats
3194 args = new Object[NUM_WIFI_STATES];
3195 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003196 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003197 }
3198 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
3199 for (int i=0; i<NUM_WIFI_STATES; i++) {
3200 args[i] = getWifiStateCount(i, which);
3201 }
3202 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
3203
Dianne Hackborn3251b902014-06-20 14:40:53 -07003204 // Dump wifi suppl state stats
3205 args = new Object[NUM_WIFI_SUPPL_STATES];
3206 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3207 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
3208 }
3209 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
3210 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3211 args[i] = getWifiSupplStateCount(i, which);
3212 }
3213 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
3214
3215 // Dump wifi signal strength stats
3216 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
3217 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3218 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
3219 }
3220 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
3221 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3222 args[i] = getWifiSignalStrengthCount(i, which);
3223 }
3224 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
3225
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003226 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003227 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07003228 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003229 }
Bookatzc8c44962017-05-11 12:12:54 -07003230
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003231 if (which == STATS_SINCE_UNPLUGGED) {
3232 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3233 getDischargeStartLevel()-getDischargeCurrentLevel(),
3234 getDischargeStartLevel()-getDischargeCurrentLevel(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003235 getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
3236 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003237 } else {
3238 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
3239 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07003240 getDischargeAmountScreenOnSinceCharge(),
Adam Lesinski67c134f2016-06-10 15:15:08 -07003241 getDischargeAmountScreenOffSinceCharge(),
3242 dischargeCount / 1000, dischargeScreenOffCount / 1000);
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003243 }
Bookatzc8c44962017-05-11 12:12:54 -07003244
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003245 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003246 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003247 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003248 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003249 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003250 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003251 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA,
3252 "\"" + ent.getKey() + "\"", sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003253 }
Evan Millarc64edde2009-04-18 12:26:32 -07003254 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003255 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003256 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003257 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3258 // Not doing the regular wake lock formatting to remain compatible
3259 // with the old checkin format.
3260 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
3261 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003262 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003263 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003264 }
3265 }
Evan Millarc64edde2009-04-18 12:26:32 -07003266 }
Bookatzc8c44962017-05-11 12:12:54 -07003267
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003268 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003269 helper.create(this);
3270 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003271 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003272 if (sippers != null && sippers.size() > 0) {
3273 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
3274 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08003275 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003276 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
3277 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
3278 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003279 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003280 int uid = 0;
3281 String label;
3282 switch (bs.drainType) {
3283 case IDLE:
3284 label="idle";
3285 break;
3286 case CELL:
3287 label="cell";
3288 break;
3289 case PHONE:
3290 label="phone";
3291 break;
3292 case WIFI:
3293 label="wifi";
3294 break;
3295 case BLUETOOTH:
3296 label="blue";
3297 break;
3298 case SCREEN:
3299 label="scrn";
3300 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003301 case FLASHLIGHT:
3302 label="flashlight";
3303 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003304 case APP:
3305 uid = bs.uidObj.getUid();
3306 label = "uid";
3307 break;
3308 case USER:
3309 uid = UserHandle.getUid(bs.userId, 0);
3310 label = "user";
3311 break;
3312 case UNACCOUNTED:
3313 label = "unacc";
3314 break;
3315 case OVERCOUNTED:
3316 label = "over";
3317 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003318 case CAMERA:
3319 label = "camera";
3320 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003321 default:
3322 label = "???";
3323 }
3324 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07003325 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003326 }
3327 }
3328
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003329 final long[] cpuFreqs = getCpuFreqs();
3330 if (cpuFreqs != null) {
3331 sb.setLength(0);
3332 for (int i = 0; i < cpuFreqs.length; ++i) {
3333 sb.append((i == 0 ? "" : ",") + cpuFreqs[i]);
3334 }
3335 dumpLine(pw, 0 /* uid */, category, GLOBAL_CPU_FREQ_DATA, sb.toString());
3336 }
3337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 for (int iu = 0; iu < NU; iu++) {
3339 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003340 if (reqUid >= 0 && uid != reqUid) {
3341 continue;
3342 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003343 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07003344
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003346 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3347 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3348 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3349 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3350 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3351 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3352 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
3353 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003354 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003355 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3356 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski5f056f62016-07-14 16:56:08 -07003357 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003358 final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3359 final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Amith Yamasani59fe8412017-03-03 16:28:52 -08003360 // Background data transfers
3361 final long mobileBytesBgRx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_RX_DATA,
3362 which);
3363 final long mobileBytesBgTx = u.getNetworkActivityBytes(NETWORK_MOBILE_BG_TX_DATA,
3364 which);
3365 final long wifiBytesBgRx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_RX_DATA, which);
3366 final long wifiBytesBgTx = u.getNetworkActivityBytes(NETWORK_WIFI_BG_TX_DATA, which);
3367 final long mobilePacketsBgRx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_RX_DATA,
3368 which);
3369 final long mobilePacketsBgTx = u.getNetworkActivityPackets(NETWORK_MOBILE_BG_TX_DATA,
3370 which);
3371 final long wifiPacketsBgRx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_RX_DATA,
3372 which);
3373 final long wifiPacketsBgTx = u.getNetworkActivityPackets(NETWORK_WIFI_BG_TX_DATA,
3374 which);
3375
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003376 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
3377 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003378 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0
Amith Yamasani59fe8412017-03-03 16:28:52 -08003379 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0
3380 || mobileBytesBgRx > 0 || mobileBytesBgTx > 0 || wifiBytesBgRx > 0
3381 || wifiBytesBgTx > 0
3382 || mobilePacketsBgRx > 0 || mobilePacketsBgTx > 0 || wifiPacketsBgRx > 0
3383 || wifiPacketsBgTx > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003384 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
3385 wifiBytesRx, wifiBytesTx,
3386 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003387 wifiPacketsRx, wifiPacketsTx,
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003388 mobileActiveTime, mobileActiveCount,
Amith Yamasani59fe8412017-03-03 16:28:52 -08003389 btBytesRx, btBytesTx, mobileWakeup, wifiWakeup,
3390 mobileBytesBgRx, mobileBytesBgTx, wifiBytesBgRx, wifiBytesBgTx,
3391 mobilePacketsBgRx, mobilePacketsBgTx, wifiPacketsBgRx, wifiPacketsBgTx
3392 );
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003393 }
3394
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003395 // Dump modem controller data, per UID.
3396 dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA,
3397 u.getModemControllerActivity(), which);
3398
3399 // Dump Wifi controller data, per UID.
Adam Lesinskie283d332015-04-16 12:29:25 -07003400 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3401 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3402 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08003403 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
3404 // Note that 'ActualTime' are unpooled and always since reset (regardless of 'which')
Bookatzce49aca2017-04-03 09:47:05 -07003405 final long wifiScanActualTimeMs = (u.getWifiScanActualTime(rawRealtime) + 500) / 1000;
3406 final long wifiScanActualTimeMsBg = (u.getWifiScanBackgroundTime(rawRealtime) + 500)
3407 / 1000;
Adam Lesinskie283d332015-04-16 12:29:25 -07003408 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003409 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatzce49aca2017-04-03 09:47:05 -07003410 || wifiScanCountBg != 0 || wifiScanActualTimeMs != 0
3411 || wifiScanActualTimeMsBg != 0 || uidWifiRunningTime != 0) {
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003412 dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime,
3413 uidWifiRunningTime, wifiScanCount,
Bookatz867c0d72017-03-07 18:23:42 -08003414 /* legacy fields follow, keep at 0 */ 0, 0, 0,
Bookatzce49aca2017-04-03 09:47:05 -07003415 wifiScanCountBg, wifiScanActualTimeMs, wifiScanActualTimeMsBg);
The Android Open Source Project10592532009-03-18 17:39:46 -07003416 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003417
Adam Lesinski21f76aa2016-01-25 12:27:06 -08003418 dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA,
3419 u.getWifiControllerActivity(), which);
3420
Bookatz867c0d72017-03-07 18:23:42 -08003421 final Timer bleTimer = u.getBluetoothScanTimer();
3422 if (bleTimer != null) {
3423 // Convert from microseconds to milliseconds with rounding
3424 final long totalTime = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
3425 / 1000;
3426 if (totalTime != 0) {
3427 final int count = bleTimer.getCountLocked(which);
3428 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
3429 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
3430 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
3431 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3432 final long actualTime = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
3433 final long actualTimeBg = bleTimerBg != null ?
3434 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatz956f36bf2017-04-28 09:48:17 -07003435 final int resultCount = u.getBluetoothScanResultCounter() != null ?
3436 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08003437 dumpLine(pw, uid, category, BLUETOOTH_MISC_DATA, totalTime, count,
Bookatz956f36bf2017-04-28 09:48:17 -07003438 countBg, actualTime, actualTimeBg, resultCount);
Bookatz867c0d72017-03-07 18:23:42 -08003439 }
3440 }
Adam Lesinskid9b99be2016-03-30 16:58:51 -07003441
Adam Lesinski9f55cc72016-01-27 20:42:14 -08003442 dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA,
3443 u.getBluetoothControllerActivity(), which);
3444
Dianne Hackborn617f8772009-03-31 15:04:46 -07003445 if (u.hasUserActivity()) {
3446 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
3447 boolean hasData = false;
3448 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
3449 int val = u.getUserActivityCount(i, which);
3450 args[i] = val;
3451 if (val != 0) hasData = true;
3452 }
3453 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07003454 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003455 }
3456 }
Bookatzc8c44962017-05-11 12:12:54 -07003457
3458 if (u.getAggregatedPartialWakelockTimer() != null) {
3459 final Timer timer = u.getAggregatedPartialWakelockTimer();
3460 // Convert from microseconds to milliseconds with rounding
3461 final long totTimeMs = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3462 final Timer bgTimer = timer.getSubTimer();
3463 final long bgTimeMs = bgTimer != null ?
3464 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
3465 dumpLine(pw, uid, category, AGGREGATED_WAKELOCK_DATA, totTimeMs, bgTimeMs);
3466 }
3467
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003468 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
3469 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3470 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3471 String linePrefix = "";
3472 sb.setLength(0);
3473 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
3474 rawRealtime, "f", which, linePrefix);
3475 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
3476 rawRealtime, "p", which, linePrefix);
3477 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
3478 rawRealtime, "w", which, linePrefix);
3479
3480 // Only log if we had at lease one wakelock...
3481 if (sb.length() > 0) {
3482 String name = wakelocks.keyAt(iw);
3483 if (name.indexOf(',') >= 0) {
3484 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003486 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 }
3488 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003489
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003490 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3491 for (int isy=syncs.size()-1; isy>=0; isy--) {
3492 final Timer timer = syncs.valueAt(isy);
3493 // Convert from microseconds to milliseconds with rounding
3494 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3495 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07003496 final Timer bgTimer = timer.getSubTimer();
3497 final long bgTime = bgTimer != null ?
3498 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
3499 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003500 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003501 dumpLine(pw, uid, category, SYNC_DATA, "\"" + syncs.keyAt(isy) + "\"",
Bookatz2bffb5b2017-04-13 11:59:33 -07003502 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003503 }
3504 }
3505
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003506 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3507 for (int ij=jobs.size()-1; ij>=0; ij--) {
3508 final Timer timer = jobs.valueAt(ij);
3509 // Convert from microseconds to milliseconds with rounding
3510 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3511 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07003512 final Timer bgTimer = timer.getSubTimer();
3513 final long bgTime = bgTimer != null ?
3514 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
3515 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003516 if (totalTime != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003517 dumpLine(pw, uid, category, JOB_DATA, "\"" + jobs.keyAt(ij) + "\"",
Bookatzaa4594a2017-03-24 12:39:56 -07003518 totalTime, count, bgTime, bgCount);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003519 }
3520 }
3521
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003522 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
3523 rawRealtime, which);
3524 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
3525 rawRealtime, which);
3526 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
3527 rawRealtime, which);
3528 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
3529 rawRealtime, which);
3530
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003531 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3532 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003533 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003534 final Uid.Sensor se = sensors.valueAt(ise);
3535 final int sensorNumber = sensors.keyAt(ise);
3536 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003537 if (timer != null) {
3538 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003539 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
3540 / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003541 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08003542 final int count = timer.getCountLocked(which);
3543 final Timer bgTimer = se.getSensorBackgroundTime();
3544 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
3545 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
3546 // 'actualTime' are unpooled and always since reset (regardless of 'which')
3547 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
3548 final long bgActualTime = bgTimer != null ?
3549 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
3550 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime,
3551 count, bgCount, actualTime, bgActualTime);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 }
3554 }
3555
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003556 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
3557 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003558
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003559 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
3560 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003561
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003562 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07003563 long totalStateTime = 0;
3564 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
Dianne Hackborna8d10942015-11-19 17:55:19 -08003565 final long time = u.getProcessStateTime(ips, rawRealtime, which);
3566 totalStateTime += time;
3567 stateTimes[ips] = (time + 500) / 1000;
Dianne Hackborn61659e52014-07-09 16:13:01 -07003568 }
3569 if (totalStateTime > 0) {
3570 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
3571 }
3572
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003573 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
3574 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003575 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003576 dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000,
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07003577 0 /* old cpu power, keep for compatibility */);
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003578 }
3579
Sudheer Shanka9b735c52017-05-09 18:26:18 -07003580 final long[] cpuFreqTimeMs = u.getCpuFreqTimes(which);
3581 // If total cpuFreqTimes is null, then we don't need to check for screenOffCpuFreqTimes.
3582 if (cpuFreqTimeMs != null) {
3583 sb.setLength(0);
3584 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3585 sb.append((i == 0 ? "" : ",") + cpuFreqTimeMs[i]);
3586 }
3587 final long[] screenOffCpuFreqTimeMs = u.getScreenOffCpuFreqTimes(which);
3588 if (screenOffCpuFreqTimeMs != null) {
3589 for (int i = 0; i < screenOffCpuFreqTimeMs.length; ++i) {
3590 sb.append("," + screenOffCpuFreqTimeMs[i]);
3591 }
3592 } else {
3593 for (int i = 0; i < cpuFreqTimeMs.length; ++i) {
3594 sb.append(",0");
3595 }
3596 }
3597 dumpLine(pw, uid, category, CPU_TIMES_AT_FREQ_DATA, UID_TIMES_TYPE_ALL,
3598 cpuFreqTimeMs.length, sb.toString());
3599 }
3600
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003601 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
3602 = u.getProcessStats();
3603 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
3604 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003605
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003606 final long userMillis = ps.getUserTime(which);
3607 final long systemMillis = ps.getSystemTime(which);
3608 final long foregroundMillis = ps.getForegroundTime(which);
3609 final int starts = ps.getStarts(which);
3610 final int numCrashes = ps.getNumCrashes(which);
3611 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003612
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003613 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
3614 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Kweku Adamse0dd9c12017-03-08 08:12:15 -08003615 dumpLine(pw, uid, category, PROCESS_DATA, "\"" + processStats.keyAt(ipr) + "\"",
3616 userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 }
3618 }
3619
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003620 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
3621 = u.getPackageStats();
3622 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
3623 final Uid.Pkg ps = packageStats.valueAt(ipkg);
3624 int wakeups = 0;
3625 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
3626 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
Joe Onorato1476d322016-05-05 14:46:15 -07003627 int count = alarms.valueAt(iwa).getCountLocked(which);
3628 wakeups += count;
3629 String name = alarms.keyAt(iwa).replace(',', '_');
3630 dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003631 }
3632 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3633 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
3634 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
3635 final long startTime = ss.getStartTime(batteryUptime, which);
3636 final int starts = ss.getStarts(which);
3637 final int launches = ss.getLaunches(which);
3638 if (startTime != 0 || starts != 0 || launches != 0) {
3639 dumpLine(pw, uid, category, APK_DATA,
3640 wakeups, // wakeup alarms
3641 packageStats.keyAt(ipkg), // Apk
3642 serviceStats.keyAt(isvc), // service
3643 startTime / 1000, // time spent started, in ms
3644 starts,
3645 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003646 }
3647 }
3648 }
3649 }
3650 }
3651
Dianne Hackborn81038902012-11-26 17:04:09 -08003652 static final class TimerEntry {
3653 final String mName;
3654 final int mId;
3655 final BatteryStats.Timer mTimer;
3656 final long mTime;
3657 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
3658 mName = name;
3659 mId = id;
3660 mTimer = timer;
3661 mTime = time;
3662 }
3663 }
3664
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003665 private void printmAh(PrintWriter printer, double power) {
3666 printer.print(BatteryStatsHelper.makemAh(power));
3667 }
3668
Adam Lesinskia7a4ccc2015-06-26 17:43:04 -07003669 private void printmAh(StringBuilder sb, double power) {
3670 sb.append(BatteryStatsHelper.makemAh(power));
3671 }
3672
Dianne Hackbornd953c532014-08-16 18:17:38 -07003673 /**
3674 * Temporary for settings.
3675 */
3676 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
3677 int reqUid) {
3678 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
3679 }
3680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003682 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07003683 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 final long rawUptime = SystemClock.uptimeMillis() * 1000;
3685 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
3686 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687
3688 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
3689 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
3690 final long totalRealtime = computeRealtime(rawRealtime, which);
3691 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003692 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
3693 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
3694 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003695 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
3696 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003697
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003698 final StringBuilder sb = new StringBuilder(128);
Bookatzc8c44962017-05-11 12:12:54 -07003699
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003700 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07003701 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003702
Adam Lesinskif9b20a92016-06-17 17:30:01 -07003703 final int estimatedBatteryCapacity = getEstimatedBatteryCapacity();
3704 if (estimatedBatteryCapacity > 0) {
3705 sb.setLength(0);
3706 sb.append(prefix);
3707 sb.append(" Estimated battery capacity: ");
3708 sb.append(BatteryStatsHelper.makemAh(estimatedBatteryCapacity));
3709 sb.append(" mAh");
3710 pw.println(sb.toString());
3711 }
3712
Jocelyn Dangc627d102017-04-14 13:15:14 -07003713 final int minLearnedBatteryCapacity = getMinLearnedBatteryCapacity();
3714 if (minLearnedBatteryCapacity > 0) {
3715 sb.setLength(0);
3716 sb.append(prefix);
3717 sb.append(" Min learned battery capacity: ");
3718 sb.append(BatteryStatsHelper.makemAh(minLearnedBatteryCapacity / 1000));
3719 sb.append(" mAh");
3720 pw.println(sb.toString());
3721 }
3722 final int maxLearnedBatteryCapacity = getMaxLearnedBatteryCapacity();
3723 if (maxLearnedBatteryCapacity > 0) {
3724 sb.setLength(0);
3725 sb.append(prefix);
3726 sb.append(" Max learned battery capacity: ");
3727 sb.append(BatteryStatsHelper.makemAh(maxLearnedBatteryCapacity / 1000));
3728 sb.append(" mAh");
3729 pw.println(sb.toString());
3730 }
3731
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003732 sb.setLength(0);
3733 sb.append(prefix);
3734 sb.append(" Time on battery: ");
3735 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3736 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3737 sb.append(") realtime, ");
3738 formatTimeMs(sb, whichBatteryUptime / 1000);
3739 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3740 sb.append(") uptime");
3741 pw.println(sb.toString());
3742 sb.setLength(0);
3743 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003744 sb.append(" Time on battery screen off: ");
3745 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3746 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3747 sb.append(") realtime, ");
3748 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3749 sb.append("(");
3750 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3751 sb.append(") uptime");
3752 pw.println(sb.toString());
3753 sb.setLength(0);
3754 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003755 sb.append(" Total run time: ");
3756 formatTimeMs(sb, totalRealtime / 1000);
3757 sb.append("realtime, ");
3758 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003759 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003760 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003761 if (batteryTimeRemaining >= 0) {
3762 sb.setLength(0);
3763 sb.append(prefix);
3764 sb.append(" Battery time remaining: ");
3765 formatTimeMs(sb, batteryTimeRemaining / 1000);
3766 pw.println(sb.toString());
3767 }
3768 if (chargeTimeRemaining >= 0) {
3769 sb.setLength(0);
3770 sb.append(prefix);
3771 sb.append(" Charge time remaining: ");
3772 formatTimeMs(sb, chargeTimeRemaining / 1000);
3773 pw.println(sb.toString());
3774 }
Adam Lesinski3ee3f632016-06-08 13:55:55 -07003775
3776 final LongCounter dischargeCounter = getDischargeCoulombCounter();
3777 final long dischargeCount = dischargeCounter.getCountLocked(which);
3778 if (dischargeCount >= 0) {
3779 sb.setLength(0);
3780 sb.append(prefix);
3781 sb.append(" Discharge: ");
3782 sb.append(BatteryStatsHelper.makemAh(dischargeCount / 1000.0));
3783 sb.append(" mAh");
3784 pw.println(sb.toString());
3785 }
3786
3787 final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
3788 final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
3789 if (dischargeScreenOffCount >= 0) {
3790 sb.setLength(0);
3791 sb.append(prefix);
3792 sb.append(" Screen off discharge: ");
3793 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOffCount / 1000.0));
3794 sb.append(" mAh");
3795 pw.println(sb.toString());
3796 }
3797
3798 final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
3799 if (dischargeScreenOnCount >= 0) {
3800 sb.setLength(0);
3801 sb.append(prefix);
3802 sb.append(" Screen on discharge: ");
3803 sb.append(BatteryStatsHelper.makemAh(dischargeScreenOnCount / 1000.0));
3804 sb.append(" mAh");
3805 pw.println(sb.toString());
3806 }
3807
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003808 pw.print(" Start clock time: ");
3809 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3810
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003811 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003812 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003813 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003814 final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
3815 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003816 final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003817 rawRealtime, which);
3818 final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT,
3819 rawRealtime, which);
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003820 final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP,
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003821 rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003822 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3823 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3824 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003825 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003826 sb.append(prefix);
3827 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3828 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003829 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003830 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3831 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003832 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003833 pw.println(sb.toString());
3834 sb.setLength(0);
3835 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003836 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003837 boolean didOne = false;
3838 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003839 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003840 if (time == 0) {
3841 continue;
3842 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003843 sb.append("\n ");
3844 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003845 didOne = true;
3846 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3847 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003848 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003849 sb.append("(");
3850 sb.append(formatRatioLocked(time, screenOnTime));
3851 sb.append(")");
3852 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003853 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003854 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003855 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003856 sb.setLength(0);
3857 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003858 sb.append(" Power save mode enabled: ");
3859 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003860 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003861 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003862 sb.append(")");
3863 pw.println(sb.toString());
3864 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003865 if (deviceLightIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003866 sb.setLength(0);
3867 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003868 sb.append(" Device light idling: ");
3869 formatTimeMs(sb, deviceLightIdlingTime / 1000);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003870 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003871 sb.append(formatRatioLocked(deviceLightIdlingTime, whichBatteryRealtime));
3872 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003873 sb.append("x");
3874 pw.println(sb.toString());
3875 }
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003876 if (deviceIdleModeLightTime != 0) {
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003877 sb.setLength(0);
3878 sb.append(prefix);
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003879 sb.append(" Idle mode light time: ");
3880 formatTimeMs(sb, deviceIdleModeLightTime / 1000);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003881 sb.append("(");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003882 sb.append(formatRatioLocked(deviceIdleModeLightTime, whichBatteryRealtime));
3883 sb.append(") ");
3884 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003885 sb.append("x");
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003886 sb.append(" -- longest ");
3887 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT));
3888 pw.println(sb.toString());
3889 }
3890 if (deviceIdlingTime != 0) {
3891 sb.setLength(0);
3892 sb.append(prefix);
3893 sb.append(" Device full idling: ");
3894 formatTimeMs(sb, deviceIdlingTime / 1000);
3895 sb.append("(");
3896 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003897 sb.append(") "); sb.append(getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003898 sb.append("x");
3899 pw.println(sb.toString());
3900 }
3901 if (deviceIdleModeFullTime != 0) {
3902 sb.setLength(0);
3903 sb.append(prefix);
3904 sb.append(" Idle mode full time: ");
3905 formatTimeMs(sb, deviceIdleModeFullTime / 1000);
3906 sb.append("(");
3907 sb.append(formatRatioLocked(deviceIdleModeFullTime, whichBatteryRealtime));
3908 sb.append(") ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003909 sb.append(getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which));
Dianne Hackborn08c47a52015-10-15 12:38:14 -07003910 sb.append("x");
3911 sb.append(" -- longest ");
Dianne Hackborn2fefbcf2016-03-18 15:34:54 -07003912 formatTimeMs(sb, getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003913 pw.println(sb.toString());
3914 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003915 if (phoneOnTime != 0) {
3916 sb.setLength(0);
3917 sb.append(prefix);
3918 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3919 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003920 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003921 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003922 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003923 if (connChanges != 0) {
3924 pw.print(prefix);
3925 pw.print(" Connectivity changes: "); pw.println(connChanges);
3926 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003927
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003928 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003929 long fullWakeLockTimeTotalMicros = 0;
3930 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003931
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003932 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003933
Evan Millar22ac0432009-03-31 11:33:18 -07003934 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003935 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003936
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003937 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3938 = u.getWakelockStats();
3939 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3940 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003941
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003942 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3943 if (fullWakeTimer != null) {
3944 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3945 rawRealtime, which);
3946 }
3947
3948 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3949 if (partialWakeTimer != null) {
3950 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3951 rawRealtime, which);
3952 if (totalTimeMicros > 0) {
3953 if (reqUid < 0) {
3954 // Only show the ordered list of all wake
3955 // locks if the caller is not asking for data
3956 // about a specific uid.
3957 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3958 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003959 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003960 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003961 }
3962 }
3963 }
3964 }
Bookatzc8c44962017-05-11 12:12:54 -07003965
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003966 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3967 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3968 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3969 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3970 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3971 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3972 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3973 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08003974 final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
3975 final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003976
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003977 if (fullWakeLockTimeTotalMicros != 0) {
3978 sb.setLength(0);
3979 sb.append(prefix);
3980 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3981 (fullWakeLockTimeTotalMicros + 500) / 1000);
3982 pw.println(sb.toString());
3983 }
3984
3985 if (partialWakeLockTimeTotalMicros != 0) {
3986 sb.setLength(0);
3987 sb.append(prefix);
3988 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3989 (partialWakeLockTimeTotalMicros + 500) / 1000);
3990 pw.println(sb.toString());
3991 }
3992
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003993 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003994 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3995 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3996 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3997 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003998 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003999 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07004000 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07004001 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08004002 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004003 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004004 if (time == 0) {
4005 continue;
4006 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004007 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004008 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004009 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08004010 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004011 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004012 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004013 sb.append("(");
4014 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004015 sb.append(") ");
4016 sb.append(getPhoneSignalStrengthCount(i, which));
4017 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004018 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004019 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004020 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07004021
4022 sb.setLength(0);
4023 sb.append(prefix);
4024 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004025 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07004026 pw.println(sb.toString());
4027
Dianne Hackborn627bba72009-03-24 22:32:56 -07004028 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004029 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004030 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004031 didOne = false;
4032 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004033 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004034 if (time == 0) {
4035 continue;
4036 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004037 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004038 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004039 didOne = true;
4040 sb.append(DATA_CONNECTION_NAMES[i]);
4041 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004042 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07004043 sb.append("(");
4044 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07004045 sb.append(") ");
4046 sb.append(getPhoneDataConnectionCount(i, which));
4047 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004048 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004049 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07004050 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004051
4052 sb.setLength(0);
4053 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08004054 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004055 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004056 formatTimeMs(sb, mobileActiveTime / 1000);
4057 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
4058 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
4059 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07004060 pw.println(sb.toString());
4061
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004062 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
4063 if (mobileActiveUnknownTime != 0) {
4064 sb.setLength(0);
4065 sb.append(prefix);
4066 sb.append(" Mobile radio active unknown time: ");
4067 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
4068 sb.append("(");
4069 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
4070 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
4071 sb.append("x");
4072 pw.println(sb.toString());
4073 }
4074
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004075 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
4076 if (mobileActiveAdjustedTime != 0) {
4077 sb.setLength(0);
4078 sb.append(prefix);
4079 sb.append(" Mobile radio active adjusted time: ");
4080 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
4081 sb.append("(");
4082 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
4083 sb.append(")");
4084 pw.println(sb.toString());
4085 }
4086
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004087 printControllerActivity(pw, sb, prefix, "Radio", getModemControllerActivity(), which);
4088
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004089 pw.print(prefix);
4090 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
4091 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
4092 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
4093 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004094 sb.setLength(0);
4095 sb.append(prefix);
4096 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
4097 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
4098 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
4099 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004100 sb.append(")");
4101 pw.println(sb.toString());
4102
4103 sb.setLength(0);
4104 sb.append(prefix);
4105 sb.append(" Wifi states:");
4106 didOne = false;
4107 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08004108 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004109 if (time == 0) {
4110 continue;
4111 }
4112 sb.append("\n ");
4113 didOne = true;
4114 sb.append(WIFI_STATE_NAMES[i]);
4115 sb.append(" ");
4116 formatTimeMs(sb, time/1000);
4117 sb.append("(");
4118 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4119 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004120 sb.append(getWifiStateCount(i, which));
4121 sb.append("x");
4122 }
4123 if (!didOne) sb.append(" (no activity)");
4124 pw.println(sb.toString());
4125
4126 sb.setLength(0);
4127 sb.append(prefix);
4128 sb.append(" Wifi supplicant states:");
4129 didOne = false;
4130 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
4131 final long time = getWifiSupplStateTime(i, rawRealtime, which);
4132 if (time == 0) {
4133 continue;
4134 }
4135 sb.append("\n ");
4136 didOne = true;
4137 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
4138 sb.append(" ");
4139 formatTimeMs(sb, time/1000);
4140 sb.append("(");
4141 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4142 sb.append(") ");
4143 sb.append(getWifiSupplStateCount(i, which));
4144 sb.append("x");
4145 }
4146 if (!didOne) sb.append(" (no activity)");
4147 pw.println(sb.toString());
4148
4149 sb.setLength(0);
4150 sb.append(prefix);
4151 sb.append(" Wifi signal levels:");
4152 didOne = false;
4153 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
4154 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
4155 if (time == 0) {
4156 continue;
4157 }
4158 sb.append("\n ");
4159 sb.append(prefix);
4160 didOne = true;
4161 sb.append("level(");
4162 sb.append(i);
4163 sb.append(") ");
4164 formatTimeMs(sb, time/1000);
4165 sb.append("(");
4166 sb.append(formatRatioLocked(time, whichBatteryRealtime));
4167 sb.append(") ");
4168 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004169 sb.append("x");
4170 }
4171 if (!didOne) sb.append(" (no activity)");
4172 pw.println(sb.toString());
4173
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004174 printControllerActivity(pw, sb, prefix, "WiFi", getWifiControllerActivity(), which);
Adam Lesinskie08af192015-03-25 16:42:59 -07004175
Adam Lesinski50e47602015-12-04 17:04:54 -08004176 pw.print(prefix);
4177 pw.print(" Bluetooth total received: "); pw.print(formatBytesLocked(btRxTotalBytes));
4178 pw.print(", sent: "); pw.println(formatBytesLocked(btTxTotalBytes));
4179
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004180 final long bluetoothScanTimeMs = getBluetoothScanTime(rawRealtime, which) / 1000;
4181 sb.setLength(0);
4182 sb.append(prefix);
4183 sb.append(" Bluetooth scan time: "); formatTimeMs(sb, bluetoothScanTimeMs);
4184 pw.println(sb.toString());
4185
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004186 printControllerActivity(pw, sb, prefix, "Bluetooth", getBluetoothControllerActivity(),
4187 which);
Adam Lesinskie283d332015-04-16 12:29:25 -07004188
Dianne Hackbornca1bf212014-02-14 14:18:36 -08004189 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004190
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004191 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07004192 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004193 pw.print(prefix); pw.println(" Device is currently unplugged");
Bookatzc8c44962017-05-11 12:12:54 -07004194 pw.print(prefix); pw.print(" Discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004195 pw.println(getDischargeStartLevel());
4196 pw.print(prefix); pw.print(" Discharge cycle current level: ");
4197 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07004198 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004199 pw.print(prefix); pw.println(" Device is currently plugged into power");
Bookatzc8c44962017-05-11 12:12:54 -07004200 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004201 pw.println(getDischargeStartLevel());
Bookatzc8c44962017-05-11 12:12:54 -07004202 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004203 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07004204 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004205 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4206 pw.println(getDischargeAmountScreenOn());
4207 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4208 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07004209 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004210 } else {
4211 pw.print(prefix); pw.println(" Device battery use since last full charge");
4212 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
4213 pw.println(getLowDischargeAmountSinceCharge());
4214 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
4215 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08004216 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
4217 pw.println(getDischargeAmountScreenOnSinceCharge());
4218 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
4219 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08004220 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07004221 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004222
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004223 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004224 helper.create(this);
4225 helper.refreshStats(which, UserHandle.USER_ALL);
4226 List<BatterySipper> sippers = helper.getUsageList();
4227 if (sippers != null && sippers.size() > 0) {
4228 pw.print(prefix); pw.println(" Estimated power use (mAh):");
4229 pw.print(prefix); pw.print(" Capacity: ");
4230 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08004231 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07004232 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
4233 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
4234 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
4235 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004236 pw.println();
4237 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004238 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004239 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004240 switch (bs.drainType) {
4241 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004242 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004243 break;
4244 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004245 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004246 break;
4247 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004248 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004249 break;
4250 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004251 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004252 break;
4253 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004254 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004255 break;
4256 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004257 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004258 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004259 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004260 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07004261 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004262 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004263 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004264 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004265 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004266 break;
4267 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004268 pw.print(" User "); pw.print(bs.userId);
4269 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004270 break;
4271 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004272 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004273 break;
4274 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004275 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004276 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004277 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004278 pw.print(" Camera: ");
4279 break;
4280 default:
4281 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07004282 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004283 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004284 printmAh(pw, bs.totalPowerMah);
4285
Adam Lesinski57123002015-06-12 16:12:07 -07004286 if (bs.usagePowerMah != bs.totalPowerMah) {
4287 // If the usage (generic power) isn't the whole amount, we list out
4288 // what components are involved in the calculation.
4289
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004290 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07004291 if (bs.usagePowerMah != 0) {
4292 pw.print(" usage=");
4293 printmAh(pw, bs.usagePowerMah);
4294 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004295 if (bs.cpuPowerMah != 0) {
4296 pw.print(" cpu=");
4297 printmAh(pw, bs.cpuPowerMah);
4298 }
4299 if (bs.wakeLockPowerMah != 0) {
4300 pw.print(" wake=");
4301 printmAh(pw, bs.wakeLockPowerMah);
4302 }
4303 if (bs.mobileRadioPowerMah != 0) {
4304 pw.print(" radio=");
4305 printmAh(pw, bs.mobileRadioPowerMah);
4306 }
4307 if (bs.wifiPowerMah != 0) {
4308 pw.print(" wifi=");
4309 printmAh(pw, bs.wifiPowerMah);
4310 }
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004311 if (bs.bluetoothPowerMah != 0) {
4312 pw.print(" bt=");
4313 printmAh(pw, bs.bluetoothPowerMah);
4314 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07004315 if (bs.gpsPowerMah != 0) {
4316 pw.print(" gps=");
4317 printmAh(pw, bs.gpsPowerMah);
4318 }
4319 if (bs.sensorPowerMah != 0) {
4320 pw.print(" sensor=");
4321 printmAh(pw, bs.sensorPowerMah);
4322 }
4323 if (bs.cameraPowerMah != 0) {
4324 pw.print(" camera=");
4325 printmAh(pw, bs.cameraPowerMah);
4326 }
4327 if (bs.flashlightPowerMah != 0) {
4328 pw.print(" flash=");
4329 printmAh(pw, bs.flashlightPowerMah);
4330 }
4331 pw.print(" )");
4332 }
4333 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004334 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08004335 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08004336 }
4337
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004338 sippers = helper.getMobilemsppList();
4339 if (sippers != null && sippers.size() > 0) {
4340 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004341 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004342 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004343 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004344 sb.setLength(0);
4345 sb.append(prefix); sb.append(" Uid ");
4346 UserHandle.formatUid(sb, bs.uidObj.getUid());
4347 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
4348 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
4349 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004350 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004351 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004352 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004353 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08004354 sb.setLength(0);
4355 sb.append(prefix);
4356 sb.append(" TOTAL TIME: ");
4357 formatTimeMs(sb, totalTime);
4358 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
4359 sb.append(")");
4360 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004361 pw.println();
4362 }
4363
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004364 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
4365 @Override
4366 public int compare(TimerEntry lhs, TimerEntry rhs) {
4367 long lhsTime = lhs.mTime;
4368 long rhsTime = rhs.mTime;
4369 if (lhsTime < rhsTime) {
4370 return 1;
4371 }
4372 if (lhsTime > rhsTime) {
4373 return -1;
4374 }
4375 return 0;
4376 }
4377 };
4378
4379 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004380 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
4381 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004382 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004383 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
4384 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
4385 : kernelWakelocks.entrySet()) {
4386 final BatteryStats.Timer timer = ent.getValue();
4387 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004388 if (totalTimeMillis > 0) {
4389 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
4390 }
4391 }
4392 if (ktimers.size() > 0) {
4393 Collections.sort(ktimers, timerComparator);
4394 pw.print(prefix); pw.println(" All kernel wake locks:");
4395 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004396 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004397 String linePrefix = ": ";
4398 sb.setLength(0);
4399 sb.append(prefix);
4400 sb.append(" Kernel Wake lock ");
4401 sb.append(timer.mName);
4402 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
4403 which, linePrefix);
4404 if (!linePrefix.equals(": ")) {
4405 sb.append(" realtime");
4406 // Only print out wake locks that were held
4407 pw.println(sb.toString());
4408 }
4409 }
4410 pw.println();
4411 }
4412 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004413
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004414 if (timers.size() > 0) {
4415 Collections.sort(timers, timerComparator);
4416 pw.print(prefix); pw.println(" All partial wake locks:");
4417 for (int i=0; i<timers.size(); i++) {
4418 TimerEntry timer = timers.get(i);
4419 sb.setLength(0);
4420 sb.append(" Wake lock ");
4421 UserHandle.formatUid(sb, timer.mId);
4422 sb.append(" ");
4423 sb.append(timer.mName);
4424 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4425 sb.append(" realtime");
4426 pw.println(sb.toString());
4427 }
4428 timers.clear();
4429 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08004430 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004431
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004432 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004433 if (wakeupReasons.size() > 0) {
4434 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004435 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004436 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004437 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004438 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
4439 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004440 }
4441 Collections.sort(reasons, timerComparator);
4442 for (int i=0; i<reasons.size(); i++) {
4443 TimerEntry timer = reasons.get(i);
4444 String linePrefix = ": ";
4445 sb.setLength(0);
4446 sb.append(prefix);
4447 sb.append(" Wakeup reason ");
4448 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07004449 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
4450 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004451 pw.println(sb.toString());
4452 }
4453 pw.println();
4454 }
Dianne Hackborn81038902012-11-26 17:04:09 -08004455 }
Evan Millar22ac0432009-03-31 11:33:18 -07004456
James Carr2dd7e5e2016-07-20 18:48:39 -07004457 final LongSparseArray<? extends Timer> mMemoryStats = getKernelMemoryStats();
4458 pw.println("Memory Stats");
4459 for (int i = 0; i < mMemoryStats.size(); i++) {
4460 sb.setLength(0);
4461 sb.append("Bandwidth ");
4462 sb.append(mMemoryStats.keyAt(i));
4463 sb.append(" Time ");
4464 sb.append(mMemoryStats.valueAt(i).getTotalTimeLocked(rawRealtime, which));
4465 pw.println(sb.toString());
4466 }
4467
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004468 final long[] cpuFreqs = getCpuFreqs();
4469 if (cpuFreqs != null) {
4470 sb.setLength(0);
4471 sb.append("CPU freqs:");
4472 for (int i = 0; i < cpuFreqs.length; ++i) {
4473 sb.append(" " + cpuFreqs[i]);
4474 }
4475 pw.println(sb.toString());
4476 }
4477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004478 for (int iu=0; iu<NU; iu++) {
4479 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08004480 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08004481 continue;
4482 }
Bookatzc8c44962017-05-11 12:12:54 -07004483
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004484 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07004485
4486 pw.print(prefix);
4487 pw.print(" ");
4488 UserHandle.formatUid(pw, uid);
4489 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004490 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004491
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004492 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
4493 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
4494 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
4495 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004496 final long btRxBytes = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
4497 final long btTxBytes = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
4498
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004499 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
4500 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004501 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
4502 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Adam Lesinski50e47602015-12-04 17:04:54 -08004503
4504 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
4505 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
4506
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004507 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
4508 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
4509 final int wifiScanCount = u.getWifiScanCount(which);
Bookatz867c0d72017-03-07 18:23:42 -08004510 final int wifiScanCountBg = u.getWifiScanBackgroundCount(which);
4511 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4512 final long wifiScanActualTime = u.getWifiScanActualTime(rawRealtime);
4513 final long wifiScanActualTimeBg = u.getWifiScanBackgroundTime(rawRealtime);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004514 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004515
Adam Lesinski5f056f62016-07-14 16:56:08 -07004516 final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
4517 final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
4518
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004519 if (mobileRxBytes > 0 || mobileTxBytes > 0
4520 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004521 pw.print(prefix); pw.print(" Mobile network: ");
4522 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004523 pw.print(formatBytesLocked(mobileTxBytes));
4524 pw.print(" sent (packets "); pw.print(mobileRxPackets);
4525 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004526 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004527 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
4528 sb.setLength(0);
4529 sb.append(prefix); sb.append(" Mobile radio active: ");
4530 formatTimeMs(sb, uidMobileActiveTime / 1000);
4531 sb.append("(");
4532 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
4533 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
4534 long packets = mobileRxPackets + mobileTxPackets;
4535 if (packets == 0) {
4536 packets = 1;
4537 }
4538 sb.append(" @ ");
4539 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
4540 sb.append(" mspp");
4541 pw.println(sb.toString());
4542 }
4543
Adam Lesinski5f056f62016-07-14 16:56:08 -07004544 if (mobileWakeup > 0) {
4545 sb.setLength(0);
4546 sb.append(prefix);
4547 sb.append(" Mobile radio AP wakeups: ");
4548 sb.append(mobileWakeup);
4549 pw.println(sb.toString());
4550 }
4551
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004552 printControllerActivityIfInteresting(pw, sb, prefix + " ", "Modem",
4553 u.getModemControllerActivity(), which);
4554
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004555 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004556 pw.print(prefix); pw.print(" Wi-Fi network: ");
4557 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004558 pw.print(formatBytesLocked(wifiTxBytes));
4559 pw.print(" sent (packets "); pw.print(wifiRxPackets);
4560 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07004561 }
4562
Dianne Hackborn62793e42015-03-09 11:15:41 -07004563 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Bookatz867c0d72017-03-07 18:23:42 -08004564 || wifiScanCountBg != 0 || wifiScanActualTime != 0 || wifiScanActualTimeBg != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004565 || uidWifiRunningTime != 0) {
4566 sb.setLength(0);
4567 sb.append(prefix); sb.append(" Wifi Running: ");
4568 formatTimeMs(sb, uidWifiRunningTime / 1000);
4569 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
4570 whichBatteryRealtime)); sb.append(")\n");
Bookatzc8c44962017-05-11 12:12:54 -07004571 sb.append(prefix); sb.append(" Full Wifi Lock: ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004572 formatTimeMs(sb, fullWifiLockOnTime / 1000);
4573 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
4574 whichBatteryRealtime)); sb.append(")\n");
Bookatz867c0d72017-03-07 18:23:42 -08004575 sb.append(prefix); sb.append(" Wifi Scan (blamed): ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004576 formatTimeMs(sb, wifiScanTime / 1000);
4577 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07004578 whichBatteryRealtime)); sb.append(") ");
4579 sb.append(wifiScanCount);
Bookatz867c0d72017-03-07 18:23:42 -08004580 sb.append("x\n");
4581 // actual and background times are unpooled and since reset (regardless of 'which')
4582 sb.append(prefix); sb.append(" Wifi Scan (actual): ");
4583 formatTimeMs(sb, wifiScanActualTime / 1000);
4584 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTime,
4585 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4586 sb.append(") ");
4587 sb.append(wifiScanCount);
4588 sb.append("x\n");
4589 sb.append(prefix); sb.append(" Background Wifi Scan: ");
4590 formatTimeMs(sb, wifiScanActualTimeBg / 1000);
4591 sb.append("("); sb.append(formatRatioLocked(wifiScanActualTimeBg,
4592 computeBatteryRealtime(rawRealtime, STATS_SINCE_CHARGED)));
4593 sb.append(") ");
4594 sb.append(wifiScanCountBg);
Dianne Hackborn62793e42015-03-09 11:15:41 -07004595 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08004596 pw.println(sb.toString());
4597 }
4598
Adam Lesinski5f056f62016-07-14 16:56:08 -07004599 if (wifiWakeup > 0) {
4600 sb.setLength(0);
4601 sb.append(prefix);
4602 sb.append(" WiFi AP wakeups: ");
4603 sb.append(wifiWakeup);
4604 pw.println(sb.toString());
4605 }
4606
Adam Lesinski21f76aa2016-01-25 12:27:06 -08004607 printControllerActivityIfInteresting(pw, sb, prefix + " ", "WiFi",
4608 u.getWifiControllerActivity(), which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07004609
Adam Lesinski50e47602015-12-04 17:04:54 -08004610 if (btRxBytes > 0 || btTxBytes > 0) {
4611 pw.print(prefix); pw.print(" Bluetooth network: ");
4612 pw.print(formatBytesLocked(btRxBytes)); pw.print(" received, ");
4613 pw.print(formatBytesLocked(btTxBytes));
4614 pw.println(" sent");
4615 }
4616
Bookatz867c0d72017-03-07 18:23:42 -08004617 final Timer bleTimer = u.getBluetoothScanTimer();
4618 if (bleTimer != null) {
4619 // Convert from microseconds to milliseconds with rounding
4620 final long totalTimeMs = (bleTimer.getTotalTimeLocked(rawRealtime, which) + 500)
4621 / 1000;
4622 if (totalTimeMs != 0) {
4623 final int count = bleTimer.getCountLocked(which);
4624 final Timer bleTimerBg = u.getBluetoothScanBackgroundTimer();
4625 final int countBg = bleTimerBg != null ? bleTimerBg.getCountLocked(which) : 0;
4626 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
4627 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4628 final long actualTimeMs = bleTimer.getTotalDurationMsLocked(rawRealtimeMs);
4629 final long actualTimeMsBg = bleTimerBg != null ?
4630 bleTimerBg.getTotalDurationMsLocked(rawRealtimeMs) : 0;
Bookatz956f36bf2017-04-28 09:48:17 -07004631 final int resultCount = u.getBluetoothScanResultCounter() != null ?
4632 u.getBluetoothScanResultCounter().getCountLocked(which) : 0;
Bookatz867c0d72017-03-07 18:23:42 -08004633
4634 sb.setLength(0);
4635 sb.append(prefix);
4636 sb.append(" ");
4637 sb.append("Bluetooth Scan");
4638 sb.append(": ");
4639 if (actualTimeMs != totalTimeMs) {
4640 formatTimeMs(sb, totalTimeMs);
4641 sb.append("blamed realtime, ");
4642 }
4643 formatTimeMs(sb, actualTimeMs); // since reset, regardless of 'which'
4644 sb.append("realtime (");
4645 sb.append(count);
4646 sb.append(" times)");
4647 if (bleTimer.isRunningLocked()) {
4648 sb.append(" (running)");
4649 }
4650 if (actualTimeMsBg != 0 || countBg > 0) {
4651 sb.append(", ");
4652 formatTimeMs(sb, actualTimeMsBg); // since reset, regardless of 'which'
4653 sb.append("background (");
4654 sb.append(countBg);
4655 sb.append(" times)");
4656 }
Bookatz956f36bf2017-04-28 09:48:17 -07004657 sb.append("; Results count ");
4658 sb.append(resultCount);
Bookatz867c0d72017-03-07 18:23:42 -08004659 pw.println(sb.toString());
4660 uidActivity = true;
4661 }
4662 }
4663
4664
Adam Lesinski9f55cc72016-01-27 20:42:14 -08004665
Dianne Hackborn617f8772009-03-31 15:04:46 -07004666 if (u.hasUserActivity()) {
4667 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07004668 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004669 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07004670 if (val != 0) {
4671 if (!hasData) {
4672 sb.setLength(0);
4673 sb.append(" User activity: ");
4674 hasData = true;
4675 } else {
4676 sb.append(", ");
4677 }
4678 sb.append(val);
4679 sb.append(" ");
4680 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
4681 }
4682 }
4683 if (hasData) {
4684 pw.println(sb.toString());
4685 }
4686 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004687
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004688 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
4689 = u.getWakelockStats();
4690 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004691 long totalDrawWakelock = 0;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004692 int countWakelock = 0;
4693 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
4694 final Uid.Wakelock wl = wakelocks.valueAt(iw);
4695 String linePrefix = ": ";
4696 sb.setLength(0);
4697 sb.append(prefix);
4698 sb.append(" Wake lock ");
4699 sb.append(wakelocks.keyAt(iw));
4700 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
4701 "full", which, linePrefix);
4702 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
4703 "partial", which, linePrefix);
4704 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
4705 "window", which, linePrefix);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004706 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DRAW), rawRealtime,
4707 "draw", which, linePrefix);
Adam Lesinski9425fe22015-06-19 12:02:13 -07004708 sb.append(" realtime");
4709 pw.println(sb.toString());
4710 uidActivity = true;
4711 countWakelock++;
4712
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004713 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
4714 rawRealtime, which);
4715 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
4716 rawRealtime, which);
4717 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
4718 rawRealtime, which);
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004719 totalDrawWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DRAW),
Adam Lesinski9425fe22015-06-19 12:02:13 -07004720 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004721 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004722 if (countWakelock > 1) {
Bookatzc8c44962017-05-11 12:12:54 -07004723 // get unpooled partial wakelock quantities (unlike totalPartialWakelock, which is
4724 // pooled and therefore just a lower bound)
4725 long actualTotalPartialWakelock = 0;
4726 long actualBgPartialWakelock = 0;
4727 if (u.getAggregatedPartialWakelockTimer() != null) {
4728 final Timer aggTimer = u.getAggregatedPartialWakelockTimer();
4729 // Convert from microseconds to milliseconds with rounding
4730 actualTotalPartialWakelock =
4731 (aggTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4732 final Timer bgAggTimer = aggTimer.getSubTimer();
4733 actualBgPartialWakelock = bgAggTimer != null ?
4734 (bgAggTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : 0;
4735 }
4736
4737 if (actualTotalPartialWakelock != 0 || actualBgPartialWakelock != 0 ||
4738 totalFullWakelock != 0 || totalPartialWakelock != 0 ||
4739 totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004740 sb.setLength(0);
4741 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004742 sb.append(" TOTAL wake: ");
4743 boolean needComma = false;
4744 if (totalFullWakelock != 0) {
4745 needComma = true;
4746 formatTimeMs(sb, totalFullWakelock);
4747 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004748 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004749 if (totalPartialWakelock != 0) {
4750 if (needComma) {
4751 sb.append(", ");
4752 }
4753 needComma = true;
4754 formatTimeMs(sb, totalPartialWakelock);
Bookatzc8c44962017-05-11 12:12:54 -07004755 sb.append("blamed partial");
4756 }
4757 if (actualTotalPartialWakelock != 0) {
4758 if (needComma) {
4759 sb.append(", ");
4760 }
4761 needComma = true;
4762 formatTimeMs(sb, actualTotalPartialWakelock);
4763 sb.append("actual partial");
4764 }
4765 if (actualBgPartialWakelock != 0) {
4766 if (needComma) {
4767 sb.append(", ");
4768 }
4769 needComma = true;
4770 formatTimeMs(sb, actualBgPartialWakelock);
4771 sb.append("actual background partial");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004772 }
4773 if (totalWindowWakelock != 0) {
4774 if (needComma) {
4775 sb.append(", ");
4776 }
4777 needComma = true;
4778 formatTimeMs(sb, totalWindowWakelock);
4779 sb.append("window");
4780 }
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004781 if (totalDrawWakelock != 0) {
Adam Lesinski9425fe22015-06-19 12:02:13 -07004782 if (needComma) {
4783 sb.append(",");
4784 }
4785 needComma = true;
Jeff Brown6a8bd7b2015-06-19 15:07:51 -07004786 formatTimeMs(sb, totalDrawWakelock);
4787 sb.append("draw");
Adam Lesinski9425fe22015-06-19 12:02:13 -07004788 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004789 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004790 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07004791 }
4792 }
4793
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004794 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
4795 for (int isy=syncs.size()-1; isy>=0; isy--) {
4796 final Timer timer = syncs.valueAt(isy);
4797 // Convert from microseconds to milliseconds with rounding
4798 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4799 final int count = timer.getCountLocked(which);
Bookatz2bffb5b2017-04-13 11:59:33 -07004800 final Timer bgTimer = timer.getSubTimer();
4801 final long bgTime = bgTimer != null ?
4802 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
4803 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004804 sb.setLength(0);
4805 sb.append(prefix);
4806 sb.append(" Sync ");
4807 sb.append(syncs.keyAt(isy));
4808 sb.append(": ");
4809 if (totalTime != 0) {
4810 formatTimeMs(sb, totalTime);
4811 sb.append("realtime (");
4812 sb.append(count);
4813 sb.append(" times)");
Bookatz2bffb5b2017-04-13 11:59:33 -07004814 if (bgTime > 0) {
4815 sb.append(", ");
4816 formatTimeMs(sb, bgTime);
4817 sb.append("background (");
4818 sb.append(bgCount);
4819 sb.append(" times)");
4820 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004821 } else {
4822 sb.append("(not used)");
4823 }
4824 pw.println(sb.toString());
4825 uidActivity = true;
4826 }
4827
4828 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
4829 for (int ij=jobs.size()-1; ij>=0; ij--) {
4830 final Timer timer = jobs.valueAt(ij);
4831 // Convert from microseconds to milliseconds with rounding
4832 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
4833 final int count = timer.getCountLocked(which);
Bookatzaa4594a2017-03-24 12:39:56 -07004834 final Timer bgTimer = timer.getSubTimer();
4835 final long bgTime = bgTimer != null ?
4836 (bgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000 : -1;
4837 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : -1;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004838 sb.setLength(0);
4839 sb.append(prefix);
4840 sb.append(" Job ");
4841 sb.append(jobs.keyAt(ij));
4842 sb.append(": ");
4843 if (totalTime != 0) {
4844 formatTimeMs(sb, totalTime);
4845 sb.append("realtime (");
4846 sb.append(count);
4847 sb.append(" times)");
Bookatzaa4594a2017-03-24 12:39:56 -07004848 if (bgTime > 0) {
4849 sb.append(", ");
4850 formatTimeMs(sb, bgTime);
4851 sb.append("background (");
4852 sb.append(bgCount);
4853 sb.append(" times)");
4854 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004855 } else {
4856 sb.append("(not used)");
4857 }
4858 pw.println(sb.toString());
4859 uidActivity = true;
4860 }
4861
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004862 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
4863 prefix, "Flashlight");
4864 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
4865 prefix, "Camera");
4866 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
4867 prefix, "Video");
4868 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
4869 prefix, "Audio");
4870
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004871 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
4872 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004873 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004874 final Uid.Sensor se = sensors.valueAt(ise);
4875 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004876 sb.setLength(0);
4877 sb.append(prefix);
4878 sb.append(" Sensor ");
4879 int handle = se.getHandle();
4880 if (handle == Uid.Sensor.GPS) {
4881 sb.append("GPS");
4882 } else {
4883 sb.append(handle);
4884 }
4885 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004886
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004887 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07004888 if (timer != null) {
4889 // Convert from microseconds to milliseconds with rounding
Bookatz867c0d72017-03-07 18:23:42 -08004890 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
4891 / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004892 final int count = timer.getCountLocked(which);
Bookatz867c0d72017-03-07 18:23:42 -08004893 final Timer bgTimer = se.getSensorBackgroundTime();
4894 final int bgCount = bgTimer != null ? bgTimer.getCountLocked(which) : 0;
4895 final long rawRealtimeMs = (rawRealtime + 500) / 1000;
4896 // 'actualTime' are unpooled and always since reset (regardless of 'which')
4897 final long actualTime = timer.getTotalDurationMsLocked(rawRealtimeMs);
4898 final long bgActualTime = bgTimer != null ?
4899 bgTimer.getTotalDurationMsLocked(rawRealtimeMs) : 0;
4900
Dianne Hackborn61659e52014-07-09 16:13:01 -07004901 //timer.logState();
4902 if (totalTime != 0) {
Bookatz867c0d72017-03-07 18:23:42 -08004903 if (actualTime != totalTime) {
4904 formatTimeMs(sb, totalTime);
4905 sb.append("blamed realtime, ");
4906 }
4907
4908 formatTimeMs(sb, actualTime); // since reset, regardless of 'which'
Dianne Hackborn61659e52014-07-09 16:13:01 -07004909 sb.append("realtime (");
4910 sb.append(count);
Bookatz867c0d72017-03-07 18:23:42 -08004911 sb.append(" times)");
4912
4913 if (bgActualTime != 0 || bgCount > 0) {
Amith Yamasaniab9ad192016-12-06 12:46:59 -08004914 sb.append(", ");
Bookatz867c0d72017-03-07 18:23:42 -08004915 formatTimeMs(sb, bgActualTime); // since reset, regardless of 'which'
4916 sb.append("background (");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08004917 sb.append(bgCount);
Bookatz867c0d72017-03-07 18:23:42 -08004918 sb.append(" times)");
Amith Yamasaniab9ad192016-12-06 12:46:59 -08004919 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004920 } else {
4921 sb.append("(not used)");
4922 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004923 } else {
4924 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004925 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004926
4927 pw.println(sb.toString());
4928 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004929 }
4930
Ruben Brunk6d2c3632015-05-26 17:32:16 -07004931 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
4932 "Vibrator");
4933 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
4934 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07004935
Dianne Hackborn61659e52014-07-09 16:13:01 -07004936 long totalStateTime = 0;
4937 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4938 long time = u.getProcessStateTime(ips, rawRealtime, which);
4939 if (time > 0) {
4940 totalStateTime += time;
4941 sb.setLength(0);
4942 sb.append(prefix);
4943 sb.append(" ");
4944 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4945 sb.append(" for: ");
Dianne Hackborna8d10942015-11-19 17:55:19 -08004946 formatTimeMs(sb, (time + 500) / 1000);
Dianne Hackborn61659e52014-07-09 16:13:01 -07004947 pw.println(sb.toString());
4948 uidActivity = true;
4949 }
4950 }
Dianne Hackborna8d10942015-11-19 17:55:19 -08004951 if (totalStateTime > 0) {
4952 sb.setLength(0);
4953 sb.append(prefix);
4954 sb.append(" Total running: ");
4955 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4956 pw.println(sb.toString());
4957 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07004958
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004959 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4960 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
Adam Lesinskid4abd1e2017-04-12 11:29:13 -07004961 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004962 sb.setLength(0);
4963 sb.append(prefix);
Adam Lesinski72478f02015-06-17 15:39:43 -07004964 sb.append(" Total cpu time: u=");
4965 formatTimeMs(sb, userCpuTimeUs / 1000);
4966 sb.append("s=");
4967 formatTimeMs(sb, systemCpuTimeUs / 1000);
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004968 pw.println(sb.toString());
4969 }
4970
Sudheer Shanka9b735c52017-05-09 18:26:18 -07004971 final long[] cpuFreqTimes = u.getCpuFreqTimes(which);
4972 if (cpuFreqTimes != null) {
4973 sb.setLength(0);
4974 sb.append(" Total cpu time per freq:");
4975 for (int i = 0; i < cpuFreqTimes.length; ++i) {
4976 sb.append(" " + cpuFreqTimes[i]);
4977 }
4978 pw.println(sb.toString());
4979 }
4980 final long[] screenOffCpuFreqTimes = u.getScreenOffCpuFreqTimes(which);
4981 if (screenOffCpuFreqTimes != null) {
4982 sb.setLength(0);
4983 sb.append(" Total screen-off cpu time per freq:");
4984 for (int i = 0; i < screenOffCpuFreqTimes.length; ++i) {
4985 sb.append(" " + screenOffCpuFreqTimes[i]);
4986 }
4987 pw.println(sb.toString());
4988 }
4989
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004990 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4991 = u.getProcessStats();
4992 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4993 final Uid.Proc ps = processStats.valueAt(ipr);
4994 long userTime;
4995 long systemTime;
4996 long foregroundTime;
4997 int starts;
4998 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004999
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005000 userTime = ps.getUserTime(which);
5001 systemTime = ps.getSystemTime(which);
5002 foregroundTime = ps.getForegroundTime(which);
5003 starts = ps.getStarts(which);
5004 final int numCrashes = ps.getNumCrashes(which);
5005 final int numAnrs = ps.getNumAnrs(which);
5006 numExcessive = which == STATS_SINCE_CHARGED
5007 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005008
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005009 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
5010 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
5011 sb.setLength(0);
5012 sb.append(prefix); sb.append(" Proc ");
5013 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
5014 sb.append(prefix); sb.append(" CPU: ");
5015 formatTimeMs(sb, userTime); sb.append("usr + ");
5016 formatTimeMs(sb, systemTime); sb.append("krn ; ");
5017 formatTimeMs(sb, foregroundTime); sb.append("fg");
5018 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
5019 sb.append("\n"); sb.append(prefix); sb.append(" ");
5020 boolean hasOne = false;
5021 if (starts != 0) {
5022 hasOne = true;
5023 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07005024 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005025 if (numCrashes != 0) {
5026 if (hasOne) {
5027 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005028 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005029 hasOne = true;
5030 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07005031 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005032 if (numAnrs != 0) {
5033 if (hasOne) {
5034 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005035 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005036 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005037 }
5038 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005039 pw.println(sb.toString());
5040 for (int e=0; e<numExcessive; e++) {
5041 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
5042 if (ew != null) {
5043 pw.print(prefix); pw.print(" * Killed for ");
5044 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
5045 pw.print("wake lock");
5046 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
5047 pw.print("cpu");
5048 } else {
5049 pw.print("unknown");
5050 }
5051 pw.print(" use: ");
5052 TimeUtils.formatDuration(ew.usedTime, pw);
5053 pw.print(" over ");
5054 TimeUtils.formatDuration(ew.overTime, pw);
5055 if (ew.overTime != 0) {
5056 pw.print(" (");
5057 pw.print((ew.usedTime*100)/ew.overTime);
5058 pw.println("%)");
5059 }
5060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005061 }
5062 uidActivity = true;
5063 }
5064 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005065
5066 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
5067 = u.getPackageStats();
5068 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
5069 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
5070 pw.println(":");
5071 boolean apkActivity = false;
5072 final Uid.Pkg ps = packageStats.valueAt(ipkg);
5073 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
5074 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
5075 pw.print(prefix); pw.print(" Wakeup alarm ");
5076 pw.print(alarms.keyAt(iwa)); pw.print(": ");
5077 pw.print(alarms.valueAt(iwa).getCountLocked(which));
5078 pw.println(" times");
5079 apkActivity = true;
5080 }
5081 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
5082 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
5083 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
5084 final long startTime = ss.getStartTime(batteryUptime, which);
5085 final int starts = ss.getStarts(which);
5086 final int launches = ss.getLaunches(which);
5087 if (startTime != 0 || starts != 0 || launches != 0) {
5088 sb.setLength(0);
5089 sb.append(prefix); sb.append(" Service ");
5090 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
5091 sb.append(prefix); sb.append(" Created for: ");
5092 formatTimeMs(sb, startTime / 1000);
5093 sb.append("uptime\n");
5094 sb.append(prefix); sb.append(" Starts: ");
5095 sb.append(starts);
5096 sb.append(", launches: "); sb.append(launches);
5097 pw.println(sb.toString());
5098 apkActivity = true;
5099 }
5100 }
5101 if (!apkActivity) {
5102 pw.print(prefix); pw.println(" (nothing executed)");
5103 }
5104 uidActivity = true;
5105 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005106 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07005107 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005108 }
5109 }
5110 }
5111
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005112 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005113 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005114 int diff = oldval ^ newval;
5115 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005116 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005117 for (int i=0; i<descriptions.length; i++) {
5118 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005119 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005120 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005121 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005122 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005123 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005124 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
5125 didWake = true;
5126 pw.print("=");
5127 if (longNames) {
5128 UserHandle.formatUid(pw, wakelockTag.uid);
5129 pw.print(":\"");
5130 pw.print(wakelockTag.string);
5131 pw.print("\"");
5132 } else {
5133 pw.print(wakelockTag.poolIdx);
5134 }
5135 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005136 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005137 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005138 pw.print("=");
5139 int val = (newval&bd.mask)>>bd.shift;
5140 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005141 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005142 } else {
5143 pw.print(val);
5144 }
5145 }
5146 }
5147 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005148 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07005149 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005150 if (longNames) {
5151 UserHandle.formatUid(pw, wakelockTag.uid);
5152 pw.print(":\"");
5153 pw.print(wakelockTag.string);
5154 pw.print("\"");
5155 } else {
5156 pw.print(wakelockTag.poolIdx);
5157 }
5158 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07005159 }
5160
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005161 public void prepareForDumpLocked() {
5162 }
5163
5164 public static class HistoryPrinter {
5165 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005166 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005167 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005168 int oldStatus = -1;
5169 int oldHealth = -1;
5170 int oldPlug = -1;
5171 int oldTemp = -1;
5172 int oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005173 int oldChargeMAh = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005174 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005175
Dianne Hackborn3251b902014-06-20 14:40:53 -07005176 void reset() {
5177 oldState = oldState2 = 0;
5178 oldLevel = -1;
5179 oldStatus = -1;
5180 oldHealth = -1;
5181 oldPlug = -1;
5182 oldTemp = -1;
5183 oldVolt = -1;
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005184 oldChargeMAh = -1;
Dianne Hackborn3251b902014-06-20 14:40:53 -07005185 }
5186
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005187 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005188 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005189 if (!checkin) {
5190 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005191 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005192 pw.print(" (");
5193 pw.print(rec.numReadInts);
5194 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005195 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005196 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5197 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005198 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005199 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005200 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005201 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005202 }
5203 lastTime = rec.time;
5204 }
5205 if (rec.cmd == HistoryItem.CMD_START) {
5206 if (checkin) {
5207 pw.print(":");
5208 }
5209 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005210 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005211 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
5212 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005213 if (checkin) {
5214 pw.print(":");
5215 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005216 if (rec.cmd == HistoryItem.CMD_RESET) {
5217 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07005218 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005219 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005220 pw.print("TIME:");
5221 if (checkin) {
5222 pw.println(rec.currentTime);
5223 } else {
5224 pw.print(" ");
5225 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5226 rec.currentTime).toString());
5227 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005228 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
5229 if (checkin) {
5230 pw.print(":");
5231 }
5232 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005233 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
5234 if (checkin) {
5235 pw.print(":");
5236 }
5237 pw.println("*OVERFLOW*");
5238 } else {
5239 if (!checkin) {
5240 if (rec.batteryLevel < 10) pw.print("00");
5241 else if (rec.batteryLevel < 100) pw.print("0");
5242 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005243 if (verbose) {
5244 pw.print(" ");
5245 if (rec.states < 0) ;
5246 else if (rec.states < 0x10) pw.print("0000000");
5247 else if (rec.states < 0x100) pw.print("000000");
5248 else if (rec.states < 0x1000) pw.print("00000");
5249 else if (rec.states < 0x10000) pw.print("0000");
5250 else if (rec.states < 0x100000) pw.print("000");
5251 else if (rec.states < 0x1000000) pw.print("00");
5252 else if (rec.states < 0x10000000) pw.print("0");
5253 pw.print(Integer.toHexString(rec.states));
5254 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005255 } else {
5256 if (oldLevel != rec.batteryLevel) {
5257 oldLevel = rec.batteryLevel;
5258 pw.print(",Bl="); pw.print(rec.batteryLevel);
5259 }
5260 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005261 if (oldStatus != rec.batteryStatus) {
5262 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005263 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005264 switch (oldStatus) {
5265 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005266 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005267 break;
5268 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005269 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005270 break;
5271 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005272 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005273 break;
5274 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005275 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005276 break;
5277 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005278 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005279 break;
5280 default:
5281 pw.print(oldStatus);
5282 break;
5283 }
5284 }
5285 if (oldHealth != rec.batteryHealth) {
5286 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005287 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005288 switch (oldHealth) {
5289 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005290 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005291 break;
5292 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005293 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005294 break;
5295 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005296 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005297 break;
5298 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005299 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005300 break;
5301 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005302 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005303 break;
5304 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005305 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005306 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005307 case BatteryManager.BATTERY_HEALTH_COLD:
5308 pw.print(checkin ? "c" : "cold");
5309 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005310 default:
5311 pw.print(oldHealth);
5312 break;
5313 }
5314 }
5315 if (oldPlug != rec.batteryPlugType) {
5316 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005317 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005318 switch (oldPlug) {
5319 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005320 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005321 break;
5322 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005323 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005324 break;
5325 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005326 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005327 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005328 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005329 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07005330 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005331 default:
5332 pw.print(oldPlug);
5333 break;
5334 }
5335 }
5336 if (oldTemp != rec.batteryTemperature) {
5337 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005338 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005339 pw.print(oldTemp);
5340 }
5341 if (oldVolt != rec.batteryVoltage) {
5342 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005343 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005344 pw.print(oldVolt);
5345 }
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005346 final int chargeMAh = rec.batteryChargeUAh / 1000;
5347 if (oldChargeMAh != chargeMAh) {
5348 oldChargeMAh = chargeMAh;
Adam Lesinski926969b2016-04-28 17:31:12 -07005349 pw.print(checkin ? ",Bcc=" : " charge=");
Adam Lesinskia8018ac2016-05-03 10:18:10 -07005350 pw.print(oldChargeMAh);
Adam Lesinski926969b2016-04-28 17:31:12 -07005351 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005352 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08005353 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07005354 printBitDescriptions(pw, oldState2, rec.states2, null,
5355 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005356 if (rec.wakeReasonTag != null) {
5357 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005358 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005359 pw.print(rec.wakeReasonTag.poolIdx);
5360 } else {
5361 pw.print(" wake_reason=");
5362 pw.print(rec.wakeReasonTag.uid);
5363 pw.print(":\"");
5364 pw.print(rec.wakeReasonTag.string);
5365 pw.print("\"");
5366 }
5367 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08005368 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005369 pw.print(checkin ? "," : " ");
5370 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
5371 pw.print("+");
5372 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
5373 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005374 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08005375 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
5376 : HISTORY_EVENT_NAMES;
5377 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
5378 | HistoryItem.EVENT_FLAG_FINISH);
5379 if (idx >= 0 && idx < eventNames.length) {
5380 pw.print(eventNames[idx]);
5381 } else {
5382 pw.print(checkin ? "Ev" : "event");
5383 pw.print(idx);
5384 }
5385 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005386 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005387 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08005388 } else {
Adam Lesinski041d9172016-12-12 12:03:56 -08005389 pw.append(HISTORY_EVENT_INT_FORMATTERS[idx]
5390 .applyAsString(rec.eventTag.uid));
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005391 pw.print(":\"");
5392 pw.print(rec.eventTag.string);
5393 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08005394 }
5395 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005396 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005397 if (rec.stepDetails != null) {
5398 if (!checkin) {
5399 pw.print(" Details: cpu=");
5400 pw.print(rec.stepDetails.userTime);
5401 pw.print("u+");
5402 pw.print(rec.stepDetails.systemTime);
5403 pw.print("s");
5404 if (rec.stepDetails.appCpuUid1 >= 0) {
5405 pw.print(" (");
5406 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
5407 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
5408 if (rec.stepDetails.appCpuUid2 >= 0) {
5409 pw.print(", ");
5410 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
5411 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
5412 }
5413 if (rec.stepDetails.appCpuUid3 >= 0) {
5414 pw.print(", ");
5415 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
5416 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
5417 }
5418 pw.print(')');
5419 }
5420 pw.println();
5421 pw.print(" /proc/stat=");
5422 pw.print(rec.stepDetails.statUserTime);
5423 pw.print(" usr, ");
5424 pw.print(rec.stepDetails.statSystemTime);
5425 pw.print(" sys, ");
5426 pw.print(rec.stepDetails.statIOWaitTime);
5427 pw.print(" io, ");
5428 pw.print(rec.stepDetails.statIrqTime);
5429 pw.print(" irq, ");
5430 pw.print(rec.stepDetails.statSoftIrqTime);
5431 pw.print(" sirq, ");
5432 pw.print(rec.stepDetails.statIdlTime);
5433 pw.print(" idle");
5434 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
5435 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
5436 + rec.stepDetails.statSoftIrqTime;
5437 int total = totalRun + rec.stepDetails.statIdlTime;
5438 if (total > 0) {
5439 pw.print(" (");
5440 float perc = ((float)totalRun) / ((float)total) * 100;
5441 pw.print(String.format("%.1f%%", perc));
5442 pw.print(" of ");
5443 StringBuilder sb = new StringBuilder(64);
5444 formatTimeMsNoSpace(sb, total*10);
5445 pw.print(sb);
5446 pw.print(")");
5447 }
Badhri Jagan Sridharan68cdf192016-04-03 21:57:15 -07005448 pw.print(", PlatformIdleStat ");
5449 pw.print(rec.stepDetails.statPlatformIdleState);
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005450 pw.println();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005451
5452 pw.print(", SubsystemPowerState ");
5453 pw.print(rec.stepDetails.statSubsystemPowerState);
5454 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005455 } 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();
Ahmed ElArabawyd8b44112017-05-23 21:25:02 +00005492
5493 if (rec.stepDetails.statSubsystemPowerState != null) {
5494 pw.print(rec.stepDetails.statSubsystemPowerState);
5495 }
5496 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005497 }
5498 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005499 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005500 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005501 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005502 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08005503
5504 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
5505 UserHandle.formatUid(pw, uid);
5506 pw.print("=");
5507 pw.print(utime);
5508 pw.print("u+");
5509 pw.print(stime);
5510 pw.print("s");
5511 }
5512
5513 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
5514 pw.print('/');
5515 pw.print(uid);
5516 pw.print(":");
5517 pw.print(utime);
5518 pw.print(":");
5519 pw.print(stime);
5520 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005521 }
5522
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005523 private void printSizeValue(PrintWriter pw, long size) {
5524 float result = size;
5525 String suffix = "";
5526 if (result >= 10*1024) {
5527 suffix = "KB";
5528 result = result / 1024;
5529 }
5530 if (result >= 10*1024) {
5531 suffix = "MB";
5532 result = result / 1024;
5533 }
5534 if (result >= 10*1024) {
5535 suffix = "GB";
5536 result = result / 1024;
5537 }
5538 if (result >= 10*1024) {
5539 suffix = "TB";
5540 result = result / 1024;
5541 }
5542 if (result >= 10*1024) {
5543 suffix = "PB";
5544 result = result / 1024;
5545 }
5546 pw.print((int)result);
5547 pw.print(suffix);
5548 }
5549
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005550 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
5551 String label3, long estimatedTime) {
5552 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005553 return false;
5554 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005555 pw.print(label1);
5556 pw.print(label2);
5557 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005558 StringBuilder sb = new StringBuilder(64);
5559 formatTimeMs(sb, estimatedTime);
5560 pw.print(sb);
5561 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08005562 return true;
5563 }
5564
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005565 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
5566 LevelStepTracker steps, boolean checkin) {
5567 if (steps == null) {
5568 return false;
5569 }
5570 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005571 if (count <= 0) {
5572 return false;
5573 }
5574 if (!checkin) {
5575 pw.println(header);
5576 }
Kweku Adams030980a2015-04-01 16:07:48 -07005577 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005578 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005579 long duration = steps.getDurationAt(i);
5580 int level = steps.getLevelAt(i);
5581 long initMode = steps.getInitModeAt(i);
5582 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005583 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005584 lineArgs[0] = Long.toString(duration);
5585 lineArgs[1] = Integer.toString(level);
5586 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5587 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5588 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
5589 case Display.STATE_ON: lineArgs[2] = "s+"; break;
5590 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
5591 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07005592 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005593 }
5594 } else {
5595 lineArgs[2] = "";
5596 }
5597 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5598 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
5599 } else {
5600 lineArgs[3] = "";
5601 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005602 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07005603 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005604 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07005605 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005606 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005607 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
5608 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005609 pw.print(prefix);
5610 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005611 TimeUtils.formatDuration(duration, pw);
5612 pw.print(" to "); pw.print(level);
5613 boolean haveModes = false;
5614 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
5615 pw.print(" (");
5616 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
5617 case Display.STATE_OFF: pw.print("screen-off"); break;
5618 case Display.STATE_ON: pw.print("screen-on"); break;
5619 case Display.STATE_DOZE: pw.print("screen-doze"); break;
5620 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07005621 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005622 }
5623 haveModes = true;
5624 }
5625 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
5626 pw.print(haveModes ? ", " : " (");
5627 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
5628 ? "power-save-on" : "power-save-off");
5629 haveModes = true;
5630 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005631 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
5632 pw.print(haveModes ? ", " : " (");
5633 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
5634 ? "device-idle-on" : "device-idle-off");
5635 haveModes = true;
5636 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07005637 if (haveModes) {
5638 pw.print(")");
5639 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005640 pw.println();
5641 }
5642 }
5643 return true;
5644 }
5645
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005646 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005647 public static final int DUMP_DAILY_ONLY = 1<<2;
5648 public static final int DUMP_HISTORY_ONLY = 1<<3;
5649 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
5650 public static final int DUMP_VERBOSE = 1<<5;
5651 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005652
Dianne Hackborn37de0982014-05-09 09:32:18 -07005653 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
5654 final HistoryPrinter hprinter = new HistoryPrinter();
5655 final HistoryItem rec = new HistoryItem();
5656 long lastTime = -1;
5657 long baseTime = -1;
5658 boolean printed = false;
5659 HistoryEventTracker tracker = null;
5660 while (getNextHistoryLocked(rec)) {
5661 lastTime = rec.time;
5662 if (baseTime < 0) {
5663 baseTime = lastTime;
5664 }
5665 if (rec.time >= histStart) {
5666 if (histStart >= 0 && !printed) {
5667 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07005668 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08005669 || rec.cmd == HistoryItem.CMD_START
5670 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005671 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005672 hprinter.printNextItem(pw, rec, baseTime, checkin,
5673 (flags&DUMP_VERBOSE) != 0);
5674 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005675 } else if (rec.currentTime != 0) {
5676 printed = true;
5677 byte cmd = rec.cmd;
5678 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005679 hprinter.printNextItem(pw, rec, baseTime, checkin,
5680 (flags&DUMP_VERBOSE) != 0);
5681 rec.cmd = cmd;
5682 }
5683 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005684 if (rec.cmd != HistoryItem.CMD_UPDATE) {
5685 hprinter.printNextItem(pw, rec, baseTime, checkin,
5686 (flags&DUMP_VERBOSE) != 0);
5687 rec.cmd = HistoryItem.CMD_UPDATE;
5688 }
5689 int oldEventCode = rec.eventCode;
5690 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005691 rec.eventTag = new HistoryTag();
5692 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
5693 HashMap<String, SparseIntArray> active
5694 = tracker.getStateForEvent(i);
5695 if (active == null) {
5696 continue;
5697 }
5698 for (HashMap.Entry<String, SparseIntArray> ent
5699 : active.entrySet()) {
5700 SparseIntArray uids = ent.getValue();
5701 for (int j=0; j<uids.size(); j++) {
5702 rec.eventCode = i;
5703 rec.eventTag.string = ent.getKey();
5704 rec.eventTag.uid = uids.keyAt(j);
5705 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07005706 hprinter.printNextItem(pw, rec, baseTime, checkin,
5707 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005708 rec.wakeReasonTag = null;
5709 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005710 }
5711 }
5712 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07005713 rec.eventCode = oldEventCode;
5714 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07005715 tracker = null;
5716 }
5717 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005718 hprinter.printNextItem(pw, rec, baseTime, checkin,
5719 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07005720 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
5721 // This is an attempt to aggregate the previous state and generate
5722 // fake events to reflect that state at the point where we start
5723 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07005724 if (tracker == null) {
5725 tracker = new HistoryEventTracker();
5726 }
5727 tracker.updateState(rec.eventCode, rec.eventTag.string,
5728 rec.eventTag.uid, rec.eventTag.poolIdx);
5729 }
5730 }
5731 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07005732 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07005733 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
5734 }
5735 }
5736
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005737 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
5738 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
5739 if (steps == null) {
5740 return;
5741 }
5742 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
5743 if (timeRemaining >= 0) {
5744 pw.print(prefix); pw.print(label); pw.print(" total time: ");
5745 tmpSb.setLength(0);
5746 formatTimeMs(tmpSb, timeRemaining);
5747 pw.print(tmpSb);
5748 pw.print(" (from "); pw.print(tmpOutInt[0]);
5749 pw.println(" steps)");
5750 }
5751 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5752 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5753 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
5754 if (estimatedTime > 0) {
5755 pw.print(prefix); pw.print(label); pw.print(" ");
5756 pw.print(STEP_LEVEL_MODE_LABELS[i]);
5757 pw.print(" time: ");
5758 tmpSb.setLength(0);
5759 formatTimeMs(tmpSb, estimatedTime);
5760 pw.print(tmpSb);
5761 pw.print(" (from "); pw.print(tmpOutInt[0]);
5762 pw.println(" steps)");
5763 }
5764 }
5765 }
5766
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005767 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
5768 ArrayList<PackageChange> changes) {
5769 if (changes == null) {
5770 return;
5771 }
5772 pw.print(prefix); pw.println("Package changes:");
5773 for (int i=0; i<changes.size(); i++) {
5774 PackageChange pc = changes.get(i);
5775 if (pc.mUpdate) {
5776 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
5777 pw.print(" vers="); pw.println(pc.mVersionCode);
5778 } else {
5779 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
5780 }
5781 }
5782 }
5783
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005784 /**
5785 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
5786 *
5787 * @param pw a Printer to receive the dump output.
5788 */
5789 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005790 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005791 prepareForDumpLocked();
5792
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005793 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005794 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005795
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005796 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005797 final long historyTotalSize = getHistoryTotalSize();
5798 final long historyUsedSize = getHistoryUsedSize();
5799 if (startIteratingHistoryLocked()) {
5800 try {
5801 pw.print("Battery History (");
5802 pw.print((100*historyUsedSize)/historyTotalSize);
5803 pw.print("% used, ");
5804 printSizeValue(pw, historyUsedSize);
5805 pw.print(" used of ");
5806 printSizeValue(pw, historyTotalSize);
5807 pw.print(", ");
5808 pw.print(getHistoryStringPoolSize());
5809 pw.print(" strings using ");
5810 printSizeValue(pw, getHistoryStringPoolBytes());
5811 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07005812 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005813 pw.println();
5814 } finally {
5815 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005816 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005817 }
5818
5819 if (startIteratingOldHistoryLocked()) {
5820 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07005821 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005822 pw.println("Old battery History:");
5823 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005824 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005825 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005826 if (baseTime < 0) {
5827 baseTime = rec.time;
5828 }
5829 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005830 }
5831 pw.println();
5832 } finally {
5833 finishIteratingOldHistoryLocked();
5834 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07005835 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005836 }
5837
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005838 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005839 return;
5840 }
5841
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005842 if (!filtering) {
5843 SparseArray<? extends Uid> uidStats = getUidStats();
5844 final int NU = uidStats.size();
5845 boolean didPid = false;
5846 long nowRealtime = SystemClock.elapsedRealtime();
5847 for (int i=0; i<NU; i++) {
5848 Uid uid = uidStats.valueAt(i);
5849 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
5850 if (pids != null) {
5851 for (int j=0; j<pids.size(); j++) {
5852 Uid.Pid pid = pids.valueAt(j);
5853 if (!didPid) {
5854 pw.println("Per-PID Stats:");
5855 didPid = true;
5856 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08005857 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
5858 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005859 pw.print(" PID "); pw.print(pids.keyAt(j));
5860 pw.print(" wake time: ");
5861 TimeUtils.formatDuration(time, pw);
5862 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005863 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07005864 }
5865 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005866 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005867 pw.println();
5868 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005869 }
5870
5871 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005872 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
5873 getDischargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07005874 long timeRemaining = computeBatteryTimeRemaining(
5875 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005876 if (timeRemaining >= 0) {
5877 pw.print(" Estimated discharge time remaining: ");
5878 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5879 pw.println();
5880 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005881 final LevelStepTracker steps = getDischargeLevelStepTracker();
5882 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
5883 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
5884 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
5885 STEP_LEVEL_MODE_VALUES[i], null));
5886 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005887 pw.println();
5888 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005889 if (dumpDurationSteps(pw, " ", "Charge step durations:",
5890 getChargeLevelStepTracker(), false)) {
Kweku Adamsb0449e02016-10-12 14:18:27 -07005891 long timeRemaining = computeChargeTimeRemaining(
5892 SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005893 if (timeRemaining >= 0) {
5894 pw.print(" Estimated charge time remaining: ");
5895 TimeUtils.formatDuration(timeRemaining / 1000, pw);
5896 pw.println();
5897 }
5898 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005899 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005900 }
5901 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
5902 pw.println("Daily stats:");
5903 pw.print(" Current start time: ");
5904 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5905 getCurrentDailyStartTime()).toString());
5906 pw.print(" Next min deadline: ");
5907 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5908 getNextMinDailyDeadline()).toString());
5909 pw.print(" Next max deadline: ");
5910 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
5911 getNextMaxDailyDeadline()).toString());
5912 StringBuilder sb = new StringBuilder(64);
5913 int[] outInt = new int[1];
5914 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
5915 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005916 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
5917 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005918 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005919 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
5920 dsteps, false)) {
5921 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5922 sb, outInt);
5923 }
5924 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
5925 csteps, false)) {
5926 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5927 sb, outInt);
5928 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005929 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005930 } else {
5931 pw.println(" Current daily steps:");
5932 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
5933 sb, outInt);
5934 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
5935 sb, outInt);
5936 }
5937 }
5938 DailyItem dit;
5939 int curIndex = 0;
5940 while ((dit=getDailyItemLocked(curIndex)) != null) {
5941 curIndex++;
5942 if ((flags&DUMP_DAILY_ONLY) != 0) {
5943 pw.println();
5944 }
5945 pw.print(" Daily from ");
5946 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
5947 pw.print(" to ");
5948 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
5949 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005950 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005951 if (dumpDurationSteps(pw, " ",
5952 " Discharge step durations:", dit.mDischargeSteps, false)) {
5953 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5954 sb, outInt);
5955 }
5956 if (dumpDurationSteps(pw, " ",
5957 " Charge step durations:", dit.mChargeSteps, false)) {
5958 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5959 sb, outInt);
5960 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07005961 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005962 } else {
5963 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
5964 sb, outInt);
5965 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
5966 sb, outInt);
5967 }
5968 }
5969 pw.println();
5970 }
5971 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005972 pw.println("Statistics since last charge:");
5973 pw.println(" System starts: " + getStartCount()
5974 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07005975 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
5976 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07005977 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07005978 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005979 }
5980
5981 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005982 public void dumpCheckinLocked(Context context, PrintWriter pw,
5983 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07005984 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005985
5986 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07005987 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
5988 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005989
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005990 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5991
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005992 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005993 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005994
5995 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005996 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005997 try {
5998 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5999 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
6000 pw.print(HISTORY_STRING_POOL); pw.print(',');
6001 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006002 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006003 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07006004 pw.print(",\"");
6005 String str = getHistoryTagPoolString(i);
6006 str = str.replace("\\", "\\\\");
6007 str = str.replace("\"", "\\\"");
6008 pw.print(str);
6009 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006010 pw.println();
6011 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07006012 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08006013 } finally {
6014 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08006015 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006016 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07006017 }
6018
Dianne Hackborn1e725a72015-03-24 18:23:19 -07006019 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08006020 return;
6021 }
6022
Dianne Hackborne4a59512010-12-07 11:08:07 -08006023 if (apps != null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006024 SparseArray<Pair<ArrayList<String>, MutableBoolean>> uids = new SparseArray<>();
Dianne Hackborne4a59512010-12-07 11:08:07 -08006025 for (int i=0; i<apps.size(); i++) {
6026 ApplicationInfo ai = apps.get(i);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006027 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(
6028 UserHandle.getAppId(ai.uid));
Dianne Hackborne4a59512010-12-07 11:08:07 -08006029 if (pkgs == null) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006030 pkgs = new Pair<>(new ArrayList<String>(), new MutableBoolean(false));
6031 uids.put(UserHandle.getAppId(ai.uid), pkgs);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006032 }
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006033 pkgs.first.add(ai.packageName);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006034 }
6035 SparseArray<? extends Uid> uidStats = getUidStats();
6036 final int NU = uidStats.size();
6037 String[] lineArgs = new String[2];
6038 for (int i=0; i<NU; i++) {
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006039 int uid = UserHandle.getAppId(uidStats.keyAt(i));
6040 Pair<ArrayList<String>, MutableBoolean> pkgs = uids.get(uid);
6041 if (pkgs != null && !pkgs.second.value) {
6042 pkgs.second.value = true;
6043 for (int j=0; j<pkgs.first.size(); j++) {
Dianne Hackborne4a59512010-12-07 11:08:07 -08006044 lineArgs[0] = Integer.toString(uid);
Dianne Hackborn9cfba352016-03-24 17:31:28 -07006045 lineArgs[1] = pkgs.first.get(j);
Dianne Hackborne4a59512010-12-07 11:08:07 -08006046 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
6047 (Object[])lineArgs);
6048 }
6049 }
6050 }
6051 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07006052 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006053 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006054 String[] lineArgs = new String[1];
Kweku Adamsb0449e02016-10-12 14:18:27 -07006055 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006056 if (timeRemaining >= 0) {
6057 lineArgs[0] = Long.toString(timeRemaining);
6058 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
6059 (Object[])lineArgs);
6060 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08006061 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Kweku Adamsb0449e02016-10-12 14:18:27 -07006062 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07006063 if (timeRemaining >= 0) {
6064 lineArgs[0] = Long.toString(timeRemaining);
6065 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
6066 (Object[])lineArgs);
6067 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07006068 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
6069 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08006070 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006071 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006072}