blob: d165240e2394f627b43ed7a69fdab81ef8a092cf [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.util.Printer;
34import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070035import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070036import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070037import android.view.Display;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080038import com.android.internal.os.BatterySipper;
39import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
41/**
42 * A class providing access to battery usage statistics, including information on
43 * wakelocks, processes, packages, and services. All times are represented in microseconds
44 * except where indicated otherwise.
45 * @hide
46 */
47public abstract class BatteryStats implements Parcelable {
48
49 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070050
51 /** @hide */
52 public static final String SERVICE_NAME = "batterystats";
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 /**
55 * A constant indicating a partial wake lock timer.
56 */
57 public static final int WAKE_TYPE_PARTIAL = 0;
58
59 /**
60 * A constant indicating a full wake lock timer.
61 */
62 public static final int WAKE_TYPE_FULL = 1;
63
64 /**
65 * A constant indicating a window wake lock timer.
66 */
67 public static final int WAKE_TYPE_WINDOW = 2;
68
69 /**
70 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 */
72 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070073
74 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070075 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070076 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070077 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070078
79 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070080 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070081 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070082 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070083
84 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070085 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070086 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070087 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
Dianne Hackborn62793e42015-03-09 11:15:41 -070089 /**
90 * A constant indicating a wifi multicast timer
91 */
92 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070095 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070096 */
97 public static final int VIDEO_TURNED_ON = 8;
98
99 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800100 * A constant indicating a vibrator on timer
101 */
102 public static final int VIBRATOR_ON = 9;
103
104 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700105 * A constant indicating a foreground activity timer
106 */
107 public static final int FOREGROUND_ACTIVITY = 10;
108
109 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700110 * A constant indicating a wifi batched scan is active
111 */
112 public static final int WIFI_BATCHED_SCAN = 11;
113
114 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700115 * A constant indicating a process state timer
116 */
117 public static final int PROCESS_STATE = 12;
118
119 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700120 * A constant indicating a sync timer
121 */
122 public static final int SYNC = 13;
123
124 /**
125 * A constant indicating a job timer
126 */
127 public static final int JOB = 14;
128
129 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800130 * A constant indicating an audio turn on timer
131 */
132 public static final int AUDIO_TURNED_ON = 15;
133
134 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700135 * A constant indicating a flashlight turn on timer
136 */
137 public static final int FLASHLIGHT_TURNED_ON = 16;
138
139 /**
140 * A constant indicating a camera turn on timer
141 */
142 public static final int CAMERA_TURNED_ON = 17;
143
144 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 * Include all of the data in the stats, including previously saved data.
146 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700147 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148
149 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 * Include only the current run in the stats.
151 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700152 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153
154 /**
155 * Include only the run since the last time the device was unplugged in the stats.
156 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700157 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700158
159 // NOTE: Update this list if you add/change any stats above.
160 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700161 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700162 private static final String[] STAT_NAMES = { "l", "c", "u" };
163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 /**
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700165 * Current version of checkin data format.
166 */
167 static final String CHECKIN_VERSION = "14";
168
169 /**
170 * Old version, we hit 9 and ran out of room, need to remove.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700172 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Dianne Hackborn0c820db2015-04-14 17:47:34 -0700173
Evan Millar22ac0432009-03-31 11:33:18 -0700174 private static final long BYTES_PER_KB = 1024;
175 private static final long BYTES_PER_MB = 1048576; // 1024^2
176 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700178 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800179 private static final String UID_DATA = "uid";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700181 private static final String PROCESS_DATA = "pr";
182 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800183 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700184 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700185 private static final String STATE_TIME_DATA = "st";
Evan Millare84de8d2009-04-02 22:16:12 -0700186 private static final String WAKELOCK_DATA = "wl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700187 private static final String SYNC_DATA = "sy";
188 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700189 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700190 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700191 private static final String NETWORK_DATA = "nt";
192 private static final String USER_ACTIVITY_DATA = "ua";
193 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800194 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700195 private static final String BATTERY_LEVEL_DATA = "lv";
Adam Lesinskie283d332015-04-16 12:29:25 -0700196 private static final String GLOBAL_WIFI_DATA = "gwfl";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700197 private static final String WIFI_DATA = "wfl";
Adam Lesinskie283d332015-04-16 12:29:25 -0700198 private static final String GLOBAL_BLUETOOTH_DATA = "gble";
Evan Millare84de8d2009-04-02 22:16:12 -0700199 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800200 private static final String GLOBAL_NETWORK_DATA = "gn";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800201 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700202 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700203 private static final String SCREEN_BRIGHTNESS_DATA = "br";
204 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700205 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700206 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
207 private static final String DATA_CONNECTION_TIME_DATA = "dct";
208 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800209 private static final String WIFI_STATE_TIME_DATA = "wst";
210 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700211 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
212 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
213 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
214 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800215 private static final String POWER_USE_SUMMARY_DATA = "pws";
216 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700217 private static final String DISCHARGE_STEP_DATA = "dsd";
218 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700219 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
220 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700221 private static final String FLASHLIGHT_DATA = "fla";
222 private static final String CAMERA_DATA = "cam";
223 private static final String VIDEO_DATA = "vid";
224 private static final String AUDIO_DATA = "aud";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700226 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 private final Formatter mFormatter = new Formatter(mFormatBuilder);
228
229 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700230 * State for keeping track of counting information.
231 */
232 public static abstract class Counter {
233
234 /**
235 * Returns the count associated with this Counter for the
236 * selected type of statistics.
237 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700238 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700239 */
Evan Millarc64edde2009-04-18 12:26:32 -0700240 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700241
242 /**
243 * Temporary for debugging.
244 */
245 public abstract void logState(Printer pw, String prefix);
246 }
247
248 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700249 * State for keeping track of long counting information.
250 */
251 public static abstract class LongCounter {
252
253 /**
254 * Returns the count associated with this Counter for the
255 * selected type of statistics.
256 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700257 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700258 */
259 public abstract long getCountLocked(int which);
260
261 /**
262 * Temporary for debugging.
263 */
264 public abstract void logState(Printer pw, String prefix);
265 }
266
267 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 * State for keeping track of timing information.
269 */
270 public static abstract class Timer {
271
272 /**
273 * Returns the count associated with this Timer for the
274 * selected type of statistics.
275 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700276 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 */
Evan Millarc64edde2009-04-18 12:26:32 -0700278 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279
280 /**
281 * Returns the total time in microseconds associated with this Timer for the
282 * selected type of statistics.
283 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800284 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700285 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 * @return a time in microseconds
287 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800288 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 /**
Adam Lesinskie08af192015-03-25 16:42:59 -0700291 * Returns the total time in microseconds associated with this Timer since the
292 * 'mark' was last set.
293 *
294 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
295 * @return a time in microseconds
296 */
297 public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);
298
299 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 * Temporary for debugging.
301 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700302 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 }
304
305 /**
306 * The statistics associated with a particular uid.
307 */
308 public static abstract class Uid {
309
310 /**
311 * Returns a mapping containing wakelock statistics.
312 *
313 * @return a Map from Strings to Uid.Wakelock objects.
314 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700315 public abstract ArrayMap<String, ? extends Wakelock> getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316
317 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700318 * Returns a mapping containing sync statistics.
319 *
320 * @return a Map from Strings to Timer objects.
321 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700322 public abstract ArrayMap<String, ? extends Timer> getSyncStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700323
324 /**
325 * Returns a mapping containing scheduled job statistics.
326 *
327 * @return a Map from Strings to Timer objects.
328 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700329 public abstract ArrayMap<String, ? extends Timer> getJobStats();
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700330
331 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 * The statistics associated with a particular wake lock.
333 */
334 public static abstract class Wakelock {
335 public abstract Timer getWakeTime(int type);
336 }
337
338 /**
339 * Returns a mapping containing sensor statistics.
340 *
341 * @return a Map from Integer sensor ids to Uid.Sensor objects.
342 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700343 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344
345 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700346 * Returns a mapping containing active process data.
347 */
348 public abstract SparseArray<? extends Pid> getPidStats();
349
350 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 * Returns a mapping containing process statistics.
352 *
353 * @return a Map from Strings to Uid.Proc objects.
354 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700355 public abstract ArrayMap<String, ? extends Proc> getProcessStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356
357 /**
358 * Returns a mapping containing package statistics.
359 *
360 * @return a Map from Strings to Uid.Pkg objects.
361 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700362 public abstract ArrayMap<String, ? extends Pkg> getPackageStats();
Adam Lesinskie08af192015-03-25 16:42:59 -0700363
364 /**
365 * Returns the time in milliseconds that this app kept the WiFi controller in the
366 * specified state <code>type</code>.
367 * @param type one of {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, or
368 * {@link #CONTROLLER_TX_TIME}.
369 * @param which one of {@link #STATS_CURRENT}, {@link #STATS_SINCE_CHARGED}, or
370 * {@link #STATS_SINCE_UNPLUGGED}.
371 */
372 public abstract long getWifiControllerActivity(int type, int which);
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 /**
375 * {@hide}
376 */
377 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700378
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800379 public abstract void noteWifiRunningLocked(long elapsedRealtime);
380 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
381 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
382 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
383 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
384 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
385 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
386 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
387 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
388 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800389 public abstract void noteActivityResumedLocked(long elapsedRealtime);
390 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800391 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
392 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
393 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700394 public abstract int getWifiScanCount(int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800395 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700396 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800397 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -0700398 public abstract Timer getAudioTurnedOnTimer();
399 public abstract Timer getVideoTurnedOnTimer();
400 public abstract Timer getFlashlightTurnedOnTimer();
401 public abstract Timer getCameraTurnedOnTimer();
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700402 public abstract Timer getForegroundActivityTimer();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700403
404 // Time this uid has any processes in foreground state.
405 public static final int PROCESS_STATE_FOREGROUND = 0;
406 // Time this uid has any process in active state (not cached).
407 public static final int PROCESS_STATE_ACTIVE = 1;
408 // Time this uid has any processes running at all.
409 public static final int PROCESS_STATE_RUNNING = 2;
410 // Total number of process states we track.
411 public static final int NUM_PROCESS_STATE = 3;
412
413 static final String[] PROCESS_STATE_NAMES = {
414 "Foreground", "Active", "Running"
415 };
416
417 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
418
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800419 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420
Robert Greenwalta029ea12013-09-25 16:38:12 -0700421 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
422
Dianne Hackborn617f8772009-03-31 15:04:46 -0700423 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700424 * Note that these must match the constants in android.os.PowerManager.
425 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
426 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700427 */
428 static final String[] USER_ACTIVITY_TYPES = {
Jeff Browndf693de2012-07-27 12:03:38 -0700429 "other", "button", "touch"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700430 };
431
Jeff Browndf693de2012-07-27 12:03:38 -0700432 public static final int NUM_USER_ACTIVITY_TYPES = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700433
Dianne Hackborn617f8772009-03-31 15:04:46 -0700434 public abstract void noteUserActivityLocked(int type);
435 public abstract boolean hasUserActivity();
436 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700437
438 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800439 public abstract long getNetworkActivityBytes(int type, int which);
440 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800441 public abstract long getMobileRadioActiveTime(int which);
442 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700443
Adam Lesinski06af1fa2015-05-05 17:35:35 -0700444 /**
445 * Get the total cpu time (in microseconds) this UID had processes executing in userspace.
446 */
447 public abstract long getUserCpuTimeUs(int which);
448
449 /**
450 * Get the total cpu time (in microseconds) this UID had processes executing kernel syscalls.
451 */
452 public abstract long getSystemCpuTimeUs(int which);
453
454 /**
455 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed.
456 * @param speedStep the index of the CPU speed. This is not the actual speed of the CPU.
457 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
458 * @see BatteryStats#getCpuSpeedSteps()
459 */
460 public abstract long getTimeAtCpuSpeed(int step, int which);
461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800463 /*
464 * FIXME: it's not correct to use this magic value because it
465 * could clash with a sensor handle (which are defined by
466 * the sensor HAL, and therefore out of our control
467 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 // Magic sensor number for the GPS.
469 public static final int GPS = -10000;
470
471 public abstract int getHandle();
472
473 public abstract Timer getSensorTime();
474 }
475
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700476 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800477 public int mWakeNesting;
478 public long mWakeSumMs;
479 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700480 }
481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 /**
483 * The statistics associated with a particular process.
484 */
485 public static abstract class Proc {
486
Dianne Hackborn287952c2010-09-22 22:34:31 -0700487 public static class ExcessivePower {
488 public static final int TYPE_WAKE = 1;
489 public static final int TYPE_CPU = 2;
490
491 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700492 public long overTime;
493 public long usedTime;
494 }
495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800497 * Returns true if this process is still active in the battery stats.
498 */
499 public abstract boolean isActive();
500
501 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700502 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700504 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 */
506 public abstract long getUserTime(int which);
507
508 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700509 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700511 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 */
513 public abstract long getSystemTime(int which);
514
515 /**
516 * Returns the number of times the process has been started.
517 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700518 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 */
520 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700521
522 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800523 * Returns the number of times the process has crashed.
524 *
525 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
526 */
527 public abstract int getNumCrashes(int which);
528
529 /**
530 * Returns the number of times the process has ANRed.
531 *
532 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
533 */
534 public abstract int getNumAnrs(int which);
535
536 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700537 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700538 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700539 * @return foreground cpu time in microseconds
540 */
541 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700542
Dianne Hackborn287952c2010-09-22 22:34:31 -0700543 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700544
Dianne Hackborn287952c2010-09-22 22:34:31 -0700545 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 }
547
548 /**
549 * The statistics associated with a particular package.
550 */
551 public static abstract class Pkg {
552
553 /**
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700554 * Returns information about all wakeup alarms that have been triggered for this
555 * package. The mapping keys are tag names for the alarms, the counter contains
556 * the number of times the alarm was triggered while on battery.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700558 public abstract ArrayMap<String, ? extends Counter> getWakeupAlarmStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559
560 /**
561 * Returns a mapping containing service statistics.
562 */
Dianne Hackborn1e725a72015-03-24 18:23:19 -0700563 public abstract ArrayMap<String, ? extends Serv> getServiceStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564
565 /**
566 * The statistics associated with a particular service.
567 */
568 public abstract class Serv {
569
570 /**
571 * Returns the amount of time spent started.
572 *
573 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700574 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 * @return
576 */
577 public abstract long getStartTime(long batteryUptime, int which);
578
579 /**
580 * Returns the total number of times startService() has been called.
581 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700582 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 */
584 public abstract int getStarts(int which);
585
586 /**
587 * Returns the total number times the service has been launched.
588 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700589 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 */
591 public abstract int getLaunches(int which);
592 }
593 }
594 }
595
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800596 public static final class LevelStepTracker {
597 public long mLastStepTime = -1;
598 public int mNumStepDurations;
599 public final long[] mStepDurations;
600
601 public LevelStepTracker(int maxLevelSteps) {
602 mStepDurations = new long[maxLevelSteps];
603 }
604
605 public LevelStepTracker(int numSteps, long[] steps) {
606 mNumStepDurations = numSteps;
607 mStepDurations = new long[numSteps];
608 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
609 }
610
611 public long getDurationAt(int index) {
612 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
613 }
614
615 public int getLevelAt(int index) {
616 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
617 >> STEP_LEVEL_LEVEL_SHIFT);
618 }
619
620 public int getInitModeAt(int index) {
621 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
622 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
623 }
624
625 public int getModModeAt(int index) {
626 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
627 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
628 }
629
630 private void appendHex(long val, int topOffset, StringBuilder out) {
631 boolean hasData = false;
632 while (topOffset >= 0) {
633 int digit = (int)( (val>>topOffset) & 0xf );
634 topOffset -= 4;
635 if (!hasData && digit == 0) {
636 continue;
637 }
638 hasData = true;
639 if (digit >= 0 && digit <= 9) {
640 out.append((char)('0' + digit));
641 } else {
642 out.append((char)('a' + digit - 10));
643 }
644 }
645 }
646
647 public void encodeEntryAt(int index, StringBuilder out) {
648 long item = mStepDurations[index];
649 long duration = item & STEP_LEVEL_TIME_MASK;
650 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
651 >> STEP_LEVEL_LEVEL_SHIFT);
652 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
653 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
654 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
655 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
656 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
657 case Display.STATE_OFF: out.append('f'); break;
658 case Display.STATE_ON: out.append('o'); break;
659 case Display.STATE_DOZE: out.append('d'); break;
660 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
661 }
662 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
663 out.append('p');
664 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700665 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
666 out.append('i');
667 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800668 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
669 case Display.STATE_OFF: out.append('F'); break;
670 case Display.STATE_ON: out.append('O'); break;
671 case Display.STATE_DOZE: out.append('D'); break;
672 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
673 }
674 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
675 out.append('P');
676 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700677 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
678 out.append('I');
679 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800680 out.append('-');
681 appendHex(level, 4, out);
682 out.append('-');
683 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
684 }
685
686 public void decodeEntryAt(int index, String value) {
687 final int N = value.length();
688 int i = 0;
689 char c;
690 long out = 0;
691 while (i < N && (c=value.charAt(i)) != '-') {
692 i++;
693 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800694 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800695 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800696 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800697 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800698 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800699 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800700 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
701 << STEP_LEVEL_INITIAL_MODE_SHIFT);
702 break;
703 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
704 << STEP_LEVEL_INITIAL_MODE_SHIFT);
705 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700706 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
707 << STEP_LEVEL_INITIAL_MODE_SHIFT);
708 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800709 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
710 break;
711 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
712 break;
713 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
714 break;
715 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
716 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
717 break;
718 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
719 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800720 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700721 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
722 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
723 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800724 }
725 }
726 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800727 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800728 while (i < N && (c=value.charAt(i)) != '-') {
729 i++;
730 level <<= 4;
731 if (c >= '0' && c <= '9') {
732 level += c - '0';
733 } else if (c >= 'a' && c <= 'f') {
734 level += c - 'a' + 10;
735 } else if (c >= 'A' && c <= 'F') {
736 level += c - 'A' + 10;
737 }
738 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800739 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800740 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
741 long duration = 0;
742 while (i < N && (c=value.charAt(i)) != '-') {
743 i++;
744 duration <<= 4;
745 if (c >= '0' && c <= '9') {
746 duration += c - '0';
747 } else if (c >= 'a' && c <= 'f') {
748 duration += c - 'a' + 10;
749 } else if (c >= 'A' && c <= 'F') {
750 duration += c - 'A' + 10;
751 }
752 }
753 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
754 }
755
756 public void init() {
757 mLastStepTime = -1;
758 mNumStepDurations = 0;
759 }
760
761 public void clearTime() {
762 mLastStepTime = -1;
763 }
764
765 public long computeTimePerLevel() {
766 final long[] steps = mStepDurations;
767 final int numSteps = mNumStepDurations;
768
769 // For now we'll do a simple average across all steps.
770 if (numSteps <= 0) {
771 return -1;
772 }
773 long total = 0;
774 for (int i=0; i<numSteps; i++) {
775 total += steps[i] & STEP_LEVEL_TIME_MASK;
776 }
777 return total / numSteps;
778 /*
779 long[] buckets = new long[numSteps];
780 int numBuckets = 0;
781 int numToAverage = 4;
782 int i = 0;
783 while (i < numSteps) {
784 long totalTime = 0;
785 int num = 0;
786 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
787 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
788 num++;
789 }
790 buckets[numBuckets] = totalTime / num;
791 numBuckets++;
792 numToAverage *= 2;
793 i += num;
794 }
795 if (numBuckets < 1) {
796 return -1;
797 }
798 long averageTime = buckets[numBuckets-1];
799 for (i=numBuckets-2; i>=0; i--) {
800 averageTime = (averageTime + buckets[i]) / 2;
801 }
802 return averageTime;
803 */
804 }
805
806 public long computeTimeEstimate(long modesOfInterest, long modeValues,
807 int[] outNumOfInterest) {
808 final long[] steps = mStepDurations;
809 final int count = mNumStepDurations;
810 if (count <= 0) {
811 return -1;
812 }
813 long total = 0;
814 int numOfInterest = 0;
815 for (int i=0; i<count; i++) {
816 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
817 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
818 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
819 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
820 // If the modes of interest didn't change during this step period...
821 if ((modMode&modesOfInterest) == 0) {
822 // And the mode values during this period match those we are measuring...
823 if ((initMode&modesOfInterest) == modeValues) {
824 // Then this can be used to estimate the total time!
825 numOfInterest++;
826 total += steps[i] & STEP_LEVEL_TIME_MASK;
827 }
828 }
829 }
830 if (numOfInterest <= 0) {
831 return -1;
832 }
833
834 if (outNumOfInterest != null) {
835 outNumOfInterest[0] = numOfInterest;
836 }
837
838 // The estimated time is the average time we spend in each level, multipled
839 // by 100 -- the total number of battery levels
840 return (total / numOfInterest) * 100;
841 }
842
843 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
844 int stepCount = mNumStepDurations;
845 final long lastStepTime = mLastStepTime;
846 if (lastStepTime >= 0 && numStepLevels > 0) {
847 final long[] steps = mStepDurations;
848 long duration = elapsedRealtime - lastStepTime;
849 for (int i=0; i<numStepLevels; i++) {
850 System.arraycopy(steps, 0, steps, 1, steps.length-1);
851 long thisDuration = duration / (numStepLevels-i);
852 duration -= thisDuration;
853 if (thisDuration > STEP_LEVEL_TIME_MASK) {
854 thisDuration = STEP_LEVEL_TIME_MASK;
855 }
856 steps[0] = thisDuration | modeBits;
857 }
858 stepCount += numStepLevels;
859 if (stepCount > steps.length) {
860 stepCount = steps.length;
861 }
862 }
863 mNumStepDurations = stepCount;
864 mLastStepTime = elapsedRealtime;
865 }
866
867 public void readFromParcel(Parcel in) {
868 final int N = in.readInt();
869 mNumStepDurations = N;
870 for (int i=0; i<N; i++) {
871 mStepDurations[i] = in.readLong();
872 }
873 }
874
875 public void writeToParcel(Parcel out) {
876 final int N = mNumStepDurations;
877 out.writeInt(N);
878 for (int i=0; i<N; i++) {
879 out.writeLong(mStepDurations[i]);
880 }
881 }
882 }
883
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700884 public static final class PackageChange {
885 public String mPackageName;
886 public boolean mUpdate;
887 public int mVersionCode;
888 }
889
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800890 public static final class DailyItem {
891 public long mStartTime;
892 public long mEndTime;
893 public LevelStepTracker mDischargeSteps;
894 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700895 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800896 }
897
898 public abstract DailyItem getDailyItemLocked(int daysAgo);
899
900 public abstract long getCurrentDailyStartTime();
901
902 public abstract long getNextMinDailyDeadline();
903
904 public abstract long getNextMaxDailyDeadline();
905
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800906 public final static class HistoryTag {
907 public String string;
908 public int uid;
909
910 public int poolIdx;
911
912 public void setTo(HistoryTag o) {
913 string = o.string;
914 uid = o.uid;
915 poolIdx = o.poolIdx;
916 }
917
918 public void setTo(String _string, int _uid) {
919 string = _string;
920 uid = _uid;
921 poolIdx = -1;
922 }
923
924 public void writeToParcel(Parcel dest, int flags) {
925 dest.writeString(string);
926 dest.writeInt(uid);
927 }
928
929 public void readFromParcel(Parcel src) {
930 string = src.readString();
931 uid = src.readInt();
932 poolIdx = -1;
933 }
934
935 @Override
936 public boolean equals(Object o) {
937 if (this == o) return true;
938 if (o == null || getClass() != o.getClass()) return false;
939
940 HistoryTag that = (HistoryTag) o;
941
942 if (uid != that.uid) return false;
943 if (!string.equals(that.string)) return false;
944
945 return true;
946 }
947
948 @Override
949 public int hashCode() {
950 int result = string.hashCode();
951 result = 31 * result + uid;
952 return result;
953 }
954 }
955
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -0800956 /**
957 * Optional detailed information that can go into a history step. This is typically
958 * generated each time the battery level changes.
959 */
960 public final static class HistoryStepDetails {
961 // Time (in 1/100 second) spent in user space and the kernel since the last step.
962 public int userTime;
963 public int systemTime;
964
965 // Top three apps using CPU in the last step, with times in 1/100 second.
966 public int appCpuUid1;
967 public int appCpuUTime1;
968 public int appCpuSTime1;
969 public int appCpuUid2;
970 public int appCpuUTime2;
971 public int appCpuSTime2;
972 public int appCpuUid3;
973 public int appCpuUTime3;
974 public int appCpuSTime3;
975
976 // Information from /proc/stat
977 public int statUserTime;
978 public int statSystemTime;
979 public int statIOWaitTime;
980 public int statIrqTime;
981 public int statSoftIrqTime;
982 public int statIdlTime;
983
984 public HistoryStepDetails() {
985 clear();
986 }
987
988 public void clear() {
989 userTime = systemTime = 0;
990 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
991 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
992 = appCpuUTime3 = appCpuSTime3 = 0;
993 }
994
995 public void writeToParcel(Parcel out) {
996 out.writeInt(userTime);
997 out.writeInt(systemTime);
998 out.writeInt(appCpuUid1);
999 out.writeInt(appCpuUTime1);
1000 out.writeInt(appCpuSTime1);
1001 out.writeInt(appCpuUid2);
1002 out.writeInt(appCpuUTime2);
1003 out.writeInt(appCpuSTime2);
1004 out.writeInt(appCpuUid3);
1005 out.writeInt(appCpuUTime3);
1006 out.writeInt(appCpuSTime3);
1007 out.writeInt(statUserTime);
1008 out.writeInt(statSystemTime);
1009 out.writeInt(statIOWaitTime);
1010 out.writeInt(statIrqTime);
1011 out.writeInt(statSoftIrqTime);
1012 out.writeInt(statIdlTime);
1013 }
1014
1015 public void readFromParcel(Parcel in) {
1016 userTime = in.readInt();
1017 systemTime = in.readInt();
1018 appCpuUid1 = in.readInt();
1019 appCpuUTime1 = in.readInt();
1020 appCpuSTime1 = in.readInt();
1021 appCpuUid2 = in.readInt();
1022 appCpuUTime2 = in.readInt();
1023 appCpuSTime2 = in.readInt();
1024 appCpuUid3 = in.readInt();
1025 appCpuUTime3 = in.readInt();
1026 appCpuSTime3 = in.readInt();
1027 statUserTime = in.readInt();
1028 statSystemTime = in.readInt();
1029 statIOWaitTime = in.readInt();
1030 statIrqTime = in.readInt();
1031 statSoftIrqTime = in.readInt();
1032 statIdlTime = in.readInt();
1033 }
1034 }
1035
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001036 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001037 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -07001038
1039 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001040 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001041
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001042 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001043 public static final byte CMD_NULL = -1;
1044 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001045 public static final byte CMD_CURRENT_TIME = 5;
1046 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001047 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08001048 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001049
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001050 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001051
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001052 /**
1053 * Return whether the command code is a delta data update.
1054 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001055 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001056 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001057 }
1058
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001059 public byte batteryLevel;
1060 public byte batteryStatus;
1061 public byte batteryHealth;
1062 public byte batteryPlugType;
1063
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001064 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001065 public char batteryVoltage;
1066
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001067 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001068 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001069 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001070 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001071 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1072 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001073 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001074 public static final int STATE_PHONE_STATE_SHIFT = 6;
1075 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001076 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001077 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001078 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001079
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001080 // These states always appear directly in the first int token
1081 // of a delta change; they should be ones that change relatively
1082 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001083 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1084 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001085 public static final int STATE_GPS_ON_FLAG = 1<<29;
1086 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001087 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001088 public static final int STATE_WIFI_RADIO_ACTIVE_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001089 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001090 // These are on the lower bits used for the command; if they change
1091 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001092 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001093 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001094 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001095 public static final int STATE_SCREEN_ON_FLAG = 1<<20; // consider moving to states2
1096 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
1097 // empty slot
1098 // empty slot
1099 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001100
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001101 public static final int MOST_INTERESTING_STATES =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001102 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
1103
1104 public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001105
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001106 public int states;
1107
Dianne Hackborn3251b902014-06-20 14:40:53 -07001108 // Constants from WIFI_SUPPL_STATE_*
1109 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1110 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1111 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1112 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1113 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1114 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1115
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001116 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001117 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1118 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1119 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001120 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001121 public static final int STATE2_DEVICE_IDLE_FLAG = 1<<26;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001122 public static final int STATE2_CHARGING_FLAG = 1<<25;
1123 public static final int STATE2_PHONE_IN_CALL_FLAG = 1<<24;
1124 public static final int STATE2_BLUETOOTH_ON_FLAG = 1<<23;
Ruben Brunk6d2c3632015-05-26 17:32:16 -07001125 public static final int STATE2_CAMERA_FLAG = 1<<22;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001126
1127 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001128 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_FLAG
1129 | STATE2_CHARGING_FLAG | STATE2_PHONE_IN_CALL_FLAG | STATE2_BLUETOOTH_ON_FLAG;
1130
1131 public static final int SETTLE_TO_ZERO_STATES2 = 0xffff0000 & ~MOST_INTERESTING_STATES2;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001132
Dianne Hackborn40c87252014-03-19 16:55:40 -07001133 public int states2;
1134
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001135 // The wake lock that was acquired at this point.
1136 public HistoryTag wakelockTag;
1137
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001138 // Kernel wakeup reason at this point.
1139 public HistoryTag wakeReasonTag;
1140
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001141 // Non-null when there is more detailed information at this step.
1142 public HistoryStepDetails stepDetails;
1143
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001144 public static final int EVENT_FLAG_START = 0x8000;
1145 public static final int EVENT_FLAG_FINISH = 0x4000;
1146
1147 // No event in this item.
1148 public static final int EVENT_NONE = 0x0000;
1149 // Event is about a process that is running.
1150 public static final int EVENT_PROC = 0x0001;
1151 // Event is about an application package that is in the foreground.
1152 public static final int EVENT_FOREGROUND = 0x0002;
1153 // Event is about an application package that is at the top of the screen.
1154 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001155 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001156 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001157 // Events for all additional wake locks aquired/release within a wake block.
1158 // These are not generated by default.
1159 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001160 // Event is about an application executing a scheduled job.
1161 public static final int EVENT_JOB = 0x0006;
1162 // Events for users running.
1163 public static final int EVENT_USER_RUNNING = 0x0007;
1164 // Events for foreground user.
1165 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001166 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001167 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001168 // Event for significant motion taking us out of idle mode.
1169 public static final int EVENT_SIGNIFICANT_MOTION = 0x000a;
1170 // Event for becoming active taking us out of idle mode.
1171 public static final int EVENT_ACTIVE = 0x000b;
1172 // Event for a package being installed.
1173 public static final int EVENT_PACKAGE_INSTALLED = 0x000c;
1174 // Event for a package being uninstalled.
1175 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000d;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001176 // Event for a package being uninstalled.
1177 public static final int EVENT_ALARM = 0x000e;
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001178 // Record that we have decided we need to collect new stats data.
1179 public static final int EVENT_COLLECT_EXTERNAL_STATS = 0x000f;
Amith Yamasani67768492015-06-09 12:23:58 -07001180 // Event for a package becoming inactive due to being unused for a period of time.
1181 public static final int EVENT_PACKAGE_INACTIVE = 0x0010;
1182 // Event for a package becoming active due to an interaction.
1183 public static final int EVENT_PACKAGE_ACTIVE = 0x0011;
1184
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001185 // Number of event types.
Amith Yamasani67768492015-06-09 12:23:58 -07001186 public static final int EVENT_COUNT = 0x0012;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001187 // Mask to extract out only the type part of the event.
1188 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001189
1190 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1191 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1192 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1193 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1194 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1195 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001196 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1197 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001198 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1199 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001200 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1201 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1202 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1203 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1204 public static final int EVENT_USER_FOREGROUND_START =
1205 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1206 public static final int EVENT_USER_FOREGROUND_FINISH =
1207 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn1e383822015-04-10 14:02:33 -07001208 public static final int EVENT_ALARM_START = EVENT_ALARM | EVENT_FLAG_START;
1209 public static final int EVENT_ALARM_FINISH = EVENT_ALARM | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001210
1211 // For CMD_EVENT.
1212 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001213 public HistoryTag eventTag;
1214
Dianne Hackborn9a755432014-05-15 17:05:22 -07001215 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001216 public long currentTime;
1217
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001218 // Meta-data when reading.
1219 public int numReadInts;
1220
1221 // Pre-allocated objects.
1222 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001223 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001224 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001225
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001226 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001227 }
1228
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001229 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001230 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001231 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001232 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001233 }
1234
1235 public int describeContents() {
1236 return 0;
1237 }
1238
1239 public void writeToParcel(Parcel dest, int flags) {
1240 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001241 int bat = (((int)cmd)&0xff)
1242 | ((((int)batteryLevel)<<8)&0xff00)
1243 | ((((int)batteryStatus)<<16)&0xf0000)
1244 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001245 | ((((int)batteryPlugType)<<24)&0xf000000)
1246 | (wakelockTag != null ? 0x10000000 : 0)
1247 | (wakeReasonTag != null ? 0x20000000 : 0)
1248 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001249 dest.writeInt(bat);
1250 bat = (((int)batteryTemperature)&0xffff)
1251 | ((((int)batteryVoltage)<<16)&0xffff0000);
1252 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001253 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001254 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001255 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001256 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001257 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001258 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001259 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001260 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001261 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001262 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001263 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001264 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001265 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001266 dest.writeLong(currentTime);
1267 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001268 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001269
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001270 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001271 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001272 int bat = src.readInt();
1273 cmd = (byte)(bat&0xff);
1274 batteryLevel = (byte)((bat>>8)&0xff);
1275 batteryStatus = (byte)((bat>>16)&0xf);
1276 batteryHealth = (byte)((bat>>20)&0xf);
1277 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001278 int bat2 = src.readInt();
1279 batteryTemperature = (short)(bat2&0xffff);
1280 batteryVoltage = (char)((bat2>>16)&0xffff);
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001281 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001282 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001283 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001284 wakelockTag = localWakelockTag;
1285 wakelockTag.readFromParcel(src);
1286 } else {
1287 wakelockTag = null;
1288 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001289 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001290 wakeReasonTag = localWakeReasonTag;
1291 wakeReasonTag.readFromParcel(src);
1292 } else {
1293 wakeReasonTag = null;
1294 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001295 if ((bat&0x40000000) != 0) {
1296 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001297 eventTag = localEventTag;
1298 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001299 } else {
1300 eventCode = EVENT_NONE;
1301 eventTag = null;
1302 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001303 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001304 currentTime = src.readLong();
1305 } else {
1306 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001307 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001308 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001309 }
1310
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001311 public void clear() {
1312 time = 0;
1313 cmd = CMD_NULL;
1314 batteryLevel = 0;
1315 batteryStatus = 0;
1316 batteryHealth = 0;
1317 batteryPlugType = 0;
1318 batteryTemperature = 0;
1319 batteryVoltage = 0;
1320 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001321 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001322 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001323 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001324 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001325 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001326 }
1327
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001328 public void setTo(HistoryItem o) {
1329 time = o.time;
1330 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001331 setToCommon(o);
1332 }
1333
1334 public void setTo(long time, byte cmd, HistoryItem o) {
1335 this.time = time;
1336 this.cmd = cmd;
1337 setToCommon(o);
1338 }
1339
1340 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001341 batteryLevel = o.batteryLevel;
1342 batteryStatus = o.batteryStatus;
1343 batteryHealth = o.batteryHealth;
1344 batteryPlugType = o.batteryPlugType;
1345 batteryTemperature = o.batteryTemperature;
1346 batteryVoltage = o.batteryVoltage;
1347 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001348 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001349 if (o.wakelockTag != null) {
1350 wakelockTag = localWakelockTag;
1351 wakelockTag.setTo(o.wakelockTag);
1352 } else {
1353 wakelockTag = null;
1354 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001355 if (o.wakeReasonTag != null) {
1356 wakeReasonTag = localWakeReasonTag;
1357 wakeReasonTag.setTo(o.wakeReasonTag);
1358 } else {
1359 wakeReasonTag = null;
1360 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001361 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001362 if (o.eventTag != null) {
1363 eventTag = localEventTag;
1364 eventTag.setTo(o.eventTag);
1365 } else {
1366 eventTag = null;
1367 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001368 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001369 }
1370
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001371 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001372 return batteryLevel == o.batteryLevel
1373 && batteryStatus == o.batteryStatus
1374 && batteryHealth == o.batteryHealth
1375 && batteryPlugType == o.batteryPlugType
1376 && batteryTemperature == o.batteryTemperature
1377 && batteryVoltage == o.batteryVoltage
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001378 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001379 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001380 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001381 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001382
1383 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001384 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001385 return false;
1386 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001387 if (wakelockTag != o.wakelockTag) {
1388 if (wakelockTag == null || o.wakelockTag == null) {
1389 return false;
1390 }
1391 if (!wakelockTag.equals(o.wakelockTag)) {
1392 return false;
1393 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001394 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001395 if (wakeReasonTag != o.wakeReasonTag) {
1396 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1397 return false;
1398 }
1399 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1400 return false;
1401 }
1402 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001403 if (eventTag != o.eventTag) {
1404 if (eventTag == null || o.eventTag == null) {
1405 return false;
1406 }
1407 if (!eventTag.equals(o.eventTag)) {
1408 return false;
1409 }
1410 }
1411 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001412 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001413 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001414
1415 public final static class HistoryEventTracker {
1416 private final HashMap<String, SparseIntArray>[] mActiveEvents
1417 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1418
1419 public boolean updateState(int code, String name, int uid, int poolIdx) {
1420 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1421 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1422 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1423 if (active == null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07001424 active = new HashMap<>();
Dianne Hackborn37de0982014-05-09 09:32:18 -07001425 mActiveEvents[idx] = active;
1426 }
1427 SparseIntArray uids = active.get(name);
1428 if (uids == null) {
1429 uids = new SparseIntArray();
1430 active.put(name, uids);
1431 }
1432 if (uids.indexOfKey(uid) >= 0) {
1433 // Already set, nothing to do!
1434 return false;
1435 }
1436 uids.put(uid, poolIdx);
1437 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1438 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1439 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1440 if (active == null) {
1441 // not currently active, nothing to do.
1442 return false;
1443 }
1444 SparseIntArray uids = active.get(name);
1445 if (uids == null) {
1446 // not currently active, nothing to do.
1447 return false;
1448 }
1449 idx = uids.indexOfKey(uid);
1450 if (idx < 0) {
1451 // not currently active, nothing to do.
1452 return false;
1453 }
1454 uids.removeAt(idx);
1455 if (uids.size() <= 0) {
1456 active.remove(name);
1457 }
1458 }
1459 return true;
1460 }
1461
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001462 public void removeEvents(int code) {
1463 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1464 mActiveEvents[idx] = null;
1465 }
1466
Dianne Hackborn37de0982014-05-09 09:32:18 -07001467 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1468 return mActiveEvents[code];
1469 }
1470 }
1471
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001472 public static final class BitDescription {
1473 public final int mask;
1474 public final int shift;
1475 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001476 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001477 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001478 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001479
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001480 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001481 this.mask = mask;
1482 this.shift = -1;
1483 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001484 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001485 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001486 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001487 }
1488
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001489 public BitDescription(int mask, int shift, String name, String shortName,
1490 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001491 this.mask = mask;
1492 this.shift = shift;
1493 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001494 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001495 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001496 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001497 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001498 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001499
Dianne Hackbornfc064132014-06-02 12:42:12 -07001500 /**
1501 * Don't allow any more batching in to the current history event. This
1502 * is called when printing partial histories, so to ensure that the next
1503 * history event will go in to a new batch after what was printed in the
1504 * last partial history.
1505 */
1506 public abstract void commitCurrentHistoryBatchLocked();
1507
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001508 public abstract int getHistoryTotalSize();
1509
1510 public abstract int getHistoryUsedSize();
1511
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001512 public abstract boolean startIteratingHistoryLocked();
1513
Dianne Hackborn099bc622014-01-22 13:39:16 -08001514 public abstract int getHistoryStringPoolSize();
1515
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001516 public abstract int getHistoryStringPoolBytes();
1517
1518 public abstract String getHistoryTagPoolString(int index);
1519
1520 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001521
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001522 public abstract boolean getNextHistoryLocked(HistoryItem out);
1523
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001524 public abstract void finishIteratingHistoryLocked();
1525
1526 public abstract boolean startIteratingOldHistoryLocked();
1527
1528 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1529
1530 public abstract void finishIteratingOldHistoryLocked();
1531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001533 * Return the base time offset for the battery history.
1534 */
1535 public abstract long getHistoryBaseTime();
1536
1537 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 * Returns the number of times the device has been started.
1539 */
1540 public abstract int getStartCount();
1541
1542 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001543 * 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 -08001544 * running on battery.
1545 *
1546 * {@hide}
1547 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001548 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001550 /**
1551 * Returns the number of times the screen was turned on.
1552 *
1553 * {@hide}
1554 */
1555 public abstract int getScreenOnCount(int which);
1556
Jeff Browne95c3cd2014-05-02 16:59:26 -07001557 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1558
Dianne Hackborn617f8772009-03-31 15:04:46 -07001559 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1560 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1561 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1562 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1563 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1564
1565 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1566 "dark", "dim", "medium", "light", "bright"
1567 };
1568
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001569 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1570 "0", "1", "2", "3", "4"
1571 };
1572
Dianne Hackborn617f8772009-03-31 15:04:46 -07001573 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001574
Dianne Hackborn617f8772009-03-31 15:04:46 -07001575 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001576 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001577 * the given brightness
1578 *
1579 * {@hide}
1580 */
1581 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001582 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001583
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001585 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001586 * running on battery.
1587 *
1588 * {@hide}
1589 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001590 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001591
1592 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001593 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001594 *
1595 * {@hide}
1596 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001597 public abstract int getPowerSaveModeEnabledCount(int which);
1598
1599 /**
1600 * Returns the time in microseconds that device has been in idle mode while
1601 * running on battery.
1602 *
1603 * {@hide}
1604 */
1605 public abstract long getDeviceIdleModeEnabledTime(long elapsedRealtimeUs, int which);
1606
1607 /**
1608 * Returns the number of times that the devie has gone in to idle mode.
1609 *
1610 * {@hide}
1611 */
1612 public abstract int getDeviceIdleModeEnabledCount(int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001613
1614 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001615 * Returns the time in microseconds that device has been in idling while on
1616 * battery. This is broader than {@link #getDeviceIdleModeEnabledTime} -- it
1617 * counts all of the time that we consider the device to be idle, whether or not
1618 * it is currently in the actual device idle mode.
1619 *
1620 * {@hide}
1621 */
1622 public abstract long getDeviceIdlingTime(long elapsedRealtimeUs, int which);
1623
1624 /**
1625 * Returns the number of times that the devie has started idling.
1626 *
1627 * {@hide}
1628 */
1629 public abstract int getDeviceIdlingCount(int which);
1630
1631 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001632 * Returns the number of times that connectivity state changed.
1633 *
1634 * {@hide}
1635 */
1636 public abstract int getNumConnectivityChange(int which);
1637
1638 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001639 * 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 -08001640 * running on battery.
1641 *
1642 * {@hide}
1643 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001644 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001645
1646 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001647 * Returns the number of times a phone call was activated.
1648 *
1649 * {@hide}
1650 */
1651 public abstract int getPhoneOnCount(int which);
1652
1653 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001654 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001655 * the given signal strength.
1656 *
1657 * {@hide}
1658 */
1659 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001660 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001661
Dianne Hackborn617f8772009-03-31 15:04:46 -07001662 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001663 * Returns the time in microseconds that the phone has been trying to
1664 * acquire a signal.
1665 *
1666 * {@hide}
1667 */
1668 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001669 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001670
1671 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001672 * Returns the number of times the phone has entered the given signal strength.
1673 *
1674 * {@hide}
1675 */
1676 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1677
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001678 /**
1679 * Returns the time in microseconds that the mobile network has been active
1680 * (in a high power state).
1681 *
1682 * {@hide}
1683 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001684 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001685
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001686 /**
1687 * Returns the number of times that the mobile network has transitioned to the
1688 * active state.
1689 *
1690 * {@hide}
1691 */
1692 public abstract int getMobileRadioActiveCount(int which);
1693
1694 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001695 * Returns the time in microseconds that is the difference between the mobile radio
1696 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1697 * from the radio.
1698 *
1699 * {@hide}
1700 */
1701 public abstract long getMobileRadioActiveAdjustedTime(int which);
1702
1703 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001704 * Returns the time in microseconds that the mobile network has been active
1705 * (in a high power state) but not being able to blame on an app.
1706 *
1707 * {@hide}
1708 */
1709 public abstract long getMobileRadioActiveUnknownTime(int which);
1710
1711 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001712 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001713 *
1714 * {@hide}
1715 */
1716 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001717
Dianne Hackborn627bba72009-03-24 22:32:56 -07001718 public static final int DATA_CONNECTION_NONE = 0;
1719 public static final int DATA_CONNECTION_GPRS = 1;
1720 public static final int DATA_CONNECTION_EDGE = 2;
1721 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001722 public static final int DATA_CONNECTION_CDMA = 4;
1723 public static final int DATA_CONNECTION_EVDO_0 = 5;
1724 public static final int DATA_CONNECTION_EVDO_A = 6;
1725 public static final int DATA_CONNECTION_1xRTT = 7;
1726 public static final int DATA_CONNECTION_HSDPA = 8;
1727 public static final int DATA_CONNECTION_HSUPA = 9;
1728 public static final int DATA_CONNECTION_HSPA = 10;
1729 public static final int DATA_CONNECTION_IDEN = 11;
1730 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001731 public static final int DATA_CONNECTION_LTE = 13;
1732 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001733 public static final int DATA_CONNECTION_HSPAP = 15;
1734 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001735
Dianne Hackborn627bba72009-03-24 22:32:56 -07001736 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001737 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001738 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001739 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001740 };
1741
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001742 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001743
1744 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001745 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001746 * the given data connection.
1747 *
1748 * {@hide}
1749 */
1750 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001751 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001752
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001754 * Returns the number of times the phone has entered the given data
1755 * connection type.
1756 *
1757 * {@hide}
1758 */
1759 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001760
Dianne Hackborn3251b902014-06-20 14:40:53 -07001761 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1762 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1763 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1764 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1765 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1766 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1767 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1768 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1769 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1770 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1771 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1772 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1773 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1774
1775 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1776
1777 static final String[] WIFI_SUPPL_STATE_NAMES = {
1778 "invalid", "disconn", "disabled", "inactive", "scanning",
1779 "authenticating", "associating", "associated", "4-way-handshake",
1780 "group-handshake", "completed", "dormant", "uninit"
1781 };
1782
1783 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1784 "inv", "dsc", "dis", "inact", "scan",
1785 "auth", "ascing", "asced", "4-way",
1786 "group", "compl", "dorm", "uninit"
1787 };
1788
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001789 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1790 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001791 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001792 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1793 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001794 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001795 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1796 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1797 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001798 new BitDescription(HistoryItem.STATE_WIFI_RADIO_ACTIVE_FLAG, "wifi_radio", "Wr"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001799 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001800 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001801 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001802 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1803 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001804 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1805 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1806 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1807 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1808 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1809 new String[] {"in", "out", "emergency", "off"},
1810 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001811 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1812 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1813 SignalStrength.SIGNAL_STRENGTH_NAMES,
1814 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001815 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1816 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1817 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001818 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001819
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001820 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1821 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001822 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001823 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001824 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Ww"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001825 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001826 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001827 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_FLAG, "device_idle", "di"),
Dianne Hackborn0c820db2015-04-14 17:47:34 -07001828 new BitDescription(HistoryItem.STATE2_CHARGING_FLAG, "charging", "ch"),
1829 new BitDescription(HistoryItem.STATE2_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
1830 new BitDescription(HistoryItem.STATE2_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001831 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1832 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1833 new String[] { "0", "1", "2", "3", "4" },
1834 new String[] { "0", "1", "2", "3", "4" }),
1835 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1836 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1837 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Ruben Brunk6d2c3632015-05-26 17:32:16 -07001838 new BitDescription(HistoryItem.STATE2_CAMERA_FLAG, "camera", "ca"),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001839 };
1840
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001841 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001842 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
Amith Yamasani67768492015-06-09 12:23:58 -07001843 "motion", "active", "pkginst", "pkgunin", "alarm", "stats", "inactive", "active"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001844 };
1845
1846 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001847 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
Amith Yamasani67768492015-06-09 12:23:58 -07001848 "Esm", "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001849 };
1850
Dianne Hackborn617f8772009-03-31 15:04:46 -07001851 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001852 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001853 * running on battery.
1854 *
1855 * {@hide}
1856 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001857 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001858
1859 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001860 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001861 * been in the running state while the device was running on battery.
1862 *
1863 * {@hide}
1864 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001865 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001866
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001867 public static final int WIFI_STATE_OFF = 0;
1868 public static final int WIFI_STATE_OFF_SCANNING = 1;
1869 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
1870 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
1871 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
1872 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
1873 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
1874 public static final int WIFI_STATE_SOFT_AP = 7;
1875
1876 static final String[] WIFI_STATE_NAMES = {
1877 "off", "scanning", "no_net", "disconn",
1878 "sta", "p2p", "sta_p2p", "soft_ap"
1879 };
1880
1881 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
1882
1883 /**
1884 * Returns the time in microseconds that WiFi has been running in the given state.
1885 *
1886 * {@hide}
1887 */
1888 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001889 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001890
1891 /**
1892 * Returns the number of times that WiFi has entered the given state.
1893 *
1894 * {@hide}
1895 */
1896 public abstract int getWifiStateCount(int wifiState, int which);
1897
The Android Open Source Project10592532009-03-18 17:39:46 -07001898 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07001899 * Returns the time in microseconds that the wifi supplicant has been
1900 * in a given state.
1901 *
1902 * {@hide}
1903 */
1904 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
1905
1906 /**
1907 * Returns the number of times that the wifi supplicant has transitioned
1908 * to a given state.
1909 *
1910 * {@hide}
1911 */
1912 public abstract int getWifiSupplStateCount(int state, int which);
1913
1914 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
1915
1916 /**
1917 * Returns the time in microseconds that WIFI has been running with
1918 * the given signal strength.
1919 *
1920 * {@hide}
1921 */
1922 public abstract long getWifiSignalStrengthTime(int strengthBin,
1923 long elapsedRealtimeUs, int which);
1924
1925 /**
1926 * Returns the number of times WIFI has entered the given signal strength.
1927 *
1928 * {@hide}
1929 */
1930 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
1931
1932 /**
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001933 * Returns the time in microseconds that the flashlight has been on while the device was
1934 * running on battery.
1935 *
1936 * {@hide}
1937 */
1938 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
1939
1940 /**
1941 * Returns the number of times that the flashlight has been turned on while the device was
1942 * running on battery.
1943 *
1944 * {@hide}
1945 */
1946 public abstract long getFlashlightOnCount(int which);
1947
Ruben Brunk5b1308f2015-06-03 18:49:27 -07001948 /**
1949 * Returns the time in microseconds that the camera has been on while the device was
1950 * running on battery.
1951 *
1952 * {@hide}
1953 */
1954 public abstract long getCameraOnTime(long elapsedRealtimeUs, int which);
1955
1956
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001957 public static final int NETWORK_MOBILE_RX_DATA = 0;
1958 public static final int NETWORK_MOBILE_TX_DATA = 1;
1959 public static final int NETWORK_WIFI_RX_DATA = 2;
1960 public static final int NETWORK_WIFI_TX_DATA = 3;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001961 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001962
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001963 public abstract long getNetworkActivityBytes(int type, int which);
1964 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001965
Adam Lesinski33dac552015-03-09 15:24:48 -07001966 public static final int CONTROLLER_IDLE_TIME = 0;
1967 public static final int CONTROLLER_RX_TIME = 1;
1968 public static final int CONTROLLER_TX_TIME = 2;
Adam Lesinskie08af192015-03-25 16:42:59 -07001969 public static final int CONTROLLER_POWER_DRAIN = 3;
1970 public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_POWER_DRAIN + 1;
Adam Lesinski33dac552015-03-09 15:24:48 -07001971
Adam Lesinskie08af192015-03-25 16:42:59 -07001972 /**
Adam Lesinski17390762015-04-10 13:17:47 -07001973 * Returns true if the BatteryStats object has detailed bluetooth power reports.
1974 * When true, calling {@link #getBluetoothControllerActivity(int, int)} will yield the
1975 * actual power data.
1976 */
1977 public abstract boolean hasBluetoothActivityReporting();
1978
1979 /**
Adam Lesinskie08af192015-03-25 16:42:59 -07001980 * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and
1981 * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the
1982 * respective state.
1983 * For {@link #CONTROLLER_POWER_DRAIN}, returns the power used by the controller in
1984 * milli-ampere-milliseconds (mAms).
1985 */
Adam Lesinski33dac552015-03-09 15:24:48 -07001986 public abstract long getBluetoothControllerActivity(int type, int which);
Adam Lesinskie08af192015-03-25 16:42:59 -07001987
1988 /**
Adam Lesinski17390762015-04-10 13:17:47 -07001989 * Returns true if the BatteryStats object has detailed WiFi power reports.
1990 * When true, calling {@link #getWifiControllerActivity(int, int)} will yield the
1991 * actual power data.
1992 */
1993 public abstract boolean hasWifiActivityReporting();
1994
1995 /**
Adam Lesinskie08af192015-03-25 16:42:59 -07001996 * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and
1997 * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the
1998 * respective state.
1999 * For {@link #CONTROLLER_POWER_DRAIN}, returns the power used by the controller in
2000 * milli-ampere-milliseconds (mAms).
2001 */
Adam Lesinski33dac552015-03-09 15:24:48 -07002002 public abstract long getWifiControllerActivity(int type, int which);
2003
The Android Open Source Project10592532009-03-18 17:39:46 -07002004 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002005 * Return the wall clock time when battery stats data collection started.
2006 */
2007 public abstract long getStartClockTime();
2008
2009 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002010 * Return platform version tag that we were running in when the battery stats started.
2011 */
2012 public abstract String getStartPlatformVersion();
2013
2014 /**
2015 * Return platform version tag that we were running in when the battery stats ended.
2016 */
2017 public abstract String getEndPlatformVersion();
2018
2019 /**
2020 * Return the internal version code of the parcelled format.
2021 */
2022 public abstract int getParcelVersion();
2023
2024 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 * Return whether we are currently running on battery.
2026 */
2027 public abstract boolean getIsOnBattery();
2028
2029 /**
2030 * Returns a SparseArray containing the statistics for each uid.
2031 */
2032 public abstract SparseArray<? extends Uid> getUidStats();
2033
2034 /**
2035 * Returns the current battery uptime in microseconds.
2036 *
2037 * @param curTime the amount of elapsed realtime in microseconds.
2038 */
2039 public abstract long getBatteryUptime(long curTime);
2040
2041 /**
2042 * Returns the current battery realtime in microseconds.
2043 *
2044 * @param curTime the amount of elapsed realtime in microseconds.
2045 */
2046 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07002047
2048 /**
Evan Millar633a1742009-04-02 16:36:33 -07002049 * Returns the battery percentage level at the last time the device was unplugged from power, or
2050 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07002051 */
Evan Millar633a1742009-04-02 16:36:33 -07002052 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07002053
2054 /**
Evan Millar633a1742009-04-02 16:36:33 -07002055 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
2056 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07002057 */
Evan Millar633a1742009-04-02 16:36:33 -07002058 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059
2060 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07002061 * Get the amount the battery has discharged since the stats were
2062 * last reset after charging, as a lower-end approximation.
2063 */
2064 public abstract int getLowDischargeAmountSinceCharge();
2065
2066 /**
2067 * Get the amount the battery has discharged since the stats were
2068 * last reset after charging, as an upper-end approximation.
2069 */
2070 public abstract int getHighDischargeAmountSinceCharge();
2071
2072 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002073 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2074 */
2075 public abstract int getDischargeAmount(int which);
2076
2077 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002078 * Get the amount the battery has discharged while the screen was on,
2079 * since the last time power was unplugged.
2080 */
2081 public abstract int getDischargeAmountScreenOn();
2082
2083 /**
2084 * Get the amount the battery has discharged while the screen was on,
2085 * since the last time the device was charged.
2086 */
2087 public abstract int getDischargeAmountScreenOnSinceCharge();
2088
2089 /**
2090 * Get the amount the battery has discharged while the screen was off,
2091 * since the last time power was unplugged.
2092 */
2093 public abstract int getDischargeAmountScreenOff();
2094
2095 /**
2096 * Get the amount the battery has discharged while the screen was off,
2097 * since the last time the device was charged.
2098 */
2099 public abstract int getDischargeAmountScreenOffSinceCharge();
2100
2101 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 * Returns the total, last, or current battery uptime in microseconds.
2103 *
2104 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002105 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 */
2107 public abstract long computeBatteryUptime(long curTime, int which);
2108
2109 /**
2110 * Returns the total, last, or current battery realtime in microseconds.
2111 *
2112 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002113 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002114 */
2115 public abstract long computeBatteryRealtime(long curTime, int which);
2116
2117 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002118 * Returns the total, last, or current battery screen off uptime in microseconds.
2119 *
2120 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002121 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002122 */
2123 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2124
2125 /**
2126 * Returns the total, last, or current battery screen off realtime in microseconds.
2127 *
2128 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002129 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002130 */
2131 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2132
2133 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002134 * Returns the total, last, or current uptime in microseconds.
2135 *
2136 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002137 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 */
2139 public abstract long computeUptime(long curTime, int which);
2140
2141 /**
2142 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002143 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002145 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002146 */
2147 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002148
2149 /**
2150 * Compute an approximation for how much run time (in microseconds) is remaining on
2151 * the battery. Returns -1 if no time can be computed: either there is not
2152 * enough current data to make a decision, or the battery is currently
2153 * charging.
2154 *
2155 * @param curTime The current elepsed realtime in microseconds.
2156 */
2157 public abstract long computeBatteryTimeRemaining(long curTime);
2158
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002159 // The part of a step duration that is the actual time.
2160 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2161
2162 // Bits in a step duration that are the new battery level we are at.
2163 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002164 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002165
2166 // Bits in a step duration that are the initial mode we were in at that step.
2167 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002168 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002169
2170 // Bits in a step duration that indicate which modes changed during that step.
2171 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002172 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002173
2174 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2175 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2176
2177 // Step duration mode: power save is on.
2178 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2179
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002180 // Step duration mode: device is currently in idle mode.
2181 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2182
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002183 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2184 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002185 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2186 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002187 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2188 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2189 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2190 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2191 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002192 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2193 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002194 };
2195 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2196 (Display.STATE_OFF-1),
2197 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002198 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002199 (Display.STATE_ON-1),
2200 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2201 (Display.STATE_DOZE-1),
2202 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2203 (Display.STATE_DOZE_SUSPEND-1),
2204 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002205 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002206 };
2207 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2208 "screen off",
2209 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002210 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002211 "screen on",
2212 "screen on power save",
2213 "screen doze",
2214 "screen doze power save",
2215 "screen doze-suspend",
2216 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002217 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002218 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002219
2220 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002221 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002222 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002223 public abstract LevelStepTracker getDischargeLevelStepTracker();
2224
2225 /**
2226 * Return the array of daily discharge step durations.
2227 */
2228 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002229
2230 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002231 * Compute an approximation for how much time (in microseconds) remains until the battery
2232 * is fully charged. Returns -1 if no time can be computed: either there is not
2233 * enough current data to make a decision, or the battery is currently
2234 * discharging.
2235 *
2236 * @param curTime The current elepsed realtime in microseconds.
2237 */
2238 public abstract long computeChargeTimeRemaining(long curTime);
2239
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002240 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002241 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002242 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002243 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002244
2245 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002246 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002247 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002248 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002249
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002250 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2251
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002252 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002253
Evan Millarc64edde2009-04-18 12:26:32 -07002254 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255
Amith Yamasanie43530a2009-08-21 13:11:37 -07002256 /** Returns the number of different speeds that the CPU can run at */
2257 public abstract int getCpuSpeedSteps();
2258
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002259 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2260
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002261 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 long days = seconds / (60 * 60 * 24);
2263 if (days != 0) {
2264 out.append(days);
2265 out.append("d ");
2266 }
2267 long used = days * 60 * 60 * 24;
2268
2269 long hours = (seconds - used) / (60 * 60);
2270 if (hours != 0 || used != 0) {
2271 out.append(hours);
2272 out.append("h ");
2273 }
2274 used += hours * 60 * 60;
2275
2276 long mins = (seconds-used) / 60;
2277 if (mins != 0 || used != 0) {
2278 out.append(mins);
2279 out.append("m ");
2280 }
2281 used += mins * 60;
2282
2283 if (seconds != 0 || used != 0) {
2284 out.append(seconds-used);
2285 out.append("s ");
2286 }
2287 }
2288
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002289 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002290 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002291 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 sb.append(time - (sec * 1000));
2293 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 }
2295
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002296 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002297 long sec = time / 1000;
2298 formatTimeRaw(sb, sec);
2299 sb.append(time - (sec * 1000));
2300 sb.append("ms");
2301 }
2302
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002303 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002305 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 }
2307 float perc = ((float)num) / ((float)den) * 100;
2308 mFormatBuilder.setLength(0);
2309 mFormatter.format("%.1f%%", perc);
2310 return mFormatBuilder.toString();
2311 }
2312
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002313 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002314 mFormatBuilder.setLength(0);
2315
2316 if (bytes < BYTES_PER_KB) {
2317 return bytes + "B";
2318 } else if (bytes < BYTES_PER_MB) {
2319 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2320 return mFormatBuilder.toString();
2321 } else if (bytes < BYTES_PER_GB){
2322 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2323 return mFormatBuilder.toString();
2324 } else {
2325 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2326 return mFormatBuilder.toString();
2327 }
2328 }
2329
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002330 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002331 if (timer != null) {
2332 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002333 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002334 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2335 return totalTimeMillis;
2336 }
2337 return 0;
2338 }
2339
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002340 /**
2341 *
2342 * @param sb a StringBuilder object.
2343 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002344 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002345 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002346 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 * @param linePrefix a String to be prepended to each line of output.
2348 * @return the line prefix
2349 */
2350 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002351 long elapsedRealtimeUs, String name, int which, String linePrefix) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002354 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002355
Evan Millarc64edde2009-04-18 12:26:32 -07002356 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357 if (totalTimeMillis != 0) {
2358 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002359 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002360 if (name != null) {
2361 sb.append(name);
2362 sb.append(' ');
2363 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 sb.append('(');
2365 sb.append(count);
2366 sb.append(" times)");
2367 return ", ";
2368 }
2369 }
2370 return linePrefix;
2371 }
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002372
2373 /**
2374 *
2375 * @param pw a PrintWriter object to print to.
2376 * @param sb a StringBuilder object.
2377 * @param timer a Timer object contining the wakelock times.
2378 * @param rawRealtime the current on-battery time in microseconds.
2379 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
2380 * @param prefix a String to be prepended to each line of output.
2381 * @param type the name of the timer.
2382 */
2383 private static final boolean printTimer(PrintWriter pw, StringBuilder sb, Timer timer,
2384 long rawRealtime, int which, String prefix, String type) {
2385 if (timer != null) {
2386 // Convert from microseconds to milliseconds with rounding
2387 final long totalTime = (timer.getTotalTimeLocked(
2388 rawRealtime, which) + 500) / 1000;
2389 final int count = timer.getCountLocked(which);
2390 if (totalTime != 0) {
2391 sb.setLength(0);
2392 sb.append(prefix);
2393 sb.append(" ");
2394 sb.append(type);
2395 sb.append(": ");
2396 formatTimeMs(sb, totalTime);
2397 sb.append("realtime (");
2398 sb.append(count);
2399 sb.append(" times)");
2400 pw.println(sb.toString());
2401 return true;
2402 }
2403 }
2404 return false;
2405 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406
2407 /**
2408 * Checkin version of wakelock printer. Prints simple comma-separated list.
2409 *
2410 * @param sb a StringBuilder object.
2411 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002412 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002414 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 * @param linePrefix a String to be prepended to each line of output.
2416 * @return the line prefix
2417 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002418 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2419 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 long totalTimeMicros = 0;
2421 int count = 0;
2422 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002423 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002424 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 }
2426 sb.append(linePrefix);
2427 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2428 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002429 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002430 sb.append(count);
2431 return ",";
2432 }
2433
2434 /**
2435 * Dump a comma-separated line of values for terse checkin mode.
2436 *
2437 * @param pw the PageWriter to dump log to
2438 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2439 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2440 * @param args type-dependent data arguments
2441 */
2442 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2443 Object... args ) {
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002444 pw.print(BATTERY_STATS_CHECKIN_VERSION);
2445 pw.print(',');
2446 pw.print(uid);
2447 pw.print(',');
2448 pw.print(category);
2449 pw.print(',');
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002450 pw.print(type);
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002451
2452 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002453 pw.print(',');
2454 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002456 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002458
2459 /**
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002460 * Dump a given timer stat for terse checkin mode.
2461 *
2462 * @param pw the PageWriter to dump log to
2463 * @param uid the UID to log
2464 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2465 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2466 * @param timer a {@link Timer} to dump stats for
2467 * @param rawRealtime the current elapsed realtime of the system in microseconds
2468 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
2469 */
2470 private static final void dumpTimer(PrintWriter pw, int uid, String category, String type,
2471 Timer timer, long rawRealtime, int which) {
2472 if (timer != null) {
2473 // Convert from microseconds to milliseconds with rounding
2474 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2475 / 1000;
2476 final int count = timer.getCountLocked(which);
2477 if (totalTime != 0) {
2478 dumpLine(pw, uid, category, type, totalTime, count);
2479 }
2480 }
2481 }
2482
2483 /**
Dianne Hackbornd953c532014-08-16 18:17:38 -07002484 * Temporary for settings.
2485 */
2486 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2487 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2488 }
2489
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 /**
2491 * Checkin server version of dump to produce more compact, computer-readable log.
2492 *
2493 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002495 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2496 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2498 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2499 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002500 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2501 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002502 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2503 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2504 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 final long totalRealtime = computeRealtime(rawRealtime, which);
2506 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002507 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002508 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002509 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
2510 final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002511 final long deviceIdlingTime = getDeviceIdlingTime(rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002512 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002513 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002514
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002515 final StringBuilder sb = new StringBuilder(128);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002517 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07002518 final int NU = uidStats.size();
2519
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002520 final String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 // Dump "battery" stat
2523 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002524 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002525 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002526 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002527 getStartClockTime(),
2528 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002530 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002531 long fullWakeLockTimeTotal = 0;
2532 long partialWakeLockTimeTotal = 0;
2533
2534 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002535 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002536
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002537 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
2538 = u.getWakelockStats();
2539 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2540 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07002541
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002542 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2543 if (fullWakeTimer != null) {
2544 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2545 which);
2546 }
2547
2548 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2549 if (partialWakeTimer != null) {
2550 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
2551 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002552 }
2553 }
2554 }
Adam Lesinskie283d332015-04-16 12:29:25 -07002555
2556 // Dump network stats
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002557 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2558 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2559 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2560 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2561 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2562 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2563 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2564 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002565 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2566 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
2567 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets);
2568
Adam Lesinskie283d332015-04-16 12:29:25 -07002569 // Dump Wifi controller stats
2570 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2571 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
2572 final long wifiIdleTimeMs = getWifiControllerActivity(CONTROLLER_IDLE_TIME, which);
2573 final long wifiRxTimeMs = getWifiControllerActivity(CONTROLLER_RX_TIME, which);
2574 final long wifiTxTimeMs = getWifiControllerActivity(CONTROLLER_TX_TIME, which);
2575 final long wifiPowerMaMs = getWifiControllerActivity(CONTROLLER_POWER_DRAIN, which);
2576 dumpLine(pw, 0 /* uid */, category, GLOBAL_WIFI_DATA,
2577 wifiOnTime / 1000, wifiRunningTime / 1000,
2578 wifiIdleTimeMs, wifiRxTimeMs, wifiTxTimeMs, wifiPowerMaMs / (1000*60*60));
2579
2580 // Dump Bluetooth controller stats
2581 final long btIdleTimeMs = getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which);
2582 final long btRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which);
2583 final long btTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which);
2584 final long btPowerMaMs = getBluetoothControllerActivity(CONTROLLER_POWER_DRAIN, which);
2585 dumpLine(pw, 0 /* uid */, category, GLOBAL_BLUETOOTH_DATA,
2586 btIdleTimeMs, btRxTimeMs, btTxTimeMs, btPowerMaMs / (1000*60*60));
2587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 // Dump misc stats
2589 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07002590 screenOnTime / 1000, phoneOnTime / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002591 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
Adam Lesinskie283d332015-04-16 12:29:25 -07002592 getMobileRadioActiveTime(rawRealtime, which) / 1000,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002593 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002594 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeEnabledTime / 1000,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002595 getDeviceIdleModeEnabledCount(which), deviceIdlingTime / 1000,
2596 getDeviceIdlingCount(which));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002597
2598 // Dump screen brightness stats
2599 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2600 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002601 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002602 }
2603 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002604
Dianne Hackborn627bba72009-03-24 22:32:56 -07002605 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002606 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2607 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002608 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002609 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002610 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002611 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002612 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002613 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002614 args[i] = getPhoneSignalStrengthCount(i, which);
2615 }
2616 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002617
Dianne Hackborn627bba72009-03-24 22:32:56 -07002618 // Dump network type stats
2619 args = new Object[NUM_DATA_CONNECTION_TYPES];
2620 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002621 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002622 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002623 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2624 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2625 args[i] = getPhoneDataConnectionCount(i, which);
2626 }
2627 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002628
2629 // Dump wifi state stats
2630 args = new Object[NUM_WIFI_STATES];
2631 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002632 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002633 }
2634 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2635 for (int i=0; i<NUM_WIFI_STATES; i++) {
2636 args[i] = getWifiStateCount(i, which);
2637 }
2638 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2639
Dianne Hackborn3251b902014-06-20 14:40:53 -07002640 // Dump wifi suppl state stats
2641 args = new Object[NUM_WIFI_SUPPL_STATES];
2642 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2643 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2644 }
2645 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2646 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2647 args[i] = getWifiSupplStateCount(i, which);
2648 }
2649 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
2650
2651 // Dump wifi signal strength stats
2652 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
2653 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2654 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
2655 }
2656 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
2657 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2658 args[i] = getWifiSignalStrengthCount(i, which);
2659 }
2660 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
2661
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002662 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002663 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07002664 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002665 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002667 if (which == STATS_SINCE_UNPLUGGED) {
2668 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2669 getDischargeStartLevel()-getDischargeCurrentLevel(),
2670 getDischargeStartLevel()-getDischargeCurrentLevel(),
2671 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
2672 } else {
2673 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2674 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002675 getDischargeAmountScreenOnSinceCharge(),
2676 getDischargeAmountScreenOffSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002677 }
2678
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002679 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002680 final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002681 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002682 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002683 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002684 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002685 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002686 sb.toString());
2687 }
Evan Millarc64edde2009-04-18 12:26:32 -07002688 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002689 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002690 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002691 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
2692 // Not doing the regular wake lock formatting to remain compatible
2693 // with the old checkin format.
2694 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
2695 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002696 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002697 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002698 }
2699 }
Evan Millarc64edde2009-04-18 12:26:32 -07002700 }
2701
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002702 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002703 helper.create(this);
2704 helper.refreshStats(which, UserHandle.USER_ALL);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002705 final List<BatterySipper> sippers = helper.getUsageList();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002706 if (sippers != null && sippers.size() > 0) {
2707 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
2708 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08002709 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002710 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
2711 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
2712 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002713 final BatterySipper bs = sippers.get(i);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002714 int uid = 0;
2715 String label;
2716 switch (bs.drainType) {
2717 case IDLE:
2718 label="idle";
2719 break;
2720 case CELL:
2721 label="cell";
2722 break;
2723 case PHONE:
2724 label="phone";
2725 break;
2726 case WIFI:
2727 label="wifi";
2728 break;
2729 case BLUETOOTH:
2730 label="blue";
2731 break;
2732 case SCREEN:
2733 label="scrn";
2734 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002735 case FLASHLIGHT:
2736 label="flashlight";
2737 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002738 case APP:
2739 uid = bs.uidObj.getUid();
2740 label = "uid";
2741 break;
2742 case USER:
2743 uid = UserHandle.getUid(bs.userId, 0);
2744 label = "user";
2745 break;
2746 case UNACCOUNTED:
2747 label = "unacc";
2748 break;
2749 case OVERCOUNTED:
2750 label = "over";
2751 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07002752 case CAMERA:
2753 label = "camera";
2754 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002755 default:
2756 label = "???";
2757 }
2758 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
Adam Lesinskie08af192015-03-25 16:42:59 -07002759 BatteryStatsHelper.makemAh(bs.totalPowerMah));
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002760 }
2761 }
2762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 for (int iu = 0; iu < NU; iu++) {
2764 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002765 if (reqUid >= 0 && uid != reqUid) {
2766 continue;
2767 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002768 final Uid u = uidStats.valueAt(iu);
Adam Lesinskie283d332015-04-16 12:29:25 -07002769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002770 // Dump Network stats per uid, if any
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002771 final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2772 final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2773 final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2774 final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2775 final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2776 final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2777 final long mobileActiveTime = u.getMobileRadioActiveTime(which);
2778 final int mobileActiveCount = u.getMobileRadioActiveCount(which);
2779 final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2780 final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002781 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
2782 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002783 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002784 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
2785 wifiBytesRx, wifiBytesTx,
2786 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002787 wifiPacketsRx, wifiPacketsTx,
2788 mobileActiveTime, mobileActiveCount);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002789 }
2790
Adam Lesinskie283d332015-04-16 12:29:25 -07002791 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
2792 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
2793 final int wifiScanCount = u.getWifiScanCount(which);
2794 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
2795 final long uidWifiIdleTimeMs = u.getWifiControllerActivity(CONTROLLER_IDLE_TIME, which);
2796 final long uidWifiRxTimeMs = u.getWifiControllerActivity(CONTROLLER_RX_TIME, which);
2797 final long uidWifiTxTimeMs = u.getWifiControllerActivity(CONTROLLER_TX_TIME, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07002798 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Adam Lesinskie283d332015-04-16 12:29:25 -07002799 || uidWifiRunningTime != 0 || uidWifiIdleTimeMs != 0 || uidWifiRxTimeMs != 0
2800 || uidWifiTxTimeMs != 0) {
Nick Pelly6ccaa542012-06-15 15:22:47 -07002801 dumpLine(pw, uid, category, WIFI_DATA,
Adam Lesinskie283d332015-04-16 12:29:25 -07002802 fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime, wifiScanCount,
2803 uidWifiIdleTimeMs, uidWifiRxTimeMs, uidWifiTxTimeMs);
The Android Open Source Project10592532009-03-18 17:39:46 -07002804 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805
Dianne Hackborn617f8772009-03-31 15:04:46 -07002806 if (u.hasUserActivity()) {
2807 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
2808 boolean hasData = false;
2809 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
2810 int val = u.getUserActivityCount(i, which);
2811 args[i] = val;
2812 if (val != 0) hasData = true;
2813 }
2814 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07002815 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002816 }
2817 }
2818
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002819 final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
2820 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
2821 final Uid.Wakelock wl = wakelocks.valueAt(iw);
2822 String linePrefix = "";
2823 sb.setLength(0);
2824 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
2825 rawRealtime, "f", which, linePrefix);
2826 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
2827 rawRealtime, "p", which, linePrefix);
2828 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
2829 rawRealtime, "w", which, linePrefix);
2830
2831 // Only log if we had at lease one wakelock...
2832 if (sb.length() > 0) {
2833 String name = wakelocks.keyAt(iw);
2834 if (name.indexOf(',') >= 0) {
2835 name = name.replace(',', '_');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002837 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 }
2839 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07002840
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002841 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
2842 for (int isy=syncs.size()-1; isy>=0; isy--) {
2843 final Timer timer = syncs.valueAt(isy);
2844 // Convert from microseconds to milliseconds with rounding
2845 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2846 final int count = timer.getCountLocked(which);
2847 if (totalTime != 0) {
2848 dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002849 }
2850 }
2851
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002852 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
2853 for (int ij=jobs.size()-1; ij>=0; ij--) {
2854 final Timer timer = jobs.valueAt(ij);
2855 // Convert from microseconds to milliseconds with rounding
2856 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2857 final int count = timer.getCountLocked(which);
2858 if (totalTime != 0) {
2859 dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002860 }
2861 }
2862
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002863 dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(),
2864 rawRealtime, which);
2865 dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(),
2866 rawRealtime, which);
2867 dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(),
2868 rawRealtime, which);
2869 dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(),
2870 rawRealtime, which);
2871
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002872 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
2873 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07002874 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002875 final Uid.Sensor se = sensors.valueAt(ise);
2876 final int sensorNumber = sensors.keyAt(ise);
2877 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07002878 if (timer != null) {
2879 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002880 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500)
2881 / 1000;
2882 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07002883 if (totalTime != 0) {
2884 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
2885 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 }
2887 }
2888
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002889 dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(),
2890 rawRealtime, which);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002891
Ruben Brunk6d2c3632015-05-26 17:32:16 -07002892 dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(),
2893 rawRealtime, which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002894
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002895 final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
Dianne Hackborn61659e52014-07-09 16:13:01 -07002896 long totalStateTime = 0;
2897 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
2898 totalStateTime += u.getProcessStateTime(ips, rawRealtime, which);
2899 stateTimes[ips] = (totalStateTime + 500) / 1000;
2900 }
2901 if (totalStateTime > 0) {
2902 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
2903 }
2904
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002905 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
2906 = u.getProcessStats();
2907 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
2908 final Uid.Proc ps = processStats.valueAt(ipr);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002909
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002910 final long userMillis = ps.getUserTime(which);
2911 final long systemMillis = ps.getSystemTime(which);
2912 final long foregroundMillis = ps.getForegroundTime(which);
2913 final int starts = ps.getStarts(which);
2914 final int numCrashes = ps.getNumCrashes(which);
2915 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002916
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002917 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
2918 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
2919 dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis,
2920 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 }
2922 }
2923
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002924 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
2925 = u.getPackageStats();
2926 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
2927 final Uid.Pkg ps = packageStats.valueAt(ipkg);
2928 int wakeups = 0;
2929 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
2930 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
2931 wakeups += alarms.valueAt(iwa).getCountLocked(which);
2932 }
2933 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
2934 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
2935 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
2936 final long startTime = ss.getStartTime(batteryUptime, which);
2937 final int starts = ss.getStarts(which);
2938 final int launches = ss.getLaunches(which);
2939 if (startTime != 0 || starts != 0 || launches != 0) {
2940 dumpLine(pw, uid, category, APK_DATA,
2941 wakeups, // wakeup alarms
2942 packageStats.keyAt(ipkg), // Apk
2943 serviceStats.keyAt(isvc), // service
2944 startTime / 1000, // time spent started, in ms
2945 starts,
2946 launches);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 }
2948 }
2949 }
2950 }
2951 }
2952
Dianne Hackborn81038902012-11-26 17:04:09 -08002953 static final class TimerEntry {
2954 final String mName;
2955 final int mId;
2956 final BatteryStats.Timer mTimer;
2957 final long mTime;
2958 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
2959 mName = name;
2960 mId = id;
2961 mTimer = timer;
2962 mTime = time;
2963 }
2964 }
2965
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002966 private void printmAh(PrintWriter printer, double power) {
2967 printer.print(BatteryStatsHelper.makemAh(power));
2968 }
2969
Dianne Hackbornd953c532014-08-16 18:17:38 -07002970 /**
2971 * Temporary for settings.
2972 */
2973 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
2974 int reqUid) {
2975 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2976 }
2977
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002979 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07002980 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2982 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2983 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984
2985 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2986 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
2987 final long totalRealtime = computeRealtime(rawRealtime, which);
2988 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002989 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2990 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2991 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002992 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
2993 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002994
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002995 final StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07002996
Dianne Hackborn1e725a72015-03-24 18:23:19 -07002997 final SparseArray<? extends Uid> uidStats = getUidStats();
Evan Millar22ac0432009-03-31 11:33:18 -07002998 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003000 sb.setLength(0);
3001 sb.append(prefix);
3002 sb.append(" Time on battery: ");
3003 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
3004 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
3005 sb.append(") realtime, ");
3006 formatTimeMs(sb, whichBatteryUptime / 1000);
3007 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
3008 sb.append(") uptime");
3009 pw.println(sb.toString());
3010 sb.setLength(0);
3011 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003012 sb.append(" Time on battery screen off: ");
3013 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
3014 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
3015 sb.append(") realtime, ");
3016 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
3017 sb.append("(");
3018 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
3019 sb.append(") uptime");
3020 pw.println(sb.toString());
3021 sb.setLength(0);
3022 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003023 sb.append(" Total run time: ");
3024 formatTimeMs(sb, totalRealtime / 1000);
3025 sb.append("realtime, ");
3026 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003027 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07003028 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07003029 if (batteryTimeRemaining >= 0) {
3030 sb.setLength(0);
3031 sb.append(prefix);
3032 sb.append(" Battery time remaining: ");
3033 formatTimeMs(sb, batteryTimeRemaining / 1000);
3034 pw.println(sb.toString());
3035 }
3036 if (chargeTimeRemaining >= 0) {
3037 sb.setLength(0);
3038 sb.append(prefix);
3039 sb.append(" Charge time remaining: ");
3040 formatTimeMs(sb, chargeTimeRemaining / 1000);
3041 pw.println(sb.toString());
3042 }
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08003043 pw.print(" Start clock time: ");
3044 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
3045
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003046 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07003047 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003048 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
3049 final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003050 final long deviceIdlingTime = getDeviceIdlingTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003051 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
3052 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
3053 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003054 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003055 sb.append(prefix);
3056 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
3057 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003058 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003059 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
3060 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07003061 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003062 pw.println(sb.toString());
3063 sb.setLength(0);
3064 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003065 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003066 boolean didOne = false;
3067 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003068 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003069 if (time == 0) {
3070 continue;
3071 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003072 sb.append("\n ");
3073 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003074 didOne = true;
3075 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
3076 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003077 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003078 sb.append("(");
3079 sb.append(formatRatioLocked(time, screenOnTime));
3080 sb.append(")");
3081 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003082 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003083 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003084 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003085 sb.setLength(0);
3086 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003087 sb.append(" Power save mode enabled: ");
3088 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003089 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003090 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003091 sb.append(")");
3092 pw.println(sb.toString());
3093 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003094 if (deviceIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003095 sb.setLength(0);
3096 sb.append(prefix);
3097 sb.append(" Device idling: ");
Dianne Hackborn88e98df2015-03-23 13:29:14 -07003098 formatTimeMs(sb, deviceIdlingTime / 1000);
3099 sb.append("(");
3100 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
3101 sb.append(") "); sb.append(getDeviceIdlingCount(which));
3102 sb.append("x");
3103 pw.println(sb.toString());
3104 }
3105 if (deviceIdleModeEnabledTime != 0) {
3106 sb.setLength(0);
3107 sb.append(prefix);
3108 sb.append(" Idle mode time: ");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003109 formatTimeMs(sb, deviceIdleModeEnabledTime / 1000);
3110 sb.append("(");
3111 sb.append(formatRatioLocked(deviceIdleModeEnabledTime, whichBatteryRealtime));
3112 sb.append(") "); sb.append(getDeviceIdleModeEnabledCount(which));
3113 sb.append("x");
3114 pw.println(sb.toString());
3115 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003116 if (phoneOnTime != 0) {
3117 sb.setLength(0);
3118 sb.append(prefix);
3119 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
3120 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07003121 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003122 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003123 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003124 if (connChanges != 0) {
3125 pw.print(prefix);
3126 pw.print(" Connectivity changes: "); pw.println(connChanges);
3127 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003128
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003129 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003130 long fullWakeLockTimeTotalMicros = 0;
3131 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003132
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003133 final ArrayList<TimerEntry> timers = new ArrayList<>();
Dianne Hackborn81038902012-11-26 17:04:09 -08003134
Evan Millar22ac0432009-03-31 11:33:18 -07003135 for (int iu = 0; iu < NU; iu++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003136 final Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003137
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003138 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3139 = u.getWakelockStats();
3140 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3141 final Uid.Wakelock wl = wakelocks.valueAt(iw);
Evan Millar22ac0432009-03-31 11:33:18 -07003142
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003143 final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3144 if (fullWakeTimer != null) {
3145 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
3146 rawRealtime, which);
3147 }
3148
3149 final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3150 if (partialWakeTimer != null) {
3151 final long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
3152 rawRealtime, which);
3153 if (totalTimeMicros > 0) {
3154 if (reqUid < 0) {
3155 // Only show the ordered list of all wake
3156 // locks if the caller is not asking for data
3157 // about a specific uid.
3158 timers.add(new TimerEntry(wakelocks.keyAt(iw), u.getUid(),
3159 partialWakeTimer, totalTimeMicros));
Dianne Hackborn81038902012-11-26 17:04:09 -08003160 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003161 partialWakeLockTimeTotalMicros += totalTimeMicros;
Evan Millar22ac0432009-03-31 11:33:18 -07003162 }
3163 }
3164 }
3165 }
3166
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003167 final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3168 final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3169 final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3170 final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3171 final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3172 final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3173 final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3174 final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003175
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003176 if (fullWakeLockTimeTotalMicros != 0) {
3177 sb.setLength(0);
3178 sb.append(prefix);
3179 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3180 (fullWakeLockTimeTotalMicros + 500) / 1000);
3181 pw.println(sb.toString());
3182 }
3183
3184 if (partialWakeLockTimeTotalMicros != 0) {
3185 sb.setLength(0);
3186 sb.append(prefix);
3187 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3188 (partialWakeLockTimeTotalMicros + 500) / 1000);
3189 pw.println(sb.toString());
3190 }
3191
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003192 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003193 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3194 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3195 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3196 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003197 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003198 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003199 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003200 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003201 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003202 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003203 if (time == 0) {
3204 continue;
3205 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003206 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003207 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003208 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003209 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003210 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003211 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003212 sb.append("(");
3213 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003214 sb.append(") ");
3215 sb.append(getPhoneSignalStrengthCount(i, which));
3216 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003217 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003218 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003219 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003220
3221 sb.setLength(0);
3222 sb.append(prefix);
3223 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003224 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003225 pw.println(sb.toString());
3226
Dianne Hackborn627bba72009-03-24 22:32:56 -07003227 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003228 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003229 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003230 didOne = false;
3231 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003232 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003233 if (time == 0) {
3234 continue;
3235 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003236 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003237 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003238 didOne = true;
3239 sb.append(DATA_CONNECTION_NAMES[i]);
3240 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003241 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003242 sb.append("(");
3243 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003244 sb.append(") ");
3245 sb.append(getPhoneDataConnectionCount(i, which));
3246 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003247 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003248 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003249 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003250
3251 sb.setLength(0);
3252 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003253 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003254 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003255 formatTimeMs(sb, mobileActiveTime / 1000);
3256 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3257 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3258 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003259 pw.println(sb.toString());
3260
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003261 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3262 if (mobileActiveUnknownTime != 0) {
3263 sb.setLength(0);
3264 sb.append(prefix);
3265 sb.append(" Mobile radio active unknown time: ");
3266 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3267 sb.append("(");
3268 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3269 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3270 sb.append("x");
3271 pw.println(sb.toString());
3272 }
3273
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003274 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3275 if (mobileActiveAdjustedTime != 0) {
3276 sb.setLength(0);
3277 sb.append(prefix);
3278 sb.append(" Mobile radio active adjusted time: ");
3279 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3280 sb.append("(");
3281 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3282 sb.append(")");
3283 pw.println(sb.toString());
3284 }
3285
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003286 pw.print(prefix);
3287 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3288 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3289 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3290 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003291 sb.setLength(0);
3292 sb.append(prefix);
3293 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3294 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3295 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3296 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003297 sb.append(")");
3298 pw.println(sb.toString());
3299
3300 sb.setLength(0);
3301 sb.append(prefix);
3302 sb.append(" Wifi states:");
3303 didOne = false;
3304 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003305 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003306 if (time == 0) {
3307 continue;
3308 }
3309 sb.append("\n ");
3310 didOne = true;
3311 sb.append(WIFI_STATE_NAMES[i]);
3312 sb.append(" ");
3313 formatTimeMs(sb, time/1000);
3314 sb.append("(");
3315 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3316 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003317 sb.append(getWifiStateCount(i, which));
3318 sb.append("x");
3319 }
3320 if (!didOne) sb.append(" (no activity)");
3321 pw.println(sb.toString());
3322
3323 sb.setLength(0);
3324 sb.append(prefix);
3325 sb.append(" Wifi supplicant states:");
3326 didOne = false;
3327 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3328 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3329 if (time == 0) {
3330 continue;
3331 }
3332 sb.append("\n ");
3333 didOne = true;
3334 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3335 sb.append(" ");
3336 formatTimeMs(sb, time/1000);
3337 sb.append("(");
3338 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3339 sb.append(") ");
3340 sb.append(getWifiSupplStateCount(i, which));
3341 sb.append("x");
3342 }
3343 if (!didOne) sb.append(" (no activity)");
3344 pw.println(sb.toString());
3345
3346 sb.setLength(0);
3347 sb.append(prefix);
3348 sb.append(" Wifi signal levels:");
3349 didOne = false;
3350 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3351 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3352 if (time == 0) {
3353 continue;
3354 }
3355 sb.append("\n ");
3356 sb.append(prefix);
3357 didOne = true;
3358 sb.append("level(");
3359 sb.append(i);
3360 sb.append(") ");
3361 formatTimeMs(sb, time/1000);
3362 sb.append("(");
3363 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3364 sb.append(") ");
3365 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003366 sb.append("x");
3367 }
3368 if (!didOne) sb.append(" (no activity)");
3369 pw.println(sb.toString());
3370
Adam Lesinski4b6bd8d2015-03-19 14:35:45 -07003371 final long wifiIdleTimeMs = getWifiControllerActivity(CONTROLLER_IDLE_TIME, which);
3372 final long wifiRxTimeMs = getWifiControllerActivity(CONTROLLER_RX_TIME, which);
3373 final long wifiTxTimeMs = getWifiControllerActivity(CONTROLLER_TX_TIME, which);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003374 final long wifiPowerDrainMaMs = getWifiControllerActivity(CONTROLLER_POWER_DRAIN, which);
Adam Lesinski33dac552015-03-09 15:24:48 -07003375 final long wifiTotalTimeMs = wifiIdleTimeMs + wifiRxTimeMs + wifiTxTimeMs;
3376
3377 sb.setLength(0);
3378 sb.append(prefix);
3379 sb.append(" WiFi Idle time: "); formatTimeMs(sb, wifiIdleTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003380 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003381 sb.append(formatRatioLocked(wifiIdleTimeMs, wifiTotalTimeMs));
3382 sb.append(")");
3383 pw.println(sb.toString());
3384
3385 sb.setLength(0);
3386 sb.append(prefix);
3387 sb.append(" WiFi Rx time: "); formatTimeMs(sb, wifiRxTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003388 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003389 sb.append(formatRatioLocked(wifiRxTimeMs, wifiTotalTimeMs));
3390 sb.append(")");
3391 pw.println(sb.toString());
3392
3393 sb.setLength(0);
3394 sb.append(prefix);
3395 sb.append(" WiFi Tx time: "); formatTimeMs(sb, wifiTxTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003396 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003397 sb.append(formatRatioLocked(wifiTxTimeMs, wifiTotalTimeMs));
3398 sb.append(")");
3399 pw.println(sb.toString());
3400
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003401 sb.setLength(0);
3402 sb.append(prefix);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003403 sb.append(" WiFi Power drain: ").append(
3404 BatteryStatsHelper.makemAh(wifiPowerDrainMaMs / (double) (1000*60*60)));
3405 sb.append("mAh");
Adam Lesinskie08af192015-03-25 16:42:59 -07003406 pw.println(sb.toString());
3407
Adam Lesinski33dac552015-03-09 15:24:48 -07003408 final long bluetoothIdleTimeMs =
3409 getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which);
3410 final long bluetoothRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which);
3411 final long bluetoothTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which);
3412 final long bluetoothTotalTimeMs = bluetoothIdleTimeMs + bluetoothRxTimeMs +
3413 bluetoothTxTimeMs;
3414
3415 sb.setLength(0);
3416 sb.append(prefix);
3417 sb.append(" Bluetooth Idle time: "); formatTimeMs(sb, bluetoothIdleTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003418 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003419 sb.append(formatRatioLocked(bluetoothIdleTimeMs, bluetoothTotalTimeMs));
3420 sb.append(")");
3421 pw.println(sb.toString());
3422
3423 sb.setLength(0);
3424 sb.append(prefix);
3425 sb.append(" Bluetooth Rx time: "); formatTimeMs(sb, bluetoothRxTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003426 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003427 sb.append(formatRatioLocked(bluetoothRxTimeMs, bluetoothTotalTimeMs));
3428 sb.append(")");
3429 pw.println(sb.toString());
3430
3431 sb.setLength(0);
3432 sb.append(prefix);
3433 sb.append(" Bluetooth Tx time: "); formatTimeMs(sb, bluetoothTxTimeMs);
Adam Lesinski049c88b2015-05-28 11:38:12 -07003434 sb.append("(");
Adam Lesinski33dac552015-03-09 15:24:48 -07003435 sb.append(formatRatioLocked(bluetoothTxTimeMs, bluetoothTotalTimeMs));
3436 sb.append(")");
3437 pw.println(sb.toString());
3438
Adam Lesinskie283d332015-04-16 12:29:25 -07003439 sb.setLength(0);
3440 sb.append(prefix);
3441 sb.append(" Bluetooth Power drain: ").append(BatteryStatsHelper.makemAh(
3442 getBluetoothControllerActivity(CONTROLLER_POWER_DRAIN, which) /
3443 (double)(1000*60*60)));
Adam Lesinski049c88b2015-05-28 11:38:12 -07003444 sb.append("mAh");
Adam Lesinskie283d332015-04-16 12:29:25 -07003445 pw.println(sb.toString());
3446
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003447 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003448
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003449 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003450 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003451 pw.print(prefix); pw.println(" Device is currently unplugged");
3452 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3453 pw.println(getDischargeStartLevel());
3454 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3455 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003456 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003457 pw.print(prefix); pw.println(" Device is currently plugged into power");
3458 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3459 pw.println(getDischargeStartLevel());
3460 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3461 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003462 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003463 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3464 pw.println(getDischargeAmountScreenOn());
3465 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3466 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003467 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003468 } else {
3469 pw.print(prefix); pw.println(" Device battery use since last full charge");
3470 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3471 pw.println(getLowDischargeAmountSinceCharge());
3472 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3473 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003474 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3475 pw.println(getDischargeAmountScreenOnSinceCharge());
3476 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3477 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003478 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003479 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003480
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003481 final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003482 helper.create(this);
3483 helper.refreshStats(which, UserHandle.USER_ALL);
3484 List<BatterySipper> sippers = helper.getUsageList();
3485 if (sippers != null && sippers.size() > 0) {
3486 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3487 pw.print(prefix); pw.print(" Capacity: ");
3488 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003489 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003490 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3491 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3492 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3493 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003494 pw.println();
3495 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003496 final BatterySipper bs = sippers.get(i);
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003497 pw.print(prefix);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003498 switch (bs.drainType) {
3499 case IDLE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003500 pw.print(" Idle: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003501 break;
3502 case CELL:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003503 pw.print(" Cell standby: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003504 break;
3505 case PHONE:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003506 pw.print(" Phone calls: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003507 break;
3508 case WIFI:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003509 pw.print(" Wifi: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003510 break;
3511 case BLUETOOTH:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003512 pw.print(" Bluetooth: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003513 break;
3514 case SCREEN:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003515 pw.print(" Screen: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003516 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003517 case FLASHLIGHT:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003518 pw.print(" Flashlight: ");
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003519 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003520 case APP:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003521 pw.print(" Uid ");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003522 UserHandle.formatUid(pw, bs.uidObj.getUid());
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003523 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003524 break;
3525 case USER:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003526 pw.print(" User "); pw.print(bs.userId);
3527 pw.print(": ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003528 break;
3529 case UNACCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003530 pw.print(" Unaccounted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003531 break;
3532 case OVERCOUNTED:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003533 pw.print(" Over-counted: ");
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003534 break;
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003535 case CAMERA:
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003536 pw.print(" Camera: ");
3537 break;
3538 default:
3539 pw.print(" ???: ");
Ruben Brunk5b1308f2015-06-03 18:49:27 -07003540 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003541 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003542 printmAh(pw, bs.totalPowerMah);
3543
Adam Lesinski57123002015-06-12 16:12:07 -07003544 if (bs.usagePowerMah != bs.totalPowerMah) {
3545 // If the usage (generic power) isn't the whole amount, we list out
3546 // what components are involved in the calculation.
3547
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003548 pw.print(" (");
Adam Lesinski57123002015-06-12 16:12:07 -07003549 if (bs.usagePowerMah != 0) {
3550 pw.print(" usage=");
3551 printmAh(pw, bs.usagePowerMah);
3552 }
Adam Lesinski628ef9c2015-06-10 13:08:57 -07003553 if (bs.cpuPowerMah != 0) {
3554 pw.print(" cpu=");
3555 printmAh(pw, bs.cpuPowerMah);
3556 }
3557 if (bs.wakeLockPowerMah != 0) {
3558 pw.print(" wake=");
3559 printmAh(pw, bs.wakeLockPowerMah);
3560 }
3561 if (bs.mobileRadioPowerMah != 0) {
3562 pw.print(" radio=");
3563 printmAh(pw, bs.mobileRadioPowerMah);
3564 }
3565 if (bs.wifiPowerMah != 0) {
3566 pw.print(" wifi=");
3567 printmAh(pw, bs.wifiPowerMah);
3568 }
3569 if (bs.gpsPowerMah != 0) {
3570 pw.print(" gps=");
3571 printmAh(pw, bs.gpsPowerMah);
3572 }
3573 if (bs.sensorPowerMah != 0) {
3574 pw.print(" sensor=");
3575 printmAh(pw, bs.sensorPowerMah);
3576 }
3577 if (bs.cameraPowerMah != 0) {
3578 pw.print(" camera=");
3579 printmAh(pw, bs.cameraPowerMah);
3580 }
3581 if (bs.flashlightPowerMah != 0) {
3582 pw.print(" flash=");
3583 printmAh(pw, bs.flashlightPowerMah);
3584 }
3585 pw.print(" )");
3586 }
3587 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003588 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08003589 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003590 }
3591
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003592 sippers = helper.getMobilemsppList();
3593 if (sippers != null && sippers.size() > 0) {
3594 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003595 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003596 for (int i=0; i<sippers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003597 final BatterySipper bs = sippers.get(i);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003598 sb.setLength(0);
3599 sb.append(prefix); sb.append(" Uid ");
3600 UserHandle.formatUid(sb, bs.uidObj.getUid());
3601 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
3602 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
3603 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003604 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003605 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003606 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003607 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003608 sb.setLength(0);
3609 sb.append(prefix);
3610 sb.append(" TOTAL TIME: ");
3611 formatTimeMs(sb, totalTime);
3612 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
3613 sb.append(")");
3614 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003615 pw.println();
3616 }
3617
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003618 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
3619 @Override
3620 public int compare(TimerEntry lhs, TimerEntry rhs) {
3621 long lhsTime = lhs.mTime;
3622 long rhsTime = rhs.mTime;
3623 if (lhsTime < rhsTime) {
3624 return 1;
3625 }
3626 if (lhsTime > rhsTime) {
3627 return -1;
3628 }
3629 return 0;
3630 }
3631 };
3632
3633 if (reqUid < 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003634 final Map<String, ? extends BatteryStats.Timer> kernelWakelocks
3635 = getKernelWakelockStats();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003636 if (kernelWakelocks.size() > 0) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003637 final ArrayList<TimerEntry> ktimers = new ArrayList<>();
3638 for (Map.Entry<String, ? extends BatteryStats.Timer> ent
3639 : kernelWakelocks.entrySet()) {
3640 final BatteryStats.Timer timer = ent.getValue();
3641 final long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003642 if (totalTimeMillis > 0) {
3643 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
3644 }
3645 }
3646 if (ktimers.size() > 0) {
3647 Collections.sort(ktimers, timerComparator);
3648 pw.print(prefix); pw.println(" All kernel wake locks:");
3649 for (int i=0; i<ktimers.size(); i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003650 final TimerEntry timer = ktimers.get(i);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003651 String linePrefix = ": ";
3652 sb.setLength(0);
3653 sb.append(prefix);
3654 sb.append(" Kernel Wake lock ");
3655 sb.append(timer.mName);
3656 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
3657 which, linePrefix);
3658 if (!linePrefix.equals(": ")) {
3659 sb.append(" realtime");
3660 // Only print out wake locks that were held
3661 pw.println(sb.toString());
3662 }
3663 }
3664 pw.println();
3665 }
3666 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003667
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003668 if (timers.size() > 0) {
3669 Collections.sort(timers, timerComparator);
3670 pw.print(prefix); pw.println(" All partial wake locks:");
3671 for (int i=0; i<timers.size(); i++) {
3672 TimerEntry timer = timers.get(i);
3673 sb.setLength(0);
3674 sb.append(" Wake lock ");
3675 UserHandle.formatUid(sb, timer.mId);
3676 sb.append(" ");
3677 sb.append(timer.mName);
3678 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3679 sb.append(" realtime");
3680 pw.println(sb.toString());
3681 }
3682 timers.clear();
3683 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08003684 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003685
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003686 final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003687 if (wakeupReasons.size() > 0) {
3688 pw.print(prefix); pw.println(" All wakeup reasons:");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003689 final ArrayList<TimerEntry> reasons = new ArrayList<>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003690 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003691 final Timer timer = ent.getValue();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003692 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
3693 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003694 }
3695 Collections.sort(reasons, timerComparator);
3696 for (int i=0; i<reasons.size(); i++) {
3697 TimerEntry timer = reasons.get(i);
3698 String linePrefix = ": ";
3699 sb.setLength(0);
3700 sb.append(prefix);
3701 sb.append(" Wakeup reason ");
3702 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003703 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3704 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003705 pw.println(sb.toString());
3706 }
3707 pw.println();
3708 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003709 }
Evan Millar22ac0432009-03-31 11:33:18 -07003710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003711 for (int iu=0; iu<NU; iu++) {
3712 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08003713 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003714 continue;
3715 }
3716
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003717 final Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07003718
3719 pw.print(prefix);
3720 pw.print(" ");
3721 UserHandle.formatUid(pw, uid);
3722 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003723 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003724
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003725 final long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3726 final long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3727 final long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3728 final long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3729 final long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3730 final long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3731 final long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
3732 final int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
3733 final long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3734 final long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
3735 final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3736 final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3737 final int wifiScanCount = u.getWifiScanCount(which);
3738 final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003739
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003740 if (mobileRxBytes > 0 || mobileTxBytes > 0
3741 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003742 pw.print(prefix); pw.print(" Mobile network: ");
3743 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003744 pw.print(formatBytesLocked(mobileTxBytes));
3745 pw.print(" sent (packets "); pw.print(mobileRxPackets);
3746 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003748 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
3749 sb.setLength(0);
3750 sb.append(prefix); sb.append(" Mobile radio active: ");
3751 formatTimeMs(sb, uidMobileActiveTime / 1000);
3752 sb.append("(");
3753 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
3754 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
3755 long packets = mobileRxPackets + mobileTxPackets;
3756 if (packets == 0) {
3757 packets = 1;
3758 }
3759 sb.append(" @ ");
3760 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
3761 sb.append(" mspp");
3762 pw.println(sb.toString());
3763 }
3764
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003765 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003766 pw.print(prefix); pw.print(" Wi-Fi network: ");
3767 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003768 pw.print(formatBytesLocked(wifiTxBytes));
3769 pw.print(" sent (packets "); pw.print(wifiRxPackets);
3770 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003771 }
3772
Dianne Hackborn62793e42015-03-09 11:15:41 -07003773 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003774 || uidWifiRunningTime != 0) {
3775 sb.setLength(0);
3776 sb.append(prefix); sb.append(" Wifi Running: ");
3777 formatTimeMs(sb, uidWifiRunningTime / 1000);
3778 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
3779 whichBatteryRealtime)); sb.append(")\n");
3780 sb.append(prefix); sb.append(" Full Wifi Lock: ");
3781 formatTimeMs(sb, fullWifiLockOnTime / 1000);
3782 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
3783 whichBatteryRealtime)); sb.append(")\n");
3784 sb.append(prefix); sb.append(" Wifi Scan: ");
3785 formatTimeMs(sb, wifiScanTime / 1000);
3786 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07003787 whichBatteryRealtime)); sb.append(") ");
3788 sb.append(wifiScanCount);
3789 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003790 pw.println(sb.toString());
3791 }
3792
Adam Lesinski049c88b2015-05-28 11:38:12 -07003793 final long uidWifiIdleTimeMs = u.getWifiControllerActivity(CONTROLLER_IDLE_TIME, which);
3794 final long uidWifiRxTimeMs = u.getWifiControllerActivity(CONTROLLER_RX_TIME, which);
3795 final long uidWifiTxTimeMs = u.getWifiControllerActivity(CONTROLLER_TX_TIME, which);
3796 final long uidWifiTotalTimeMs = uidWifiIdleTimeMs + uidWifiRxTimeMs + uidWifiTxTimeMs;
3797 if (uidWifiTotalTimeMs > 0) {
3798 sb.setLength(0);
3799 sb.append(prefix).append(" WiFi Idle time: ");
3800 formatTimeMs(sb, uidWifiIdleTimeMs);
3801 sb.append("(").append(formatRatioLocked(uidWifiIdleTimeMs, uidWifiTotalTimeMs))
3802 .append(")\n");
3803
3804 sb.append(prefix).append(" WiFi Rx time: "); formatTimeMs(sb, uidWifiRxTimeMs);
3805 sb.append("(").append(formatRatioLocked(uidWifiRxTimeMs, uidWifiTotalTimeMs))
3806 .append(")\n");
3807
3808 sb.append(prefix).append(" WiFi Tx time: "); formatTimeMs(sb, uidWifiTxTimeMs);
3809 sb.append("(").append(formatRatioLocked(uidWifiTxTimeMs, uidWifiTotalTimeMs))
3810 .append(")");
3811 pw.println(sb.toString());
3812 }
3813
Dianne Hackborn617f8772009-03-31 15:04:46 -07003814 if (u.hasUserActivity()) {
3815 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07003816 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003817 final int val = u.getUserActivityCount(i, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07003818 if (val != 0) {
3819 if (!hasData) {
3820 sb.setLength(0);
3821 sb.append(" User activity: ");
3822 hasData = true;
3823 } else {
3824 sb.append(", ");
3825 }
3826 sb.append(val);
3827 sb.append(" ");
3828 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
3829 }
3830 }
3831 if (hasData) {
3832 pw.println(sb.toString());
3833 }
3834 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003835
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003836 final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
3837 = u.getWakelockStats();
3838 long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
3839 int countWakelock = 0;
3840 for (int iw=wakelocks.size()-1; iw>=0; iw--) {
3841 final Uid.Wakelock wl = wakelocks.valueAt(iw);
3842 String linePrefix = ": ";
3843 sb.setLength(0);
3844 sb.append(prefix);
3845 sb.append(" Wake lock ");
3846 sb.append(wakelocks.keyAt(iw));
3847 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
3848 "full", which, linePrefix);
3849 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
3850 "partial", which, linePrefix);
3851 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
3852 "window", which, linePrefix);
3853 if (true || !linePrefix.equals(": ")) {
3854 sb.append(" realtime");
3855 // Only print out wake locks that were held
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003856 pw.println(sb.toString());
3857 uidActivity = true;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003858 countWakelock++;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003859 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003860 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
3861 rawRealtime, which);
3862 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
3863 rawRealtime, which);
3864 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
3865 rawRealtime, which);
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003866 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003867 if (countWakelock > 1) {
3868 if (totalFullWakelock != 0 || totalPartialWakelock != 0
3869 || totalWindowWakelock != 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003870 sb.setLength(0);
3871 sb.append(prefix);
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003872 sb.append(" TOTAL wake: ");
3873 boolean needComma = false;
3874 if (totalFullWakelock != 0) {
3875 needComma = true;
3876 formatTimeMs(sb, totalFullWakelock);
3877 sb.append("full");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003878 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003879 if (totalPartialWakelock != 0) {
3880 if (needComma) {
3881 sb.append(", ");
3882 }
3883 needComma = true;
3884 formatTimeMs(sb, totalPartialWakelock);
3885 sb.append("partial");
3886 }
3887 if (totalWindowWakelock != 0) {
3888 if (needComma) {
3889 sb.append(", ");
3890 }
3891 needComma = true;
3892 formatTimeMs(sb, totalWindowWakelock);
3893 sb.append("window");
3894 }
3895 sb.append(" realtime");
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003896 pw.println(sb.toString());
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003897 }
3898 }
3899
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003900 final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
3901 for (int isy=syncs.size()-1; isy>=0; isy--) {
3902 final Timer timer = syncs.valueAt(isy);
3903 // Convert from microseconds to milliseconds with rounding
3904 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3905 final int count = timer.getCountLocked(which);
3906 sb.setLength(0);
3907 sb.append(prefix);
3908 sb.append(" Sync ");
3909 sb.append(syncs.keyAt(isy));
3910 sb.append(": ");
3911 if (totalTime != 0) {
3912 formatTimeMs(sb, totalTime);
3913 sb.append("realtime (");
3914 sb.append(count);
3915 sb.append(" times)");
3916 } else {
3917 sb.append("(not used)");
3918 }
3919 pw.println(sb.toString());
3920 uidActivity = true;
3921 }
3922
3923 final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
3924 for (int ij=jobs.size()-1; ij>=0; ij--) {
3925 final Timer timer = jobs.valueAt(ij);
3926 // Convert from microseconds to milliseconds with rounding
3927 final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3928 final int count = timer.getCountLocked(which);
3929 sb.setLength(0);
3930 sb.append(prefix);
3931 sb.append(" Job ");
3932 sb.append(jobs.keyAt(ij));
3933 sb.append(": ");
3934 if (totalTime != 0) {
3935 formatTimeMs(sb, totalTime);
3936 sb.append("realtime (");
3937 sb.append(count);
3938 sb.append(" times)");
3939 } else {
3940 sb.append("(not used)");
3941 }
3942 pw.println(sb.toString());
3943 uidActivity = true;
3944 }
3945
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003946 uidActivity |= printTimer(pw, sb, u.getFlashlightTurnedOnTimer(), rawRealtime, which,
3947 prefix, "Flashlight");
3948 uidActivity |= printTimer(pw, sb, u.getCameraTurnedOnTimer(), rawRealtime, which,
3949 prefix, "Camera");
3950 uidActivity |= printTimer(pw, sb, u.getVideoTurnedOnTimer(), rawRealtime, which,
3951 prefix, "Video");
3952 uidActivity |= printTimer(pw, sb, u.getAudioTurnedOnTimer(), rawRealtime, which,
3953 prefix, "Audio");
3954
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003955 final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3956 final int NSE = sensors.size();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003957 for (int ise=0; ise<NSE; ise++) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003958 final Uid.Sensor se = sensors.valueAt(ise);
3959 final int sensorNumber = sensors.keyAt(ise);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003960 sb.setLength(0);
3961 sb.append(prefix);
3962 sb.append(" Sensor ");
3963 int handle = se.getHandle();
3964 if (handle == Uid.Sensor.GPS) {
3965 sb.append("GPS");
3966 } else {
3967 sb.append(handle);
3968 }
3969 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003970
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003971 final Timer timer = se.getSensorTime();
Dianne Hackborn61659e52014-07-09 16:13:01 -07003972 if (timer != null) {
3973 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003974 final long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn61659e52014-07-09 16:13:01 -07003975 rawRealtime, which) + 500) / 1000;
Dianne Hackborn1e725a72015-03-24 18:23:19 -07003976 final int count = timer.getCountLocked(which);
Dianne Hackborn61659e52014-07-09 16:13:01 -07003977 //timer.logState();
3978 if (totalTime != 0) {
3979 formatTimeMs(sb, totalTime);
3980 sb.append("realtime (");
3981 sb.append(count);
3982 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003983 } else {
3984 sb.append("(not used)");
3985 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003986 } else {
3987 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003989
3990 pw.println(sb.toString());
3991 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 }
3993
Ruben Brunk6d2c3632015-05-26 17:32:16 -07003994 uidActivity |= printTimer(pw, sb, u.getVibratorOnTimer(), rawRealtime, which, prefix,
3995 "Vibrator");
3996 uidActivity |= printTimer(pw, sb, u.getForegroundActivityTimer(), rawRealtime, which,
3997 prefix, "Foreground activities");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003998
Dianne Hackborn61659e52014-07-09 16:13:01 -07003999 long totalStateTime = 0;
4000 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
4001 long time = u.getProcessStateTime(ips, rawRealtime, which);
4002 if (time > 0) {
4003 totalStateTime += time;
4004 sb.setLength(0);
4005 sb.append(prefix);
4006 sb.append(" ");
4007 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
4008 sb.append(" for: ");
4009 formatTimeMs(sb, (totalStateTime + 500) / 1000);
4010 pw.println(sb.toString());
4011 uidActivity = true;
4012 }
4013 }
4014
Adam Lesinski06af1fa2015-05-05 17:35:35 -07004015 final long userCpuTimeUs = u.getUserCpuTimeUs(which);
4016 final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
4017 if (userCpuTimeUs > 0 || systemCpuTimeUs > 0) {
4018 sb.setLength(0);
4019 sb.append(prefix);
4020 sb.append(" Total cpu time: ");
4021 formatTimeMs(sb, (userCpuTimeUs + systemCpuTimeUs) / 1000);
4022 pw.println(sb.toString());
4023 }
4024
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004025 final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats
4026 = u.getProcessStats();
4027 for (int ipr=processStats.size()-1; ipr>=0; ipr--) {
4028 final Uid.Proc ps = processStats.valueAt(ipr);
4029 long userTime;
4030 long systemTime;
4031 long foregroundTime;
4032 int starts;
4033 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004035 userTime = ps.getUserTime(which);
4036 systemTime = ps.getSystemTime(which);
4037 foregroundTime = ps.getForegroundTime(which);
4038 starts = ps.getStarts(which);
4039 final int numCrashes = ps.getNumCrashes(which);
4040 final int numAnrs = ps.getNumAnrs(which);
4041 numExcessive = which == STATS_SINCE_CHARGED
4042 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004043
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004044 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
4045 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
4046 sb.setLength(0);
4047 sb.append(prefix); sb.append(" Proc ");
4048 sb.append(processStats.keyAt(ipr)); sb.append(":\n");
4049 sb.append(prefix); sb.append(" CPU: ");
4050 formatTimeMs(sb, userTime); sb.append("usr + ");
4051 formatTimeMs(sb, systemTime); sb.append("krn ; ");
4052 formatTimeMs(sb, foregroundTime); sb.append("fg");
4053 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
4054 sb.append("\n"); sb.append(prefix); sb.append(" ");
4055 boolean hasOne = false;
4056 if (starts != 0) {
4057 hasOne = true;
4058 sb.append(starts); sb.append(" starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07004059 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004060 if (numCrashes != 0) {
4061 if (hasOne) {
4062 sb.append(", ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004063 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004064 hasOne = true;
4065 sb.append(numCrashes); sb.append(" crashes");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07004066 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004067 if (numAnrs != 0) {
4068 if (hasOne) {
4069 sb.append(", ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004070 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004071 sb.append(numAnrs); sb.append(" anrs");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004072 }
4073 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004074 pw.println(sb.toString());
4075 for (int e=0; e<numExcessive; e++) {
4076 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
4077 if (ew != null) {
4078 pw.print(prefix); pw.print(" * Killed for ");
4079 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
4080 pw.print("wake lock");
4081 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
4082 pw.print("cpu");
4083 } else {
4084 pw.print("unknown");
4085 }
4086 pw.print(" use: ");
4087 TimeUtils.formatDuration(ew.usedTime, pw);
4088 pw.print(" over ");
4089 TimeUtils.formatDuration(ew.overTime, pw);
4090 if (ew.overTime != 0) {
4091 pw.print(" (");
4092 pw.print((ew.usedTime*100)/ew.overTime);
4093 pw.println("%)");
4094 }
4095 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004096 }
4097 uidActivity = true;
4098 }
4099 }
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004100
4101 final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats
4102 = u.getPackageStats();
4103 for (int ipkg=packageStats.size()-1; ipkg>=0; ipkg--) {
4104 pw.print(prefix); pw.print(" Apk "); pw.print(packageStats.keyAt(ipkg));
4105 pw.println(":");
4106 boolean apkActivity = false;
4107 final Uid.Pkg ps = packageStats.valueAt(ipkg);
4108 final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
4109 for (int iwa=alarms.size()-1; iwa>=0; iwa--) {
4110 pw.print(prefix); pw.print(" Wakeup alarm ");
4111 pw.print(alarms.keyAt(iwa)); pw.print(": ");
4112 pw.print(alarms.valueAt(iwa).getCountLocked(which));
4113 pw.println(" times");
4114 apkActivity = true;
4115 }
4116 final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
4117 for (int isvc=serviceStats.size()-1; isvc>=0; isvc--) {
4118 final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
4119 final long startTime = ss.getStartTime(batteryUptime, which);
4120 final int starts = ss.getStarts(which);
4121 final int launches = ss.getLaunches(which);
4122 if (startTime != 0 || starts != 0 || launches != 0) {
4123 sb.setLength(0);
4124 sb.append(prefix); sb.append(" Service ");
4125 sb.append(serviceStats.keyAt(isvc)); sb.append(":\n");
4126 sb.append(prefix); sb.append(" Created for: ");
4127 formatTimeMs(sb, startTime / 1000);
4128 sb.append("uptime\n");
4129 sb.append(prefix); sb.append(" Starts: ");
4130 sb.append(starts);
4131 sb.append(", launches: "); sb.append(launches);
4132 pw.println(sb.toString());
4133 apkActivity = true;
4134 }
4135 }
4136 if (!apkActivity) {
4137 pw.print(prefix); pw.println(" (nothing executed)");
4138 }
4139 uidActivity = true;
4140 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004141 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07004142 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004143 }
4144 }
4145 }
4146
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004147 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004148 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004149 int diff = oldval ^ newval;
4150 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004151 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004152 for (int i=0; i<descriptions.length; i++) {
4153 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004154 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004155 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004156 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004157 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004158 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004159 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
4160 didWake = true;
4161 pw.print("=");
4162 if (longNames) {
4163 UserHandle.formatUid(pw, wakelockTag.uid);
4164 pw.print(":\"");
4165 pw.print(wakelockTag.string);
4166 pw.print("\"");
4167 } else {
4168 pw.print(wakelockTag.poolIdx);
4169 }
4170 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004171 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004172 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004173 pw.print("=");
4174 int val = (newval&bd.mask)>>bd.shift;
4175 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004176 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004177 } else {
4178 pw.print(val);
4179 }
4180 }
4181 }
4182 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004183 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07004184 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004185 if (longNames) {
4186 UserHandle.formatUid(pw, wakelockTag.uid);
4187 pw.print(":\"");
4188 pw.print(wakelockTag.string);
4189 pw.print("\"");
4190 } else {
4191 pw.print(wakelockTag.poolIdx);
4192 }
4193 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004194 }
4195
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004196 public void prepareForDumpLocked() {
4197 }
4198
4199 public static class HistoryPrinter {
4200 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004201 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004202 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004203 int oldStatus = -1;
4204 int oldHealth = -1;
4205 int oldPlug = -1;
4206 int oldTemp = -1;
4207 int oldVolt = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004208 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004209
Dianne Hackborn3251b902014-06-20 14:40:53 -07004210 void reset() {
4211 oldState = oldState2 = 0;
4212 oldLevel = -1;
4213 oldStatus = -1;
4214 oldHealth = -1;
4215 oldPlug = -1;
4216 oldTemp = -1;
4217 oldVolt = -1;
4218 }
4219
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004220 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004221 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004222 if (!checkin) {
4223 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004224 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004225 pw.print(" (");
4226 pw.print(rec.numReadInts);
4227 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004228 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004229 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4230 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004231 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004232 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004233 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004234 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004235 }
4236 lastTime = rec.time;
4237 }
4238 if (rec.cmd == HistoryItem.CMD_START) {
4239 if (checkin) {
4240 pw.print(":");
4241 }
4242 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004243 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004244 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4245 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004246 if (checkin) {
4247 pw.print(":");
4248 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004249 if (rec.cmd == HistoryItem.CMD_RESET) {
4250 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004251 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004252 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004253 pw.print("TIME:");
4254 if (checkin) {
4255 pw.println(rec.currentTime);
4256 } else {
4257 pw.print(" ");
4258 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4259 rec.currentTime).toString());
4260 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004261 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4262 if (checkin) {
4263 pw.print(":");
4264 }
4265 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004266 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4267 if (checkin) {
4268 pw.print(":");
4269 }
4270 pw.println("*OVERFLOW*");
4271 } else {
4272 if (!checkin) {
4273 if (rec.batteryLevel < 10) pw.print("00");
4274 else if (rec.batteryLevel < 100) pw.print("0");
4275 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004276 if (verbose) {
4277 pw.print(" ");
4278 if (rec.states < 0) ;
4279 else if (rec.states < 0x10) pw.print("0000000");
4280 else if (rec.states < 0x100) pw.print("000000");
4281 else if (rec.states < 0x1000) pw.print("00000");
4282 else if (rec.states < 0x10000) pw.print("0000");
4283 else if (rec.states < 0x100000) pw.print("000");
4284 else if (rec.states < 0x1000000) pw.print("00");
4285 else if (rec.states < 0x10000000) pw.print("0");
4286 pw.print(Integer.toHexString(rec.states));
4287 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004288 } else {
4289 if (oldLevel != rec.batteryLevel) {
4290 oldLevel = rec.batteryLevel;
4291 pw.print(",Bl="); pw.print(rec.batteryLevel);
4292 }
4293 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004294 if (oldStatus != rec.batteryStatus) {
4295 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004296 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004297 switch (oldStatus) {
4298 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004299 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004300 break;
4301 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004302 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004303 break;
4304 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004305 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004306 break;
4307 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004308 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004309 break;
4310 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004311 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004312 break;
4313 default:
4314 pw.print(oldStatus);
4315 break;
4316 }
4317 }
4318 if (oldHealth != rec.batteryHealth) {
4319 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004320 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004321 switch (oldHealth) {
4322 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004323 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004324 break;
4325 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004326 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004327 break;
4328 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004329 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004330 break;
4331 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004332 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004333 break;
4334 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004335 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004336 break;
4337 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004338 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004339 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004340 case BatteryManager.BATTERY_HEALTH_COLD:
4341 pw.print(checkin ? "c" : "cold");
4342 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004343 default:
4344 pw.print(oldHealth);
4345 break;
4346 }
4347 }
4348 if (oldPlug != rec.batteryPlugType) {
4349 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004350 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004351 switch (oldPlug) {
4352 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004353 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004354 break;
4355 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004356 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004357 break;
4358 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004359 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004360 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004361 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004362 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004363 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004364 default:
4365 pw.print(oldPlug);
4366 break;
4367 }
4368 }
4369 if (oldTemp != rec.batteryTemperature) {
4370 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004371 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004372 pw.print(oldTemp);
4373 }
4374 if (oldVolt != rec.batteryVoltage) {
4375 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004376 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004377 pw.print(oldVolt);
4378 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004379 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004380 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004381 printBitDescriptions(pw, oldState2, rec.states2, null,
4382 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004383 if (rec.wakeReasonTag != null) {
4384 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004385 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004386 pw.print(rec.wakeReasonTag.poolIdx);
4387 } else {
4388 pw.print(" wake_reason=");
4389 pw.print(rec.wakeReasonTag.uid);
4390 pw.print(":\"");
4391 pw.print(rec.wakeReasonTag.string);
4392 pw.print("\"");
4393 }
4394 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004395 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004396 pw.print(checkin ? "," : " ");
4397 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4398 pw.print("+");
4399 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4400 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004401 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004402 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4403 : HISTORY_EVENT_NAMES;
4404 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4405 | HistoryItem.EVENT_FLAG_FINISH);
4406 if (idx >= 0 && idx < eventNames.length) {
4407 pw.print(eventNames[idx]);
4408 } else {
4409 pw.print(checkin ? "Ev" : "event");
4410 pw.print(idx);
4411 }
4412 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004413 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004414 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004415 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004416 UserHandle.formatUid(pw, rec.eventTag.uid);
4417 pw.print(":\"");
4418 pw.print(rec.eventTag.string);
4419 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004420 }
4421 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004422 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004423 if (rec.stepDetails != null) {
4424 if (!checkin) {
4425 pw.print(" Details: cpu=");
4426 pw.print(rec.stepDetails.userTime);
4427 pw.print("u+");
4428 pw.print(rec.stepDetails.systemTime);
4429 pw.print("s");
4430 if (rec.stepDetails.appCpuUid1 >= 0) {
4431 pw.print(" (");
4432 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4433 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4434 if (rec.stepDetails.appCpuUid2 >= 0) {
4435 pw.print(", ");
4436 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4437 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4438 }
4439 if (rec.stepDetails.appCpuUid3 >= 0) {
4440 pw.print(", ");
4441 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4442 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4443 }
4444 pw.print(')');
4445 }
4446 pw.println();
4447 pw.print(" /proc/stat=");
4448 pw.print(rec.stepDetails.statUserTime);
4449 pw.print(" usr, ");
4450 pw.print(rec.stepDetails.statSystemTime);
4451 pw.print(" sys, ");
4452 pw.print(rec.stepDetails.statIOWaitTime);
4453 pw.print(" io, ");
4454 pw.print(rec.stepDetails.statIrqTime);
4455 pw.print(" irq, ");
4456 pw.print(rec.stepDetails.statSoftIrqTime);
4457 pw.print(" sirq, ");
4458 pw.print(rec.stepDetails.statIdlTime);
4459 pw.print(" idle");
4460 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4461 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4462 + rec.stepDetails.statSoftIrqTime;
4463 int total = totalRun + rec.stepDetails.statIdlTime;
4464 if (total > 0) {
4465 pw.print(" (");
4466 float perc = ((float)totalRun) / ((float)total) * 100;
4467 pw.print(String.format("%.1f%%", perc));
4468 pw.print(" of ");
4469 StringBuilder sb = new StringBuilder(64);
4470 formatTimeMsNoSpace(sb, total*10);
4471 pw.print(sb);
4472 pw.print(")");
4473 }
4474 pw.println();
4475 } else {
4476 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4477 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4478 pw.print(rec.stepDetails.userTime);
4479 pw.print(":");
4480 pw.print(rec.stepDetails.systemTime);
4481 if (rec.stepDetails.appCpuUid1 >= 0) {
4482 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4483 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4484 if (rec.stepDetails.appCpuUid2 >= 0) {
4485 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4486 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4487 }
4488 if (rec.stepDetails.appCpuUid3 >= 0) {
4489 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4490 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4491 }
4492 }
4493 pw.println();
4494 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4495 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4496 pw.print(rec.stepDetails.statUserTime);
4497 pw.print(',');
4498 pw.print(rec.stepDetails.statSystemTime);
4499 pw.print(',');
4500 pw.print(rec.stepDetails.statIOWaitTime);
4501 pw.print(',');
4502 pw.print(rec.stepDetails.statIrqTime);
4503 pw.print(',');
4504 pw.print(rec.stepDetails.statSoftIrqTime);
4505 pw.print(',');
4506 pw.print(rec.stepDetails.statIdlTime);
4507 pw.println();
4508 }
4509 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004510 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004511 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004512 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004513 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004514
4515 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4516 UserHandle.formatUid(pw, uid);
4517 pw.print("=");
4518 pw.print(utime);
4519 pw.print("u+");
4520 pw.print(stime);
4521 pw.print("s");
4522 }
4523
4524 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
4525 pw.print('/');
4526 pw.print(uid);
4527 pw.print(":");
4528 pw.print(utime);
4529 pw.print(":");
4530 pw.print(stime);
4531 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004532 }
4533
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004534 private void printSizeValue(PrintWriter pw, long size) {
4535 float result = size;
4536 String suffix = "";
4537 if (result >= 10*1024) {
4538 suffix = "KB";
4539 result = result / 1024;
4540 }
4541 if (result >= 10*1024) {
4542 suffix = "MB";
4543 result = result / 1024;
4544 }
4545 if (result >= 10*1024) {
4546 suffix = "GB";
4547 result = result / 1024;
4548 }
4549 if (result >= 10*1024) {
4550 suffix = "TB";
4551 result = result / 1024;
4552 }
4553 if (result >= 10*1024) {
4554 suffix = "PB";
4555 result = result / 1024;
4556 }
4557 pw.print((int)result);
4558 pw.print(suffix);
4559 }
4560
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004561 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
4562 String label3, long estimatedTime) {
4563 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004564 return false;
4565 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004566 pw.print(label1);
4567 pw.print(label2);
4568 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004569 StringBuilder sb = new StringBuilder(64);
4570 formatTimeMs(sb, estimatedTime);
4571 pw.print(sb);
4572 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004573 return true;
4574 }
4575
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004576 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
4577 LevelStepTracker steps, boolean checkin) {
4578 if (steps == null) {
4579 return false;
4580 }
4581 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004582 if (count <= 0) {
4583 return false;
4584 }
4585 if (!checkin) {
4586 pw.println(header);
4587 }
Kweku Adams030980a2015-04-01 16:07:48 -07004588 String[] lineArgs = new String[5];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004589 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004590 long duration = steps.getDurationAt(i);
4591 int level = steps.getLevelAt(i);
4592 long initMode = steps.getInitModeAt(i);
4593 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004594 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004595 lineArgs[0] = Long.toString(duration);
4596 lineArgs[1] = Integer.toString(level);
4597 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4598 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4599 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
4600 case Display.STATE_ON: lineArgs[2] = "s+"; break;
4601 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
4602 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
Kweku Adams030980a2015-04-01 16:07:48 -07004603 default: lineArgs[2] = "?"; break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004604 }
4605 } else {
4606 lineArgs[2] = "";
4607 }
4608 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4609 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
4610 } else {
4611 lineArgs[3] = "";
4612 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004613 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
Kweku Adams030980a2015-04-01 16:07:48 -07004614 lineArgs[4] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004615 } else {
Kweku Adams030980a2015-04-01 16:07:48 -07004616 lineArgs[4] = "";
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004617 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004618 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
4619 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004620 pw.print(prefix);
4621 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004622 TimeUtils.formatDuration(duration, pw);
4623 pw.print(" to "); pw.print(level);
4624 boolean haveModes = false;
4625 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4626 pw.print(" (");
4627 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4628 case Display.STATE_OFF: pw.print("screen-off"); break;
4629 case Display.STATE_ON: pw.print("screen-on"); break;
4630 case Display.STATE_DOZE: pw.print("screen-doze"); break;
4631 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
Kweku Adams030980a2015-04-01 16:07:48 -07004632 default: pw.print("screen-?"); break;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004633 }
4634 haveModes = true;
4635 }
4636 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4637 pw.print(haveModes ? ", " : " (");
4638 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
4639 ? "power-save-on" : "power-save-off");
4640 haveModes = true;
4641 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004642 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
4643 pw.print(haveModes ? ", " : " (");
4644 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
4645 ? "device-idle-on" : "device-idle-off");
4646 haveModes = true;
4647 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004648 if (haveModes) {
4649 pw.print(")");
4650 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004651 pw.println();
4652 }
4653 }
4654 return true;
4655 }
4656
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004657 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004658 public static final int DUMP_DAILY_ONLY = 1<<2;
4659 public static final int DUMP_HISTORY_ONLY = 1<<3;
4660 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
4661 public static final int DUMP_VERBOSE = 1<<5;
4662 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004663
Dianne Hackborn37de0982014-05-09 09:32:18 -07004664 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
4665 final HistoryPrinter hprinter = new HistoryPrinter();
4666 final HistoryItem rec = new HistoryItem();
4667 long lastTime = -1;
4668 long baseTime = -1;
4669 boolean printed = false;
4670 HistoryEventTracker tracker = null;
4671 while (getNextHistoryLocked(rec)) {
4672 lastTime = rec.time;
4673 if (baseTime < 0) {
4674 baseTime = lastTime;
4675 }
4676 if (rec.time >= histStart) {
4677 if (histStart >= 0 && !printed) {
4678 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07004679 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004680 || rec.cmd == HistoryItem.CMD_START
4681 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004682 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004683 hprinter.printNextItem(pw, rec, baseTime, checkin,
4684 (flags&DUMP_VERBOSE) != 0);
4685 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004686 } else if (rec.currentTime != 0) {
4687 printed = true;
4688 byte cmd = rec.cmd;
4689 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004690 hprinter.printNextItem(pw, rec, baseTime, checkin,
4691 (flags&DUMP_VERBOSE) != 0);
4692 rec.cmd = cmd;
4693 }
4694 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004695 if (rec.cmd != HistoryItem.CMD_UPDATE) {
4696 hprinter.printNextItem(pw, rec, baseTime, checkin,
4697 (flags&DUMP_VERBOSE) != 0);
4698 rec.cmd = HistoryItem.CMD_UPDATE;
4699 }
4700 int oldEventCode = rec.eventCode;
4701 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004702 rec.eventTag = new HistoryTag();
4703 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
4704 HashMap<String, SparseIntArray> active
4705 = tracker.getStateForEvent(i);
4706 if (active == null) {
4707 continue;
4708 }
4709 for (HashMap.Entry<String, SparseIntArray> ent
4710 : active.entrySet()) {
4711 SparseIntArray uids = ent.getValue();
4712 for (int j=0; j<uids.size(); j++) {
4713 rec.eventCode = i;
4714 rec.eventTag.string = ent.getKey();
4715 rec.eventTag.uid = uids.keyAt(j);
4716 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07004717 hprinter.printNextItem(pw, rec, baseTime, checkin,
4718 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004719 rec.wakeReasonTag = null;
4720 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004721 }
4722 }
4723 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004724 rec.eventCode = oldEventCode;
4725 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004726 tracker = null;
4727 }
4728 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004729 hprinter.printNextItem(pw, rec, baseTime, checkin,
4730 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07004731 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
4732 // This is an attempt to aggregate the previous state and generate
4733 // fake events to reflect that state at the point where we start
4734 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07004735 if (tracker == null) {
4736 tracker = new HistoryEventTracker();
4737 }
4738 tracker.updateState(rec.eventCode, rec.eventTag.string,
4739 rec.eventTag.uid, rec.eventTag.poolIdx);
4740 }
4741 }
4742 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07004743 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004744 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
4745 }
4746 }
4747
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004748 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
4749 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
4750 if (steps == null) {
4751 return;
4752 }
4753 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
4754 if (timeRemaining >= 0) {
4755 pw.print(prefix); pw.print(label); pw.print(" total time: ");
4756 tmpSb.setLength(0);
4757 formatTimeMs(tmpSb, timeRemaining);
4758 pw.print(tmpSb);
4759 pw.print(" (from "); pw.print(tmpOutInt[0]);
4760 pw.println(" steps)");
4761 }
4762 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
4763 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
4764 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
4765 if (estimatedTime > 0) {
4766 pw.print(prefix); pw.print(label); pw.print(" ");
4767 pw.print(STEP_LEVEL_MODE_LABELS[i]);
4768 pw.print(" time: ");
4769 tmpSb.setLength(0);
4770 formatTimeMs(tmpSb, estimatedTime);
4771 pw.print(tmpSb);
4772 pw.print(" (from "); pw.print(tmpOutInt[0]);
4773 pw.println(" steps)");
4774 }
4775 }
4776 }
4777
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004778 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
4779 ArrayList<PackageChange> changes) {
4780 if (changes == null) {
4781 return;
4782 }
4783 pw.print(prefix); pw.println("Package changes:");
4784 for (int i=0; i<changes.size(); i++) {
4785 PackageChange pc = changes.get(i);
4786 if (pc.mUpdate) {
4787 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
4788 pw.print(" vers="); pw.println(pc.mVersionCode);
4789 } else {
4790 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
4791 }
4792 }
4793 }
4794
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004795 /**
4796 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
4797 *
4798 * @param pw a Printer to receive the dump output.
4799 */
4800 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004801 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004802 prepareForDumpLocked();
4803
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004804 final boolean filtering = (flags
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004805 & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004806
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004807 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004808 final long historyTotalSize = getHistoryTotalSize();
4809 final long historyUsedSize = getHistoryUsedSize();
4810 if (startIteratingHistoryLocked()) {
4811 try {
4812 pw.print("Battery History (");
4813 pw.print((100*historyUsedSize)/historyTotalSize);
4814 pw.print("% used, ");
4815 printSizeValue(pw, historyUsedSize);
4816 pw.print(" used of ");
4817 printSizeValue(pw, historyTotalSize);
4818 pw.print(", ");
4819 pw.print(getHistoryStringPoolSize());
4820 pw.print(" strings using ");
4821 printSizeValue(pw, getHistoryStringPoolBytes());
4822 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07004823 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004824 pw.println();
4825 } finally {
4826 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004827 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004828 }
4829
4830 if (startIteratingOldHistoryLocked()) {
4831 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004832 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004833 pw.println("Old battery History:");
4834 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004835 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004836 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004837 if (baseTime < 0) {
4838 baseTime = rec.time;
4839 }
4840 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004841 }
4842 pw.println();
4843 } finally {
4844 finishIteratingOldHistoryLocked();
4845 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07004846 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004847 }
4848
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004849 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08004850 return;
4851 }
4852
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004853 if (!filtering) {
4854 SparseArray<? extends Uid> uidStats = getUidStats();
4855 final int NU = uidStats.size();
4856 boolean didPid = false;
4857 long nowRealtime = SystemClock.elapsedRealtime();
4858 for (int i=0; i<NU; i++) {
4859 Uid uid = uidStats.valueAt(i);
4860 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
4861 if (pids != null) {
4862 for (int j=0; j<pids.size(); j++) {
4863 Uid.Pid pid = pids.valueAt(j);
4864 if (!didPid) {
4865 pw.println("Per-PID Stats:");
4866 didPid = true;
4867 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004868 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
4869 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004870 pw.print(" PID "); pw.print(pids.keyAt(j));
4871 pw.print(" wake time: ");
4872 TimeUtils.formatDuration(time, pw);
4873 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004874 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004875 }
4876 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004877 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004878 pw.println();
4879 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004880 }
4881
4882 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004883 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
4884 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004885 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
4886 if (timeRemaining >= 0) {
4887 pw.print(" Estimated discharge time remaining: ");
4888 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4889 pw.println();
4890 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004891 final LevelStepTracker steps = getDischargeLevelStepTracker();
4892 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
4893 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
4894 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
4895 STEP_LEVEL_MODE_VALUES[i], null));
4896 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004897 pw.println();
4898 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004899 if (dumpDurationSteps(pw, " ", "Charge step durations:",
4900 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004901 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
4902 if (timeRemaining >= 0) {
4903 pw.print(" Estimated charge time remaining: ");
4904 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4905 pw.println();
4906 }
4907 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004908 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004909 }
4910 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
4911 pw.println("Daily stats:");
4912 pw.print(" Current start time: ");
4913 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4914 getCurrentDailyStartTime()).toString());
4915 pw.print(" Next min deadline: ");
4916 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4917 getNextMinDailyDeadline()).toString());
4918 pw.print(" Next max deadline: ");
4919 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4920 getNextMaxDailyDeadline()).toString());
4921 StringBuilder sb = new StringBuilder(64);
4922 int[] outInt = new int[1];
4923 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
4924 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004925 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
4926 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004927 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004928 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
4929 dsteps, false)) {
4930 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
4931 sb, outInt);
4932 }
4933 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
4934 csteps, false)) {
4935 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
4936 sb, outInt);
4937 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004938 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004939 } else {
4940 pw.println(" Current daily steps:");
4941 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
4942 sb, outInt);
4943 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
4944 sb, outInt);
4945 }
4946 }
4947 DailyItem dit;
4948 int curIndex = 0;
4949 while ((dit=getDailyItemLocked(curIndex)) != null) {
4950 curIndex++;
4951 if ((flags&DUMP_DAILY_ONLY) != 0) {
4952 pw.println();
4953 }
4954 pw.print(" Daily from ");
4955 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
4956 pw.print(" to ");
4957 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
4958 pw.println(":");
Dianne Hackborn1e725a72015-03-24 18:23:19 -07004959 if ((flags&DUMP_DAILY_ONLY) != 0 || !filtering) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004960 if (dumpDurationSteps(pw, " ",
4961 " Discharge step durations:", dit.mDischargeSteps, false)) {
4962 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
4963 sb, outInt);
4964 }
4965 if (dumpDurationSteps(pw, " ",
4966 " Charge step durations:", dit.mChargeSteps, false)) {
4967 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
4968 sb, outInt);
4969 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004970 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004971 } else {
4972 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
4973 sb, outInt);
4974 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
4975 sb, outInt);
4976 }
4977 }
4978 pw.println();
4979 }
4980 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004981 pw.println("Statistics since last charge:");
4982 pw.println(" System starts: " + getStartCount()
4983 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07004984 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
4985 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004986 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004987 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004988 }
4989
4990 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004991 public void dumpCheckinLocked(Context context, PrintWriter pw,
4992 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004993 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004994
4995 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0c820db2015-04-14 17:47:34 -07004996 CHECKIN_VERSION, getParcelVersion(), getStartPlatformVersion(),
4997 getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004998
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004999 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
5000
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005001 final boolean filtering = (flags &
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005002 (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005003
5004 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07005005 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005006 try {
5007 for (int i=0; i<getHistoryStringPoolSize(); i++) {
5008 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
5009 pw.print(HISTORY_STRING_POOL); pw.print(',');
5010 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005011 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005012 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07005013 pw.print(",\"");
5014 String str = getHistoryTagPoolString(i);
5015 str = str.replace("\\", "\\\\");
5016 str = str.replace("\"", "\\\"");
5017 pw.print(str);
5018 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005019 pw.println();
5020 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07005021 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08005022 } finally {
5023 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08005024 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005025 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07005026 }
5027
Dianne Hackborn1e725a72015-03-24 18:23:19 -07005028 if (filtering && (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08005029 return;
5030 }
5031
Dianne Hackborne4a59512010-12-07 11:08:07 -08005032 if (apps != null) {
5033 SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
5034 for (int i=0; i<apps.size(); i++) {
5035 ApplicationInfo ai = apps.get(i);
5036 ArrayList<String> pkgs = uids.get(ai.uid);
5037 if (pkgs == null) {
5038 pkgs = new ArrayList<String>();
5039 uids.put(ai.uid, pkgs);
5040 }
5041 pkgs.add(ai.packageName);
5042 }
5043 SparseArray<? extends Uid> uidStats = getUidStats();
5044 final int NU = uidStats.size();
5045 String[] lineArgs = new String[2];
5046 for (int i=0; i<NU; i++) {
5047 int uid = uidStats.keyAt(i);
5048 ArrayList<String> pkgs = uids.get(uid);
5049 if (pkgs != null) {
5050 for (int j=0; j<pkgs.size(); j++) {
5051 lineArgs[0] = Integer.toString(uid);
5052 lineArgs[1] = pkgs.get(j);
5053 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
5054 (Object[])lineArgs);
5055 }
5056 }
5057 }
5058 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07005059 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005060 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005061 String[] lineArgs = new String[1];
5062 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
5063 if (timeRemaining >= 0) {
5064 lineArgs[0] = Long.toString(timeRemaining);
5065 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
5066 (Object[])lineArgs);
5067 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08005068 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07005069 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
5070 if (timeRemaining >= 0) {
5071 lineArgs[0] = Long.toString(timeRemaining);
5072 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
5073 (Object[])lineArgs);
5074 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07005075 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
5076 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08005077 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005078 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005079}