blob: cab03da7e4c0ab8c0bed0927da3cf754d57e809a [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.util.Printer;
33import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070034import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070035import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070036import android.view.Display;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080037import com.android.internal.os.BatterySipper;
38import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40/**
41 * A class providing access to battery usage statistics, including information on
42 * wakelocks, processes, packages, and services. All times are represented in microseconds
43 * except where indicated otherwise.
44 * @hide
45 */
46public abstract class BatteryStats implements Parcelable {
47
48 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070049
50 /** @hide */
51 public static final String SERVICE_NAME = "batterystats";
52
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 /**
54 * A constant indicating a partial wake lock timer.
55 */
56 public static final int WAKE_TYPE_PARTIAL = 0;
57
58 /**
59 * A constant indicating a full wake lock timer.
60 */
61 public static final int WAKE_TYPE_FULL = 1;
62
63 /**
64 * A constant indicating a window wake lock timer.
65 */
66 public static final int WAKE_TYPE_WINDOW = 2;
67
68 /**
69 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 */
71 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070072
73 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070074 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070075 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070076 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070077
78 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070079 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070080 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070081 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070082
83 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070084 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070085 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070086 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087
Dianne Hackborn62793e42015-03-09 11:15:41 -070088 /**
89 * A constant indicating a wifi multicast timer
90 */
91 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070094 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070095 */
96 public static final int VIDEO_TURNED_ON = 8;
97
98 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -080099 * A constant indicating a vibrator on timer
100 */
101 public static final int VIBRATOR_ON = 9;
102
103 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700104 * A constant indicating a foreground activity timer
105 */
106 public static final int FOREGROUND_ACTIVITY = 10;
107
108 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700109 * A constant indicating a wifi batched scan is active
110 */
111 public static final int WIFI_BATCHED_SCAN = 11;
112
113 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700114 * A constant indicating a process state timer
115 */
116 public static final int PROCESS_STATE = 12;
117
118 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700119 * A constant indicating a sync timer
120 */
121 public static final int SYNC = 13;
122
123 /**
124 * A constant indicating a job timer
125 */
126 public static final int JOB = 14;
127
128 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800129 * A constant indicating an audio turn on timer
130 */
131 public static final int AUDIO_TURNED_ON = 15;
132
133 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 * Include all of the data in the stats, including previously saved data.
135 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700136 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137
138 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 * Include only the current run in the stats.
140 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700141 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142
143 /**
144 * Include only the run since the last time the device was unplugged in the stats.
145 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700146 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700147
148 // NOTE: Update this list if you add/change any stats above.
149 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700150 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700151 private static final String[] STAT_NAMES = { "l", "c", "u" };
152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 /**
154 * Bump the version on this if the checkin format changes.
155 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700156 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Evan Millar22ac0432009-03-31 11:33:18 -0700157
158 private static final long BYTES_PER_KB = 1024;
159 private static final long BYTES_PER_MB = 1048576; // 1024^2
160 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700162 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800163 private static final String UID_DATA = "uid";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700165 private static final String PROCESS_DATA = "pr";
166 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800167 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700168 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700169 private static final String STATE_TIME_DATA = "st";
Evan Millare84de8d2009-04-02 22:16:12 -0700170 private static final String WAKELOCK_DATA = "wl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700171 private static final String SYNC_DATA = "sy";
172 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700173 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700174 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700175 private static final String NETWORK_DATA = "nt";
176 private static final String USER_ACTIVITY_DATA = "ua";
177 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800178 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700179 private static final String BATTERY_LEVEL_DATA = "lv";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700180 private static final String WIFI_DATA = "wfl";
Evan Millare84de8d2009-04-02 22:16:12 -0700181 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800182 private static final String GLOBAL_NETWORK_DATA = "gn";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800183 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700184 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700185 private static final String SCREEN_BRIGHTNESS_DATA = "br";
186 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700187 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700188 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
189 private static final String DATA_CONNECTION_TIME_DATA = "dct";
190 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800191 private static final String WIFI_STATE_TIME_DATA = "wst";
192 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700193 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
194 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
195 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
196 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800197 private static final String BLUETOOTH_STATE_TIME_DATA = "bst";
198 private static final String BLUETOOTH_STATE_COUNT_DATA = "bsc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800199 private static final String POWER_USE_SUMMARY_DATA = "pws";
200 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700201 private static final String DISCHARGE_STEP_DATA = "dsd";
202 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700203 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
204 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700206 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 private final Formatter mFormatter = new Formatter(mFormatBuilder);
208
209 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700210 * State for keeping track of counting information.
211 */
212 public static abstract class Counter {
213
214 /**
215 * Returns the count associated with this Counter for the
216 * selected type of statistics.
217 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700218 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700219 */
Evan Millarc64edde2009-04-18 12:26:32 -0700220 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700221
222 /**
223 * Temporary for debugging.
224 */
225 public abstract void logState(Printer pw, String prefix);
226 }
227
228 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700229 * State for keeping track of long counting information.
230 */
231 public static abstract class LongCounter {
232
233 /**
234 * Returns the count associated with this Counter for the
235 * selected type of statistics.
236 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700237 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700238 */
239 public abstract long getCountLocked(int which);
240
241 /**
242 * Temporary for debugging.
243 */
244 public abstract void logState(Printer pw, String prefix);
245 }
246
247 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 * State for keeping track of timing information.
249 */
250 public static abstract class Timer {
251
252 /**
253 * Returns the count associated with this Timer for the
254 * selected type of statistics.
255 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700256 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 */
Evan Millarc64edde2009-04-18 12:26:32 -0700258 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259
260 /**
261 * Returns the total time in microseconds associated with this Timer for the
262 * selected type of statistics.
263 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800264 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700265 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 * @return a time in microseconds
267 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800268 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 /**
271 * Temporary for debugging.
272 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700273 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 }
275
276 /**
277 * The statistics associated with a particular uid.
278 */
279 public static abstract class Uid {
280
281 /**
282 * Returns a mapping containing wakelock statistics.
283 *
284 * @return a Map from Strings to Uid.Wakelock objects.
285 */
286 public abstract Map<String, ? extends Wakelock> getWakelockStats();
287
288 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700289 * Returns a mapping containing sync statistics.
290 *
291 * @return a Map from Strings to Timer objects.
292 */
293 public abstract Map<String, ? extends Timer> getSyncStats();
294
295 /**
296 * Returns a mapping containing scheduled job statistics.
297 *
298 * @return a Map from Strings to Timer objects.
299 */
300 public abstract Map<String, ? extends Timer> getJobStats();
301
302 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 * The statistics associated with a particular wake lock.
304 */
305 public static abstract class Wakelock {
306 public abstract Timer getWakeTime(int type);
307 }
308
309 /**
310 * Returns a mapping containing sensor statistics.
311 *
312 * @return a Map from Integer sensor ids to Uid.Sensor objects.
313 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700314 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315
316 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700317 * Returns a mapping containing active process data.
318 */
319 public abstract SparseArray<? extends Pid> getPidStats();
320
321 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 * Returns a mapping containing process statistics.
323 *
324 * @return a Map from Strings to Uid.Proc objects.
325 */
326 public abstract Map<String, ? extends Proc> getProcessStats();
327
328 /**
329 * Returns a mapping containing package statistics.
330 *
331 * @return a Map from Strings to Uid.Pkg objects.
332 */
333 public abstract Map<String, ? extends Pkg> getPackageStats();
334
335 /**
336 * {@hide}
337 */
338 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700339
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800340 public abstract void noteWifiRunningLocked(long elapsedRealtime);
341 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
342 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
343 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
344 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
345 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
346 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
347 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
348 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
349 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800350 public abstract void noteActivityResumedLocked(long elapsedRealtime);
351 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800352 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
353 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
354 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700355 public abstract int getWifiScanCount(int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800356 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700357 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800358 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
359 public abstract long getAudioTurnedOnTime(long elapsedRealtimeUs, int which);
360 public abstract long getVideoTurnedOnTime(long elapsedRealtimeUs, int which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700361 public abstract Timer getForegroundActivityTimer();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700362
363 // Time this uid has any processes in foreground state.
364 public static final int PROCESS_STATE_FOREGROUND = 0;
365 // Time this uid has any process in active state (not cached).
366 public static final int PROCESS_STATE_ACTIVE = 1;
367 // Time this uid has any processes running at all.
368 public static final int PROCESS_STATE_RUNNING = 2;
369 // Total number of process states we track.
370 public static final int NUM_PROCESS_STATE = 3;
371
372 static final String[] PROCESS_STATE_NAMES = {
373 "Foreground", "Active", "Running"
374 };
375
376 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
377
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800378 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379
Robert Greenwalta029ea12013-09-25 16:38:12 -0700380 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
381
Dianne Hackborn617f8772009-03-31 15:04:46 -0700382 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700383 * Note that these must match the constants in android.os.PowerManager.
384 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
385 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700386 */
387 static final String[] USER_ACTIVITY_TYPES = {
Jeff Browndf693de2012-07-27 12:03:38 -0700388 "other", "button", "touch"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700389 };
390
Jeff Browndf693de2012-07-27 12:03:38 -0700391 public static final int NUM_USER_ACTIVITY_TYPES = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700392
Dianne Hackborn617f8772009-03-31 15:04:46 -0700393 public abstract void noteUserActivityLocked(int type);
394 public abstract boolean hasUserActivity();
395 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700396
397 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800398 public abstract long getNetworkActivityBytes(int type, int which);
399 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800400 public abstract long getMobileRadioActiveTime(int which);
401 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800404 /*
405 * FIXME: it's not correct to use this magic value because it
406 * could clash with a sensor handle (which are defined by
407 * the sensor HAL, and therefore out of our control
408 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 // Magic sensor number for the GPS.
410 public static final int GPS = -10000;
411
412 public abstract int getHandle();
413
414 public abstract Timer getSensorTime();
415 }
416
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700417 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800418 public int mWakeNesting;
419 public long mWakeSumMs;
420 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700421 }
422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 /**
424 * The statistics associated with a particular process.
425 */
426 public static abstract class Proc {
427
Dianne Hackborn287952c2010-09-22 22:34:31 -0700428 public static class ExcessivePower {
429 public static final int TYPE_WAKE = 1;
430 public static final int TYPE_CPU = 2;
431
432 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700433 public long overTime;
434 public long usedTime;
435 }
436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800438 * Returns true if this process is still active in the battery stats.
439 */
440 public abstract boolean isActive();
441
442 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700443 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700445 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 */
447 public abstract long getUserTime(int which);
448
449 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700450 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700452 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 */
454 public abstract long getSystemTime(int which);
455
456 /**
457 * Returns the number of times the process has been started.
458 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700459 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 */
461 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700462
463 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800464 * Returns the number of times the process has crashed.
465 *
466 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
467 */
468 public abstract int getNumCrashes(int which);
469
470 /**
471 * Returns the number of times the process has ANRed.
472 *
473 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
474 */
475 public abstract int getNumAnrs(int which);
476
477 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700478 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700479 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700480 * @return foreground cpu time in microseconds
481 */
482 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700483
484 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700485 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed.
Amith Yamasanie43530a2009-08-21 13:11:37 -0700486 * @param speedStep the index of the CPU speed. This is not the actual speed of the
487 * CPU.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700488 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanie43530a2009-08-21 13:11:37 -0700489 * @see BatteryStats#getCpuSpeedSteps()
490 */
491 public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700492
Dianne Hackborn287952c2010-09-22 22:34:31 -0700493 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700494
Dianne Hackborn287952c2010-09-22 22:34:31 -0700495 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 }
497
498 /**
499 * The statistics associated with a particular package.
500 */
501 public static abstract class Pkg {
502
503 /**
504 * Returns the number of times this package has done something that could wake up the
505 * device from sleep.
506 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700507 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 */
509 public abstract int getWakeups(int which);
510
511 /**
512 * Returns a mapping containing service statistics.
513 */
514 public abstract Map<String, ? extends Serv> getServiceStats();
515
516 /**
517 * The statistics associated with a particular service.
518 */
519 public abstract class Serv {
520
521 /**
522 * Returns the amount of time spent started.
523 *
524 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700525 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 * @return
527 */
528 public abstract long getStartTime(long batteryUptime, int which);
529
530 /**
531 * Returns the total number of times startService() has been called.
532 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700533 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 */
535 public abstract int getStarts(int which);
536
537 /**
538 * Returns the total number times the service has been launched.
539 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700540 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 */
542 public abstract int getLaunches(int which);
543 }
544 }
545 }
546
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800547 public static final class LevelStepTracker {
548 public long mLastStepTime = -1;
549 public int mNumStepDurations;
550 public final long[] mStepDurations;
551
552 public LevelStepTracker(int maxLevelSteps) {
553 mStepDurations = new long[maxLevelSteps];
554 }
555
556 public LevelStepTracker(int numSteps, long[] steps) {
557 mNumStepDurations = numSteps;
558 mStepDurations = new long[numSteps];
559 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
560 }
561
562 public long getDurationAt(int index) {
563 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
564 }
565
566 public int getLevelAt(int index) {
567 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
568 >> STEP_LEVEL_LEVEL_SHIFT);
569 }
570
571 public int getInitModeAt(int index) {
572 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
573 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
574 }
575
576 public int getModModeAt(int index) {
577 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
578 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
579 }
580
581 private void appendHex(long val, int topOffset, StringBuilder out) {
582 boolean hasData = false;
583 while (topOffset >= 0) {
584 int digit = (int)( (val>>topOffset) & 0xf );
585 topOffset -= 4;
586 if (!hasData && digit == 0) {
587 continue;
588 }
589 hasData = true;
590 if (digit >= 0 && digit <= 9) {
591 out.append((char)('0' + digit));
592 } else {
593 out.append((char)('a' + digit - 10));
594 }
595 }
596 }
597
598 public void encodeEntryAt(int index, StringBuilder out) {
599 long item = mStepDurations[index];
600 long duration = item & STEP_LEVEL_TIME_MASK;
601 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
602 >> STEP_LEVEL_LEVEL_SHIFT);
603 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
604 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
605 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
606 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
607 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
608 case Display.STATE_OFF: out.append('f'); break;
609 case Display.STATE_ON: out.append('o'); break;
610 case Display.STATE_DOZE: out.append('d'); break;
611 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
612 }
613 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
614 out.append('p');
615 }
616 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
617 case Display.STATE_OFF: out.append('F'); break;
618 case Display.STATE_ON: out.append('O'); break;
619 case Display.STATE_DOZE: out.append('D'); break;
620 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
621 }
622 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
623 out.append('P');
624 }
625 out.append('-');
626 appendHex(level, 4, out);
627 out.append('-');
628 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
629 }
630
631 public void decodeEntryAt(int index, String value) {
632 final int N = value.length();
633 int i = 0;
634 char c;
635 long out = 0;
636 while (i < N && (c=value.charAt(i)) != '-') {
637 i++;
638 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800639 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800640 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800641 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800642 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800643 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800644 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800645 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
646 << STEP_LEVEL_INITIAL_MODE_SHIFT);
647 break;
648 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
649 << STEP_LEVEL_INITIAL_MODE_SHIFT);
650 break;
651 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
652 break;
653 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
654 break;
655 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
656 break;
657 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
658 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
659 break;
660 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
661 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800662 break;
663 }
664 }
665 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800666 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800667 while (i < N && (c=value.charAt(i)) != '-') {
668 i++;
669 level <<= 4;
670 if (c >= '0' && c <= '9') {
671 level += c - '0';
672 } else if (c >= 'a' && c <= 'f') {
673 level += c - 'a' + 10;
674 } else if (c >= 'A' && c <= 'F') {
675 level += c - 'A' + 10;
676 }
677 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800678 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800679 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
680 long duration = 0;
681 while (i < N && (c=value.charAt(i)) != '-') {
682 i++;
683 duration <<= 4;
684 if (c >= '0' && c <= '9') {
685 duration += c - '0';
686 } else if (c >= 'a' && c <= 'f') {
687 duration += c - 'a' + 10;
688 } else if (c >= 'A' && c <= 'F') {
689 duration += c - 'A' + 10;
690 }
691 }
692 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
693 }
694
695 public void init() {
696 mLastStepTime = -1;
697 mNumStepDurations = 0;
698 }
699
700 public void clearTime() {
701 mLastStepTime = -1;
702 }
703
704 public long computeTimePerLevel() {
705 final long[] steps = mStepDurations;
706 final int numSteps = mNumStepDurations;
707
708 // For now we'll do a simple average across all steps.
709 if (numSteps <= 0) {
710 return -1;
711 }
712 long total = 0;
713 for (int i=0; i<numSteps; i++) {
714 total += steps[i] & STEP_LEVEL_TIME_MASK;
715 }
716 return total / numSteps;
717 /*
718 long[] buckets = new long[numSteps];
719 int numBuckets = 0;
720 int numToAverage = 4;
721 int i = 0;
722 while (i < numSteps) {
723 long totalTime = 0;
724 int num = 0;
725 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
726 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
727 num++;
728 }
729 buckets[numBuckets] = totalTime / num;
730 numBuckets++;
731 numToAverage *= 2;
732 i += num;
733 }
734 if (numBuckets < 1) {
735 return -1;
736 }
737 long averageTime = buckets[numBuckets-1];
738 for (i=numBuckets-2; i>=0; i--) {
739 averageTime = (averageTime + buckets[i]) / 2;
740 }
741 return averageTime;
742 */
743 }
744
745 public long computeTimeEstimate(long modesOfInterest, long modeValues,
746 int[] outNumOfInterest) {
747 final long[] steps = mStepDurations;
748 final int count = mNumStepDurations;
749 if (count <= 0) {
750 return -1;
751 }
752 long total = 0;
753 int numOfInterest = 0;
754 for (int i=0; i<count; i++) {
755 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
756 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
757 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
758 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
759 // If the modes of interest didn't change during this step period...
760 if ((modMode&modesOfInterest) == 0) {
761 // And the mode values during this period match those we are measuring...
762 if ((initMode&modesOfInterest) == modeValues) {
763 // Then this can be used to estimate the total time!
764 numOfInterest++;
765 total += steps[i] & STEP_LEVEL_TIME_MASK;
766 }
767 }
768 }
769 if (numOfInterest <= 0) {
770 return -1;
771 }
772
773 if (outNumOfInterest != null) {
774 outNumOfInterest[0] = numOfInterest;
775 }
776
777 // The estimated time is the average time we spend in each level, multipled
778 // by 100 -- the total number of battery levels
779 return (total / numOfInterest) * 100;
780 }
781
782 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
783 int stepCount = mNumStepDurations;
784 final long lastStepTime = mLastStepTime;
785 if (lastStepTime >= 0 && numStepLevels > 0) {
786 final long[] steps = mStepDurations;
787 long duration = elapsedRealtime - lastStepTime;
788 for (int i=0; i<numStepLevels; i++) {
789 System.arraycopy(steps, 0, steps, 1, steps.length-1);
790 long thisDuration = duration / (numStepLevels-i);
791 duration -= thisDuration;
792 if (thisDuration > STEP_LEVEL_TIME_MASK) {
793 thisDuration = STEP_LEVEL_TIME_MASK;
794 }
795 steps[0] = thisDuration | modeBits;
796 }
797 stepCount += numStepLevels;
798 if (stepCount > steps.length) {
799 stepCount = steps.length;
800 }
801 }
802 mNumStepDurations = stepCount;
803 mLastStepTime = elapsedRealtime;
804 }
805
806 public void readFromParcel(Parcel in) {
807 final int N = in.readInt();
808 mNumStepDurations = N;
809 for (int i=0; i<N; i++) {
810 mStepDurations[i] = in.readLong();
811 }
812 }
813
814 public void writeToParcel(Parcel out) {
815 final int N = mNumStepDurations;
816 out.writeInt(N);
817 for (int i=0; i<N; i++) {
818 out.writeLong(mStepDurations[i]);
819 }
820 }
821 }
822
823 public static final class DailyItem {
824 public long mStartTime;
825 public long mEndTime;
826 public LevelStepTracker mDischargeSteps;
827 public LevelStepTracker mChargeSteps;
828 }
829
830 public abstract DailyItem getDailyItemLocked(int daysAgo);
831
832 public abstract long getCurrentDailyStartTime();
833
834 public abstract long getNextMinDailyDeadline();
835
836 public abstract long getNextMaxDailyDeadline();
837
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800838 public final static class HistoryTag {
839 public String string;
840 public int uid;
841
842 public int poolIdx;
843
844 public void setTo(HistoryTag o) {
845 string = o.string;
846 uid = o.uid;
847 poolIdx = o.poolIdx;
848 }
849
850 public void setTo(String _string, int _uid) {
851 string = _string;
852 uid = _uid;
853 poolIdx = -1;
854 }
855
856 public void writeToParcel(Parcel dest, int flags) {
857 dest.writeString(string);
858 dest.writeInt(uid);
859 }
860
861 public void readFromParcel(Parcel src) {
862 string = src.readString();
863 uid = src.readInt();
864 poolIdx = -1;
865 }
866
867 @Override
868 public boolean equals(Object o) {
869 if (this == o) return true;
870 if (o == null || getClass() != o.getClass()) return false;
871
872 HistoryTag that = (HistoryTag) o;
873
874 if (uid != that.uid) return false;
875 if (!string.equals(that.string)) return false;
876
877 return true;
878 }
879
880 @Override
881 public int hashCode() {
882 int result = string.hashCode();
883 result = 31 * result + uid;
884 return result;
885 }
886 }
887
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -0800888 /**
889 * Optional detailed information that can go into a history step. This is typically
890 * generated each time the battery level changes.
891 */
892 public final static class HistoryStepDetails {
893 // Time (in 1/100 second) spent in user space and the kernel since the last step.
894 public int userTime;
895 public int systemTime;
896
897 // Top three apps using CPU in the last step, with times in 1/100 second.
898 public int appCpuUid1;
899 public int appCpuUTime1;
900 public int appCpuSTime1;
901 public int appCpuUid2;
902 public int appCpuUTime2;
903 public int appCpuSTime2;
904 public int appCpuUid3;
905 public int appCpuUTime3;
906 public int appCpuSTime3;
907
908 // Information from /proc/stat
909 public int statUserTime;
910 public int statSystemTime;
911 public int statIOWaitTime;
912 public int statIrqTime;
913 public int statSoftIrqTime;
914 public int statIdlTime;
915
916 public HistoryStepDetails() {
917 clear();
918 }
919
920 public void clear() {
921 userTime = systemTime = 0;
922 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
923 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
924 = appCpuUTime3 = appCpuSTime3 = 0;
925 }
926
927 public void writeToParcel(Parcel out) {
928 out.writeInt(userTime);
929 out.writeInt(systemTime);
930 out.writeInt(appCpuUid1);
931 out.writeInt(appCpuUTime1);
932 out.writeInt(appCpuSTime1);
933 out.writeInt(appCpuUid2);
934 out.writeInt(appCpuUTime2);
935 out.writeInt(appCpuSTime2);
936 out.writeInt(appCpuUid3);
937 out.writeInt(appCpuUTime3);
938 out.writeInt(appCpuSTime3);
939 out.writeInt(statUserTime);
940 out.writeInt(statSystemTime);
941 out.writeInt(statIOWaitTime);
942 out.writeInt(statIrqTime);
943 out.writeInt(statSoftIrqTime);
944 out.writeInt(statIdlTime);
945 }
946
947 public void readFromParcel(Parcel in) {
948 userTime = in.readInt();
949 systemTime = in.readInt();
950 appCpuUid1 = in.readInt();
951 appCpuUTime1 = in.readInt();
952 appCpuSTime1 = in.readInt();
953 appCpuUid2 = in.readInt();
954 appCpuUTime2 = in.readInt();
955 appCpuSTime2 = in.readInt();
956 appCpuUid3 = in.readInt();
957 appCpuUTime3 = in.readInt();
958 appCpuSTime3 = in.readInt();
959 statUserTime = in.readInt();
960 statSystemTime = in.readInt();
961 statIOWaitTime = in.readInt();
962 statIrqTime = in.readInt();
963 statSoftIrqTime = in.readInt();
964 statIdlTime = in.readInt();
965 }
966 }
967
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700968 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700969 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -0700970
971 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700972 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800973
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800974 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800975 public static final byte CMD_NULL = -1;
976 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800977 public static final byte CMD_CURRENT_TIME = 5;
978 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -0700979 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -0800980 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800981
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700982 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700983
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800984 /**
985 * Return whether the command code is a delta data update.
986 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800987 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800988 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800989 }
990
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700991 public byte batteryLevel;
992 public byte batteryStatus;
993 public byte batteryHealth;
994 public byte batteryPlugType;
995
Sungmin Choic7e9e8b2013-01-16 12:57:36 +0900996 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700997 public char batteryVoltage;
998
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700999 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001000 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001001 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001002 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001003 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1004 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001005 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001006 public static final int STATE_PHONE_STATE_SHIFT = 6;
1007 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001008 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001009 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001010 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001011
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001012 // These states always appear directly in the first int token
1013 // of a delta change; they should be ones that change relatively
1014 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001015 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1016 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001017 public static final int STATE_GPS_ON_FLAG = 1<<29;
1018 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001019 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001020 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001021 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001022 // These are on the lower bits used for the command; if they change
1023 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001024 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001025 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001026 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001027 public static final int STATE_SCREEN_ON_FLAG = 1<<20;
1028 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19;
1029 public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001030 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001031
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001032 public static final int MOST_INTERESTING_STATES =
1033 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
Dianne Hackborn3251b902014-06-20 14:40:53 -07001034 | STATE_PHONE_IN_CALL_FLAG | STATE_BLUETOOTH_ON_FLAG;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001035
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001036 public int states;
1037
Dianne Hackborn3251b902014-06-20 14:40:53 -07001038 // Constants from WIFI_SUPPL_STATE_*
1039 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1040 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1041 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1042 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1043 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1044 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1045
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001046 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001047 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1048 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1049 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001050 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001051 public static final int STATE2_DEVICE_IDLE_FLAG = 1<<26;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001052
1053 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001054 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_FLAG;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001055
Dianne Hackborn40c87252014-03-19 16:55:40 -07001056 public int states2;
1057
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001058 // The wake lock that was acquired at this point.
1059 public HistoryTag wakelockTag;
1060
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001061 // Kernel wakeup reason at this point.
1062 public HistoryTag wakeReasonTag;
1063
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001064 // Non-null when there is more detailed information at this step.
1065 public HistoryStepDetails stepDetails;
1066
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001067 public static final int EVENT_FLAG_START = 0x8000;
1068 public static final int EVENT_FLAG_FINISH = 0x4000;
1069
1070 // No event in this item.
1071 public static final int EVENT_NONE = 0x0000;
1072 // Event is about a process that is running.
1073 public static final int EVENT_PROC = 0x0001;
1074 // Event is about an application package that is in the foreground.
1075 public static final int EVENT_FOREGROUND = 0x0002;
1076 // Event is about an application package that is at the top of the screen.
1077 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001078 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001079 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001080 // Events for all additional wake locks aquired/release within a wake block.
1081 // These are not generated by default.
1082 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001083 // Event is about an application executing a scheduled job.
1084 public static final int EVENT_JOB = 0x0006;
1085 // Events for users running.
1086 public static final int EVENT_USER_RUNNING = 0x0007;
1087 // Events for foreground user.
1088 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001089 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001090 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001091 // Event for significant motion taking us out of idle mode.
1092 public static final int EVENT_SIGNIFICANT_MOTION = 0x000a;
1093 // Event for becoming active taking us out of idle mode.
1094 public static final int EVENT_ACTIVE = 0x000b;
1095 // Event for a package being installed.
1096 public static final int EVENT_PACKAGE_INSTALLED = 0x000c;
1097 // Event for a package being uninstalled.
1098 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000d;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001099 // Number of event types.
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001100 public static final int EVENT_COUNT = 0x000e;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001101 // Mask to extract out only the type part of the event.
1102 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001103
1104 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1105 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1106 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1107 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1108 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1109 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001110 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1111 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001112 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1113 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001114 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1115 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1116 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1117 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1118 public static final int EVENT_USER_FOREGROUND_START =
1119 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1120 public static final int EVENT_USER_FOREGROUND_FINISH =
1121 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001122
1123 // For CMD_EVENT.
1124 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001125 public HistoryTag eventTag;
1126
Dianne Hackborn9a755432014-05-15 17:05:22 -07001127 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001128 public long currentTime;
1129
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001130 // Meta-data when reading.
1131 public int numReadInts;
1132
1133 // Pre-allocated objects.
1134 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001135 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001136 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001137
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001138 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001139 }
1140
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001141 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001142 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001143 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001144 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001145 }
1146
1147 public int describeContents() {
1148 return 0;
1149 }
1150
1151 public void writeToParcel(Parcel dest, int flags) {
1152 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001153 int bat = (((int)cmd)&0xff)
1154 | ((((int)batteryLevel)<<8)&0xff00)
1155 | ((((int)batteryStatus)<<16)&0xf0000)
1156 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001157 | ((((int)batteryPlugType)<<24)&0xf000000)
1158 | (wakelockTag != null ? 0x10000000 : 0)
1159 | (wakeReasonTag != null ? 0x20000000 : 0)
1160 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001161 dest.writeInt(bat);
1162 bat = (((int)batteryTemperature)&0xffff)
1163 | ((((int)batteryVoltage)<<16)&0xffff0000);
1164 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001165 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001166 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001167 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001168 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001169 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001170 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001171 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001172 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001173 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001174 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001175 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001176 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001177 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001178 dest.writeLong(currentTime);
1179 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001180 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001181
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001182 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001183 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001184 int bat = src.readInt();
1185 cmd = (byte)(bat&0xff);
1186 batteryLevel = (byte)((bat>>8)&0xff);
1187 batteryStatus = (byte)((bat>>16)&0xf);
1188 batteryHealth = (byte)((bat>>20)&0xf);
1189 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001190 int bat2 = src.readInt();
1191 batteryTemperature = (short)(bat2&0xffff);
1192 batteryVoltage = (char)((bat2>>16)&0xffff);
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001193 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001194 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001195 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001196 wakelockTag = localWakelockTag;
1197 wakelockTag.readFromParcel(src);
1198 } else {
1199 wakelockTag = null;
1200 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001201 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001202 wakeReasonTag = localWakeReasonTag;
1203 wakeReasonTag.readFromParcel(src);
1204 } else {
1205 wakeReasonTag = null;
1206 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001207 if ((bat&0x40000000) != 0) {
1208 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001209 eventTag = localEventTag;
1210 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001211 } else {
1212 eventCode = EVENT_NONE;
1213 eventTag = null;
1214 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001215 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001216 currentTime = src.readLong();
1217 } else {
1218 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001219 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001220 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001221 }
1222
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001223 public void clear() {
1224 time = 0;
1225 cmd = CMD_NULL;
1226 batteryLevel = 0;
1227 batteryStatus = 0;
1228 batteryHealth = 0;
1229 batteryPlugType = 0;
1230 batteryTemperature = 0;
1231 batteryVoltage = 0;
1232 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001233 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001234 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001235 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001236 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001237 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001238 }
1239
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001240 public void setTo(HistoryItem o) {
1241 time = o.time;
1242 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001243 setToCommon(o);
1244 }
1245
1246 public void setTo(long time, byte cmd, HistoryItem o) {
1247 this.time = time;
1248 this.cmd = cmd;
1249 setToCommon(o);
1250 }
1251
1252 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001253 batteryLevel = o.batteryLevel;
1254 batteryStatus = o.batteryStatus;
1255 batteryHealth = o.batteryHealth;
1256 batteryPlugType = o.batteryPlugType;
1257 batteryTemperature = o.batteryTemperature;
1258 batteryVoltage = o.batteryVoltage;
1259 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001260 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001261 if (o.wakelockTag != null) {
1262 wakelockTag = localWakelockTag;
1263 wakelockTag.setTo(o.wakelockTag);
1264 } else {
1265 wakelockTag = null;
1266 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001267 if (o.wakeReasonTag != null) {
1268 wakeReasonTag = localWakeReasonTag;
1269 wakeReasonTag.setTo(o.wakeReasonTag);
1270 } else {
1271 wakeReasonTag = null;
1272 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001273 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001274 if (o.eventTag != null) {
1275 eventTag = localEventTag;
1276 eventTag.setTo(o.eventTag);
1277 } else {
1278 eventTag = null;
1279 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001280 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001281 }
1282
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001283 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001284 return batteryLevel == o.batteryLevel
1285 && batteryStatus == o.batteryStatus
1286 && batteryHealth == o.batteryHealth
1287 && batteryPlugType == o.batteryPlugType
1288 && batteryTemperature == o.batteryTemperature
1289 && batteryVoltage == o.batteryVoltage
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001290 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001291 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001292 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001293 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001294
1295 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001296 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001297 return false;
1298 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001299 if (wakelockTag != o.wakelockTag) {
1300 if (wakelockTag == null || o.wakelockTag == null) {
1301 return false;
1302 }
1303 if (!wakelockTag.equals(o.wakelockTag)) {
1304 return false;
1305 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001306 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001307 if (wakeReasonTag != o.wakeReasonTag) {
1308 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1309 return false;
1310 }
1311 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1312 return false;
1313 }
1314 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001315 if (eventTag != o.eventTag) {
1316 if (eventTag == null || o.eventTag == null) {
1317 return false;
1318 }
1319 if (!eventTag.equals(o.eventTag)) {
1320 return false;
1321 }
1322 }
1323 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001324 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001325 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001326
1327 public final static class HistoryEventTracker {
1328 private final HashMap<String, SparseIntArray>[] mActiveEvents
1329 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1330
1331 public boolean updateState(int code, String name, int uid, int poolIdx) {
1332 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1333 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1334 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1335 if (active == null) {
1336 active = new HashMap<String, SparseIntArray>();
1337 mActiveEvents[idx] = active;
1338 }
1339 SparseIntArray uids = active.get(name);
1340 if (uids == null) {
1341 uids = new SparseIntArray();
1342 active.put(name, uids);
1343 }
1344 if (uids.indexOfKey(uid) >= 0) {
1345 // Already set, nothing to do!
1346 return false;
1347 }
1348 uids.put(uid, poolIdx);
1349 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1350 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1351 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1352 if (active == null) {
1353 // not currently active, nothing to do.
1354 return false;
1355 }
1356 SparseIntArray uids = active.get(name);
1357 if (uids == null) {
1358 // not currently active, nothing to do.
1359 return false;
1360 }
1361 idx = uids.indexOfKey(uid);
1362 if (idx < 0) {
1363 // not currently active, nothing to do.
1364 return false;
1365 }
1366 uids.removeAt(idx);
1367 if (uids.size() <= 0) {
1368 active.remove(name);
1369 }
1370 }
1371 return true;
1372 }
1373
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001374 public void removeEvents(int code) {
1375 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1376 mActiveEvents[idx] = null;
1377 }
1378
Dianne Hackborn37de0982014-05-09 09:32:18 -07001379 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1380 return mActiveEvents[code];
1381 }
1382 }
1383
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001384 public static final class BitDescription {
1385 public final int mask;
1386 public final int shift;
1387 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001388 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001389 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001390 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001391
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001392 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001393 this.mask = mask;
1394 this.shift = -1;
1395 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001396 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001397 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001398 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001399 }
1400
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001401 public BitDescription(int mask, int shift, String name, String shortName,
1402 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001403 this.mask = mask;
1404 this.shift = shift;
1405 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001406 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001407 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001408 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001409 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001410 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001411
Dianne Hackbornfc064132014-06-02 12:42:12 -07001412 /**
1413 * Don't allow any more batching in to the current history event. This
1414 * is called when printing partial histories, so to ensure that the next
1415 * history event will go in to a new batch after what was printed in the
1416 * last partial history.
1417 */
1418 public abstract void commitCurrentHistoryBatchLocked();
1419
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001420 public abstract int getHistoryTotalSize();
1421
1422 public abstract int getHistoryUsedSize();
1423
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001424 public abstract boolean startIteratingHistoryLocked();
1425
Dianne Hackborn099bc622014-01-22 13:39:16 -08001426 public abstract int getHistoryStringPoolSize();
1427
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001428 public abstract int getHistoryStringPoolBytes();
1429
1430 public abstract String getHistoryTagPoolString(int index);
1431
1432 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001433
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001434 public abstract boolean getNextHistoryLocked(HistoryItem out);
1435
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001436 public abstract void finishIteratingHistoryLocked();
1437
1438 public abstract boolean startIteratingOldHistoryLocked();
1439
1440 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1441
1442 public abstract void finishIteratingOldHistoryLocked();
1443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001445 * Return the base time offset for the battery history.
1446 */
1447 public abstract long getHistoryBaseTime();
1448
1449 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 * Returns the number of times the device has been started.
1451 */
1452 public abstract int getStartCount();
1453
1454 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001455 * 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 -08001456 * running on battery.
1457 *
1458 * {@hide}
1459 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001460 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001462 /**
1463 * Returns the number of times the screen was turned on.
1464 *
1465 * {@hide}
1466 */
1467 public abstract int getScreenOnCount(int which);
1468
Jeff Browne95c3cd2014-05-02 16:59:26 -07001469 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1470
Dianne Hackborn617f8772009-03-31 15:04:46 -07001471 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1472 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1473 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1474 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1475 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1476
1477 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1478 "dark", "dim", "medium", "light", "bright"
1479 };
1480
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001481 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1482 "0", "1", "2", "3", "4"
1483 };
1484
Dianne Hackborn617f8772009-03-31 15:04:46 -07001485 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001486
Dianne Hackborn617f8772009-03-31 15:04:46 -07001487 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001488 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001489 * the given brightness
1490 *
1491 * {@hide}
1492 */
1493 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001494 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001497 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001498 * running on battery.
1499 *
1500 * {@hide}
1501 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001502 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001503
1504 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001505 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001506 *
1507 * {@hide}
1508 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001509 public abstract int getPowerSaveModeEnabledCount(int which);
1510
1511 /**
1512 * Returns the time in microseconds that device has been in idle mode while
1513 * running on battery.
1514 *
1515 * {@hide}
1516 */
1517 public abstract long getDeviceIdleModeEnabledTime(long elapsedRealtimeUs, int which);
1518
1519 /**
1520 * Returns the number of times that the devie has gone in to idle mode.
1521 *
1522 * {@hide}
1523 */
1524 public abstract int getDeviceIdleModeEnabledCount(int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001525
1526 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001527 * Returns the number of times that connectivity state changed.
1528 *
1529 * {@hide}
1530 */
1531 public abstract int getNumConnectivityChange(int which);
1532
1533 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001534 * 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 -08001535 * running on battery.
1536 *
1537 * {@hide}
1538 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001539 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001540
1541 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001542 * Returns the number of times a phone call was activated.
1543 *
1544 * {@hide}
1545 */
1546 public abstract int getPhoneOnCount(int which);
1547
1548 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001549 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001550 * the given signal strength.
1551 *
1552 * {@hide}
1553 */
1554 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001555 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001556
Dianne Hackborn617f8772009-03-31 15:04:46 -07001557 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001558 * Returns the time in microseconds that the phone has been trying to
1559 * acquire a signal.
1560 *
1561 * {@hide}
1562 */
1563 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001564 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001565
1566 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001567 * Returns the number of times the phone has entered the given signal strength.
1568 *
1569 * {@hide}
1570 */
1571 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1572
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001573 /**
1574 * Returns the time in microseconds that the mobile network has been active
1575 * (in a high power state).
1576 *
1577 * {@hide}
1578 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001579 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001580
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001581 /**
1582 * Returns the number of times that the mobile network has transitioned to the
1583 * active state.
1584 *
1585 * {@hide}
1586 */
1587 public abstract int getMobileRadioActiveCount(int which);
1588
1589 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001590 * Returns the time in microseconds that is the difference between the mobile radio
1591 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1592 * from the radio.
1593 *
1594 * {@hide}
1595 */
1596 public abstract long getMobileRadioActiveAdjustedTime(int which);
1597
1598 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001599 * Returns the time in microseconds that the mobile network has been active
1600 * (in a high power state) but not being able to blame on an app.
1601 *
1602 * {@hide}
1603 */
1604 public abstract long getMobileRadioActiveUnknownTime(int which);
1605
1606 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001607 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001608 *
1609 * {@hide}
1610 */
1611 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001612
Dianne Hackborn627bba72009-03-24 22:32:56 -07001613 public static final int DATA_CONNECTION_NONE = 0;
1614 public static final int DATA_CONNECTION_GPRS = 1;
1615 public static final int DATA_CONNECTION_EDGE = 2;
1616 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001617 public static final int DATA_CONNECTION_CDMA = 4;
1618 public static final int DATA_CONNECTION_EVDO_0 = 5;
1619 public static final int DATA_CONNECTION_EVDO_A = 6;
1620 public static final int DATA_CONNECTION_1xRTT = 7;
1621 public static final int DATA_CONNECTION_HSDPA = 8;
1622 public static final int DATA_CONNECTION_HSUPA = 9;
1623 public static final int DATA_CONNECTION_HSPA = 10;
1624 public static final int DATA_CONNECTION_IDEN = 11;
1625 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001626 public static final int DATA_CONNECTION_LTE = 13;
1627 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001628 public static final int DATA_CONNECTION_HSPAP = 15;
1629 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001630
Dianne Hackborn627bba72009-03-24 22:32:56 -07001631 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001632 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001633 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001634 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001635 };
1636
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001637 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001638
1639 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001640 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001641 * the given data connection.
1642 *
1643 * {@hide}
1644 */
1645 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001646 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001649 * Returns the number of times the phone has entered the given data
1650 * connection type.
1651 *
1652 * {@hide}
1653 */
1654 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001655
Dianne Hackborn3251b902014-06-20 14:40:53 -07001656 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1657 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1658 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1659 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1660 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1661 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1662 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1663 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1664 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1665 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1666 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1667 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1668 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1669
1670 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1671
1672 static final String[] WIFI_SUPPL_STATE_NAMES = {
1673 "invalid", "disconn", "disabled", "inactive", "scanning",
1674 "authenticating", "associating", "associated", "4-way-handshake",
1675 "group-handshake", "completed", "dormant", "uninit"
1676 };
1677
1678 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1679 "inv", "dsc", "dis", "inact", "scan",
1680 "auth", "ascing", "asced", "4-way",
1681 "group", "compl", "dorm", "uninit"
1682 };
1683
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001684 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1685 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001686 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001687 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1688 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001689 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001690 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1691 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1692 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001693 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001694 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001695 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001696 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1697 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
1698 new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001699 new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
1700 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1701 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1702 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1703 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1704 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1705 new String[] {"in", "out", "emergency", "off"},
1706 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001707 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1708 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1709 SignalStrength.SIGNAL_STRENGTH_NAMES,
1710 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001711 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1712 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1713 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001714 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001715
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001716 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1717 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001718 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001719 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
1720 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Wr"),
1721 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001722 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001723 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_FLAG, "device_idle", "di"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001724 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1725 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1726 new String[] { "0", "1", "2", "3", "4" },
1727 new String[] { "0", "1", "2", "3", "4" }),
1728 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1729 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1730 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001731 };
1732
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001733 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001734 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
1735 "motion", "active", "pkginst", "pkgunin"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001736 };
1737
1738 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001739 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
1740 "Esm", "Eac", "Epi", "Epu"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001741 };
1742
Dianne Hackborn617f8772009-03-31 15:04:46 -07001743 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001744 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001745 * running on battery.
1746 *
1747 * {@hide}
1748 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001749 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001750
1751 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001752 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001753 * been in the running state while the device was running on battery.
1754 *
1755 * {@hide}
1756 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001757 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001758
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001759 public static final int WIFI_STATE_OFF = 0;
1760 public static final int WIFI_STATE_OFF_SCANNING = 1;
1761 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
1762 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
1763 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
1764 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
1765 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
1766 public static final int WIFI_STATE_SOFT_AP = 7;
1767
1768 static final String[] WIFI_STATE_NAMES = {
1769 "off", "scanning", "no_net", "disconn",
1770 "sta", "p2p", "sta_p2p", "soft_ap"
1771 };
1772
1773 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
1774
1775 /**
1776 * Returns the time in microseconds that WiFi has been running in the given state.
1777 *
1778 * {@hide}
1779 */
1780 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001781 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001782
1783 /**
1784 * Returns the number of times that WiFi has entered the given state.
1785 *
1786 * {@hide}
1787 */
1788 public abstract int getWifiStateCount(int wifiState, int which);
1789
The Android Open Source Project10592532009-03-18 17:39:46 -07001790 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07001791 * Returns the time in microseconds that the wifi supplicant has been
1792 * in a given state.
1793 *
1794 * {@hide}
1795 */
1796 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
1797
1798 /**
1799 * Returns the number of times that the wifi supplicant has transitioned
1800 * to a given state.
1801 *
1802 * {@hide}
1803 */
1804 public abstract int getWifiSupplStateCount(int state, int which);
1805
1806 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
1807
1808 /**
1809 * Returns the time in microseconds that WIFI has been running with
1810 * the given signal strength.
1811 *
1812 * {@hide}
1813 */
1814 public abstract long getWifiSignalStrengthTime(int strengthBin,
1815 long elapsedRealtimeUs, int which);
1816
1817 /**
1818 * Returns the number of times WIFI has entered the given signal strength.
1819 *
1820 * {@hide}
1821 */
1822 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
1823
1824 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001825 * Returns the time in microseconds that bluetooth has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001826 * running on battery.
1827 *
1828 * {@hide}
1829 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001830 public abstract long getBluetoothOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001831
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001832 public abstract int getBluetoothPingCount();
1833
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001834 public static final int BLUETOOTH_STATE_INACTIVE = 0;
1835 public static final int BLUETOOTH_STATE_LOW = 1;
1836 public static final int BLUETOOTH_STATE_MEDIUM = 2;
1837 public static final int BLUETOOTH_STATE_HIGH = 3;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001838
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001839 static final String[] BLUETOOTH_STATE_NAMES = {
1840 "inactive", "low", "med", "high"
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001841 };
1842
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001843 public static final int NUM_BLUETOOTH_STATES = BLUETOOTH_STATE_HIGH +1;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001844
1845 /**
1846 * Returns the time in microseconds that Bluetooth has been running in the
1847 * given active state.
1848 *
1849 * {@hide}
1850 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001851 public abstract long getBluetoothStateTime(int bluetoothState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001852 long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001853
1854 /**
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001855 * Returns the number of times that Bluetooth has entered the given active state.
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001856 *
1857 * {@hide}
1858 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001859 public abstract int getBluetoothStateCount(int bluetoothState, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001860
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001861 /**
1862 * Returns the time in microseconds that the flashlight has been on while the device was
1863 * running on battery.
1864 *
1865 * {@hide}
1866 */
1867 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
1868
1869 /**
1870 * Returns the number of times that the flashlight has been turned on while the device was
1871 * running on battery.
1872 *
1873 * {@hide}
1874 */
1875 public abstract long getFlashlightOnCount(int which);
1876
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001877 public static final int NETWORK_MOBILE_RX_DATA = 0;
1878 public static final int NETWORK_MOBILE_TX_DATA = 1;
1879 public static final int NETWORK_WIFI_RX_DATA = 2;
1880 public static final int NETWORK_WIFI_TX_DATA = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001881
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001882 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001883
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001884 public abstract long getNetworkActivityBytes(int type, int which);
1885 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001886
Adam Lesinski33dac552015-03-09 15:24:48 -07001887 public static final int CONTROLLER_IDLE_TIME = 0;
1888 public static final int CONTROLLER_RX_TIME = 1;
1889 public static final int CONTROLLER_TX_TIME = 2;
1890 public static final int CONTROLLER_ENERGY = 3;
1891 public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_ENERGY + 1;
1892
1893 public abstract long getBluetoothControllerActivity(int type, int which);
1894 public abstract long getWifiControllerActivity(int type, int which);
1895
The Android Open Source Project10592532009-03-18 17:39:46 -07001896 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08001897 * Return the wall clock time when battery stats data collection started.
1898 */
1899 public abstract long getStartClockTime();
1900
1901 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07001902 * Return platform version tag that we were running in when the battery stats started.
1903 */
1904 public abstract String getStartPlatformVersion();
1905
1906 /**
1907 * Return platform version tag that we were running in when the battery stats ended.
1908 */
1909 public abstract String getEndPlatformVersion();
1910
1911 /**
1912 * Return the internal version code of the parcelled format.
1913 */
1914 public abstract int getParcelVersion();
1915
1916 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001917 * Return whether we are currently running on battery.
1918 */
1919 public abstract boolean getIsOnBattery();
1920
1921 /**
1922 * Returns a SparseArray containing the statistics for each uid.
1923 */
1924 public abstract SparseArray<? extends Uid> getUidStats();
1925
1926 /**
1927 * Returns the current battery uptime in microseconds.
1928 *
1929 * @param curTime the amount of elapsed realtime in microseconds.
1930 */
1931 public abstract long getBatteryUptime(long curTime);
1932
1933 /**
1934 * Returns the current battery realtime in microseconds.
1935 *
1936 * @param curTime the amount of elapsed realtime in microseconds.
1937 */
1938 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001939
1940 /**
Evan Millar633a1742009-04-02 16:36:33 -07001941 * Returns the battery percentage level at the last time the device was unplugged from power, or
1942 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07001943 */
Evan Millar633a1742009-04-02 16:36:33 -07001944 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07001945
1946 /**
Evan Millar633a1742009-04-02 16:36:33 -07001947 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
1948 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07001949 */
Evan Millar633a1742009-04-02 16:36:33 -07001950 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951
1952 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001953 * Get the amount the battery has discharged since the stats were
1954 * last reset after charging, as a lower-end approximation.
1955 */
1956 public abstract int getLowDischargeAmountSinceCharge();
1957
1958 /**
1959 * Get the amount the battery has discharged since the stats were
1960 * last reset after charging, as an upper-end approximation.
1961 */
1962 public abstract int getHighDischargeAmountSinceCharge();
1963
1964 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07001965 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
1966 */
1967 public abstract int getDischargeAmount(int which);
1968
1969 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08001970 * Get the amount the battery has discharged while the screen was on,
1971 * since the last time power was unplugged.
1972 */
1973 public abstract int getDischargeAmountScreenOn();
1974
1975 /**
1976 * Get the amount the battery has discharged while the screen was on,
1977 * since the last time the device was charged.
1978 */
1979 public abstract int getDischargeAmountScreenOnSinceCharge();
1980
1981 /**
1982 * Get the amount the battery has discharged while the screen was off,
1983 * since the last time power was unplugged.
1984 */
1985 public abstract int getDischargeAmountScreenOff();
1986
1987 /**
1988 * Get the amount the battery has discharged while the screen was off,
1989 * since the last time the device was charged.
1990 */
1991 public abstract int getDischargeAmountScreenOffSinceCharge();
1992
1993 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 * Returns the total, last, or current battery uptime in microseconds.
1995 *
1996 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001997 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001998 */
1999 public abstract long computeBatteryUptime(long curTime, int which);
2000
2001 /**
2002 * Returns the total, last, or current battery realtime in microseconds.
2003 *
2004 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002005 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002006 */
2007 public abstract long computeBatteryRealtime(long curTime, int which);
2008
2009 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002010 * Returns the total, last, or current battery screen off uptime in microseconds.
2011 *
2012 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002013 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002014 */
2015 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2016
2017 /**
2018 * Returns the total, last, or current battery screen off realtime in microseconds.
2019 *
2020 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002021 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002022 */
2023 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2024
2025 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 * Returns the total, last, or current uptime in microseconds.
2027 *
2028 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002029 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 */
2031 public abstract long computeUptime(long curTime, int which);
2032
2033 /**
2034 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002035 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002037 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 */
2039 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002040
2041 /**
2042 * Compute an approximation for how much run time (in microseconds) is remaining on
2043 * the battery. Returns -1 if no time can be computed: either there is not
2044 * enough current data to make a decision, or the battery is currently
2045 * charging.
2046 *
2047 * @param curTime The current elepsed realtime in microseconds.
2048 */
2049 public abstract long computeBatteryTimeRemaining(long curTime);
2050
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002051 // The part of a step duration that is the actual time.
2052 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2053
2054 // Bits in a step duration that are the new battery level we are at.
2055 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002056 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002057
2058 // Bits in a step duration that are the initial mode we were in at that step.
2059 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002060 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002061
2062 // Bits in a step duration that indicate which modes changed during that step.
2063 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002064 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002065
2066 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2067 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2068
2069 // Step duration mode: power save is on.
2070 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2071
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002072 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2073 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2074 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2075 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2076 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2077 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2078 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2079 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2080 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2081 };
2082 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2083 (Display.STATE_OFF-1),
2084 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
2085 (Display.STATE_ON-1),
2086 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2087 (Display.STATE_DOZE-1),
2088 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2089 (Display.STATE_DOZE_SUSPEND-1),
2090 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
2091 };
2092 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2093 "screen off",
2094 "screen off power save",
2095 "screen on",
2096 "screen on power save",
2097 "screen doze",
2098 "screen doze power save",
2099 "screen doze-suspend",
2100 "screen doze-suspend power save",
2101 };
2102 public static final String[] STEP_LEVEL_MODE_TAGS = new String[] {
2103 "off",
2104 "off-save",
2105 "on",
2106 "on-save",
2107 "doze",
2108 "doze-save",
2109 "susp",
2110 "susp-save",
2111 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002112
2113 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002114 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002115 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002116 public abstract LevelStepTracker getDischargeLevelStepTracker();
2117
2118 /**
2119 * Return the array of daily discharge step durations.
2120 */
2121 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002122
2123 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002124 * Compute an approximation for how much time (in microseconds) remains until the battery
2125 * is fully charged. Returns -1 if no time can be computed: either there is not
2126 * enough current data to make a decision, or the battery is currently
2127 * discharging.
2128 *
2129 * @param curTime The current elepsed realtime in microseconds.
2130 */
2131 public abstract long computeChargeTimeRemaining(long curTime);
2132
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002133 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002134 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002135 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002136 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002137
2138 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002139 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002140 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002141 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002142
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002143 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002144
Evan Millarc64edde2009-04-18 12:26:32 -07002145 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002146
Amith Yamasanie43530a2009-08-21 13:11:37 -07002147 /** Returns the number of different speeds that the CPU can run at */
2148 public abstract int getCpuSpeedSteps();
2149
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002150 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2151
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002152 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153 long days = seconds / (60 * 60 * 24);
2154 if (days != 0) {
2155 out.append(days);
2156 out.append("d ");
2157 }
2158 long used = days * 60 * 60 * 24;
2159
2160 long hours = (seconds - used) / (60 * 60);
2161 if (hours != 0 || used != 0) {
2162 out.append(hours);
2163 out.append("h ");
2164 }
2165 used += hours * 60 * 60;
2166
2167 long mins = (seconds-used) / 60;
2168 if (mins != 0 || used != 0) {
2169 out.append(mins);
2170 out.append("m ");
2171 }
2172 used += mins * 60;
2173
2174 if (seconds != 0 || used != 0) {
2175 out.append(seconds-used);
2176 out.append("s ");
2177 }
2178 }
2179
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002180 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002182 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 sb.append(time - (sec * 1000));
2184 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 }
2186
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002187 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002188 long sec = time / 1000;
2189 formatTimeRaw(sb, sec);
2190 sb.append(time - (sec * 1000));
2191 sb.append("ms");
2192 }
2193
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002194 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002196 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 }
2198 float perc = ((float)num) / ((float)den) * 100;
2199 mFormatBuilder.setLength(0);
2200 mFormatter.format("%.1f%%", perc);
2201 return mFormatBuilder.toString();
2202 }
2203
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002204 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002205 mFormatBuilder.setLength(0);
2206
2207 if (bytes < BYTES_PER_KB) {
2208 return bytes + "B";
2209 } else if (bytes < BYTES_PER_MB) {
2210 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2211 return mFormatBuilder.toString();
2212 } else if (bytes < BYTES_PER_GB){
2213 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2214 return mFormatBuilder.toString();
2215 } else {
2216 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2217 return mFormatBuilder.toString();
2218 }
2219 }
2220
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002221 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002222 if (timer != null) {
2223 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002224 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002225 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2226 return totalTimeMillis;
2227 }
2228 return 0;
2229 }
2230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002231 /**
2232 *
2233 * @param sb a StringBuilder object.
2234 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002235 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002237 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 * @param linePrefix a String to be prepended to each line of output.
2239 * @return the line prefix
2240 */
2241 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002242 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002243
2244 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002245 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246
Evan Millarc64edde2009-04-18 12:26:32 -07002247 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002248 if (totalTimeMillis != 0) {
2249 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002250 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002251 if (name != null) {
2252 sb.append(name);
2253 sb.append(' ');
2254 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 sb.append('(');
2256 sb.append(count);
2257 sb.append(" times)");
2258 return ", ";
2259 }
2260 }
2261 return linePrefix;
2262 }
2263
2264 /**
2265 * Checkin version of wakelock printer. Prints simple comma-separated list.
2266 *
2267 * @param sb a StringBuilder object.
2268 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002269 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002271 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002272 * @param linePrefix a String to be prepended to each line of output.
2273 * @return the line prefix
2274 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002275 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2276 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002277 long totalTimeMicros = 0;
2278 int count = 0;
2279 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002280 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002281 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 }
2283 sb.append(linePrefix);
2284 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2285 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002286 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 sb.append(count);
2288 return ",";
2289 }
2290
2291 /**
2292 * Dump a comma-separated line of values for terse checkin mode.
2293 *
2294 * @param pw the PageWriter to dump log to
2295 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2296 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2297 * @param args type-dependent data arguments
2298 */
2299 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2300 Object... args ) {
2301 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
2302 pw.print(uid); pw.print(',');
2303 pw.print(category); pw.print(',');
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002304 pw.print(type);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305
2306 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002307 pw.print(',');
2308 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002310 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002312
2313 /**
2314 * Temporary for settings.
2315 */
2316 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2317 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2318 }
2319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 /**
2321 * Checkin server version of dump to produce more compact, computer-readable log.
2322 *
2323 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002325 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2326 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2328 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2329 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2331 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002332 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2333 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2334 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 final long totalRealtime = computeRealtime(rawRealtime, which);
2336 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002337 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002338 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002339 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
2340 final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002341 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002342 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
2343 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2344 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
2345 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002347 StringBuilder sb = new StringBuilder(128);
2348
Evan Millar22ac0432009-03-31 11:33:18 -07002349 SparseArray<? extends Uid> uidStats = getUidStats();
2350 final int NU = uidStats.size();
2351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 // Dump "battery" stat
2355 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002356 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002357 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002358 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002359 getStartClockTime(),
2360 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002361
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002362 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002363 long fullWakeLockTimeTotal = 0;
2364 long partialWakeLockTimeTotal = 0;
2365
2366 for (int iu = 0; iu < NU; iu++) {
2367 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002368
Evan Millar22ac0432009-03-31 11:33:18 -07002369 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
2370 if (wakelocks.size() > 0) {
2371 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
2372 : wakelocks.entrySet()) {
2373 Uid.Wakelock wl = ent.getValue();
2374
2375 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2376 if (fullWakeTimer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002377 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2378 which);
Evan Millar22ac0432009-03-31 11:33:18 -07002379 }
2380
2381 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2382 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07002383 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002384 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002385 }
2386 }
2387 }
2388 }
2389
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002390 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2391 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2392 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2393 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2394 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2395 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2396 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2397 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
2398
2399 // Dump network stats
2400 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2401 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
2402 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets);
2403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404 // Dump misc stats
2405 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002406 screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000,
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002407 wifiRunningTime / 1000, bluetoothOnTime / 1000,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002408 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002409 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
2410 0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which) / 1000,
2411 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002412 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeEnabledTime / 1000,
2413 getDeviceIdleModeEnabledCount(which));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002414
2415 // Dump screen brightness stats
2416 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2417 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002418 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002419 }
2420 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002421
Dianne Hackborn627bba72009-03-24 22:32:56 -07002422 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002423 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2424 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002425 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002426 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002427 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002428 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002429 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002430 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002431 args[i] = getPhoneSignalStrengthCount(i, which);
2432 }
2433 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002434
Dianne Hackborn627bba72009-03-24 22:32:56 -07002435 // Dump network type stats
2436 args = new Object[NUM_DATA_CONNECTION_TYPES];
2437 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002438 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002439 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002440 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2441 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2442 args[i] = getPhoneDataConnectionCount(i, which);
2443 }
2444 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002445
2446 // Dump wifi state stats
2447 args = new Object[NUM_WIFI_STATES];
2448 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002449 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002450 }
2451 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2452 for (int i=0; i<NUM_WIFI_STATES; i++) {
2453 args[i] = getWifiStateCount(i, which);
2454 }
2455 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2456
Dianne Hackborn3251b902014-06-20 14:40:53 -07002457 // Dump wifi suppl state stats
2458 args = new Object[NUM_WIFI_SUPPL_STATES];
2459 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2460 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2461 }
2462 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2463 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2464 args[i] = getWifiSupplStateCount(i, which);
2465 }
2466 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
2467
2468 // Dump wifi signal strength stats
2469 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
2470 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2471 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
2472 }
2473 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
2474 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2475 args[i] = getWifiSignalStrengthCount(i, which);
2476 }
2477 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
2478
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002479 // Dump bluetooth state stats
2480 args = new Object[NUM_BLUETOOTH_STATES];
2481 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002482 args[i] = getBluetoothStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002483 }
2484 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_TIME_DATA, args);
2485 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
2486 args[i] = getBluetoothStateCount(i, which);
2487 }
2488 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_COUNT_DATA, args);
2489
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002490 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002491 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07002492 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002495 if (which == STATS_SINCE_UNPLUGGED) {
2496 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2497 getDischargeStartLevel()-getDischargeCurrentLevel(),
2498 getDischargeStartLevel()-getDischargeCurrentLevel(),
2499 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
2500 } else {
2501 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2502 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002503 getDischargeAmountScreenOnSinceCharge(),
2504 getDischargeAmountScreenOffSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002505 }
2506
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002507 if (reqUid < 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002508 Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002509 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002510 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002511 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002512 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002513 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002514 sb.toString());
2515 }
Evan Millarc64edde2009-04-18 12:26:32 -07002516 }
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002517 Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002518 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002519 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
2520 // Not doing the regular wake lock formatting to remain compatible
2521 // with the old checkin format.
2522 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
2523 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002524 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002525 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002526 }
2527 }
Evan Millarc64edde2009-04-18 12:26:32 -07002528 }
2529
Dianne Hackbornd953c532014-08-16 18:17:38 -07002530 BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002531 helper.create(this);
2532 helper.refreshStats(which, UserHandle.USER_ALL);
2533 List<BatterySipper> sippers = helper.getUsageList();
2534 if (sippers != null && sippers.size() > 0) {
2535 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
2536 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08002537 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002538 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
2539 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
2540 for (int i=0; i<sippers.size(); i++) {
2541 BatterySipper bs = sippers.get(i);
2542 int uid = 0;
2543 String label;
2544 switch (bs.drainType) {
2545 case IDLE:
2546 label="idle";
2547 break;
2548 case CELL:
2549 label="cell";
2550 break;
2551 case PHONE:
2552 label="phone";
2553 break;
2554 case WIFI:
2555 label="wifi";
2556 break;
2557 case BLUETOOTH:
2558 label="blue";
2559 break;
2560 case SCREEN:
2561 label="scrn";
2562 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002563 case FLASHLIGHT:
2564 label="flashlight";
2565 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002566 case APP:
2567 uid = bs.uidObj.getUid();
2568 label = "uid";
2569 break;
2570 case USER:
2571 uid = UserHandle.getUid(bs.userId, 0);
2572 label = "user";
2573 break;
2574 case UNACCOUNTED:
2575 label = "unacc";
2576 break;
2577 case OVERCOUNTED:
2578 label = "over";
2579 break;
2580 default:
2581 label = "???";
2582 }
2583 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
2584 BatteryStatsHelper.makemAh(bs.value));
2585 }
2586 }
2587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 for (int iu = 0; iu < NU; iu++) {
2589 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002590 if (reqUid >= 0 && uid != reqUid) {
2591 continue;
2592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 Uid u = uidStats.valueAt(iu);
2594 // Dump Network stats per uid, if any
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002595 long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2596 long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2597 long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2598 long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2599 long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2600 long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002601 long mobileActiveTime = u.getMobileRadioActiveTime(which);
2602 int mobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002603 long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2604 long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002605 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
2606 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07002607 int wifiScanCount = u.getWifiScanCount(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002608 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002609
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002610 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
2611 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002612 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002613 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
2614 wifiBytesRx, wifiBytesTx,
2615 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002616 wifiPacketsRx, wifiPacketsTx,
2617 mobileActiveTime, mobileActiveCount);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002618 }
2619
Dianne Hackborn62793e42015-03-09 11:15:41 -07002620 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07002621 || uidWifiRunningTime != 0) {
Nick Pelly6ccaa542012-06-15 15:22:47 -07002622 dumpLine(pw, uid, category, WIFI_DATA,
Dianne Hackborn62793e42015-03-09 11:15:41 -07002623 fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime, wifiScanCount);
The Android Open Source Project10592532009-03-18 17:39:46 -07002624 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625
Dianne Hackborn617f8772009-03-31 15:04:46 -07002626 if (u.hasUserActivity()) {
2627 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
2628 boolean hasData = false;
2629 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
2630 int val = u.getUserActivityCount(i, which);
2631 args[i] = val;
2632 if (val != 0) hasData = true;
2633 }
2634 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07002635 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002636 }
2637 }
2638
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002639 Map<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002640 if (wakelocks.size() > 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002641 for (Map.Entry<String, ? extends Uid.Wakelock> ent : wakelocks.entrySet()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 Uid.Wakelock wl = ent.getValue();
2643 String linePrefix = "";
2644 sb.setLength(0);
Evan Millarc64edde2009-04-18 12:26:32 -07002645 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002646 rawRealtime, "f", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07002647 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002648 rawRealtime, "p", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07002649 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002650 rawRealtime, "w", which, linePrefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651
2652 // Only log if we had at lease one wakelock...
2653 if (sb.length() > 0) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002654 String name = ent.getKey();
2655 if (name.indexOf(',') >= 0) {
2656 name = name.replace(',', '_');
2657 }
2658 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 }
2660 }
2661 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07002662
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002663 Map<String, ? extends Timer> syncs = u.getSyncStats();
2664 if (syncs.size() > 0) {
2665 for (Map.Entry<String, ? extends Timer> ent : syncs.entrySet()) {
2666 Timer timer = ent.getValue();
2667 // Convert from microseconds to milliseconds with rounding
2668 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2669 int count = timer.getCountLocked(which);
2670 if (totalTime != 0) {
2671 dumpLine(pw, uid, category, SYNC_DATA, ent.getKey(), totalTime, count);
2672 }
2673 }
2674 }
2675
2676 Map<String, ? extends Timer> jobs = u.getJobStats();
2677 if (jobs.size() > 0) {
2678 for (Map.Entry<String, ? extends Timer> ent : jobs.entrySet()) {
2679 Timer timer = ent.getValue();
2680 // Convert from microseconds to milliseconds with rounding
2681 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2682 int count = timer.getCountLocked(which);
2683 if (totalTime != 0) {
2684 dumpLine(pw, uid, category, JOB_DATA, ent.getKey(), totalTime, count);
2685 }
2686 }
2687 }
2688
Dianne Hackborn61659e52014-07-09 16:13:01 -07002689 SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
2690 int NSE = sensors.size();
2691 for (int ise=0; ise<NSE; ise++) {
2692 Uid.Sensor se = sensors.valueAt(ise);
2693 int sensorNumber = sensors.keyAt(ise);
2694 Timer timer = se.getSensorTime();
2695 if (timer != null) {
2696 // Convert from microseconds to milliseconds with rounding
2697 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2698 int count = timer.getCountLocked(which);
2699 if (totalTime != 0) {
2700 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
2701 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 }
2703 }
2704
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002705 Timer vibTimer = u.getVibratorOnTimer();
2706 if (vibTimer != null) {
2707 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002708 long totalTime = (vibTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002709 int count = vibTimer.getCountLocked(which);
2710 if (totalTime != 0) {
2711 dumpLine(pw, uid, category, VIBRATOR_DATA, totalTime, count);
2712 }
2713 }
2714
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002715 Timer fgTimer = u.getForegroundActivityTimer();
2716 if (fgTimer != null) {
2717 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002718 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002719 int count = fgTimer.getCountLocked(which);
2720 if (totalTime != 0) {
2721 dumpLine(pw, uid, category, FOREGROUND_DATA, totalTime, count);
2722 }
2723 }
2724
Dianne Hackborn61659e52014-07-09 16:13:01 -07002725 Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
2726 long totalStateTime = 0;
2727 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
2728 totalStateTime += u.getProcessStateTime(ips, rawRealtime, which);
2729 stateTimes[ips] = (totalStateTime + 500) / 1000;
2730 }
2731 if (totalStateTime > 0) {
2732 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
2733 }
2734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002735 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
2736 if (processStats.size() > 0) {
2737 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
2738 : processStats.entrySet()) {
2739 Uid.Proc ps = ent.getValue();
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002740
Dianne Hackborn62793e42015-03-09 11:15:41 -07002741 final long userMillis = ps.getUserTime(which);
2742 final long systemMillis = ps.getSystemTime(which);
2743 final long foregroundMillis = ps.getForegroundTime(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002744 final int starts = ps.getStarts(which);
2745 final int numCrashes = ps.getNumCrashes(which);
2746 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002747
2748 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002749 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002750 dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis,
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002751 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 }
2753 }
2754 }
2755
2756 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
2757 if (packageStats.size() > 0) {
2758 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
2759 : packageStats.entrySet()) {
2760
2761 Uid.Pkg ps = ent.getValue();
2762 int wakeups = ps.getWakeups(which);
2763 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
2764 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
2765 : serviceStats.entrySet()) {
2766 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
2767 long startTime = ss.getStartTime(batteryUptime, which);
2768 int starts = ss.getStarts(which);
2769 int launches = ss.getLaunches(which);
2770 if (startTime != 0 || starts != 0 || launches != 0) {
2771 dumpLine(pw, uid, category, APK_DATA,
2772 wakeups, // wakeup alarms
2773 ent.getKey(), // Apk
2774 sent.getKey(), // service
2775 startTime / 1000, // time spent started, in ms
2776 starts,
2777 launches);
2778 }
2779 }
2780 }
2781 }
2782 }
2783 }
2784
Dianne Hackborn81038902012-11-26 17:04:09 -08002785 static final class TimerEntry {
2786 final String mName;
2787 final int mId;
2788 final BatteryStats.Timer mTimer;
2789 final long mTime;
2790 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
2791 mName = name;
2792 mId = id;
2793 mTimer = timer;
2794 mTime = time;
2795 }
2796 }
2797
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002798 private void printmAh(PrintWriter printer, double power) {
2799 printer.print(BatteryStatsHelper.makemAh(power));
2800 }
2801
Dianne Hackbornd953c532014-08-16 18:17:38 -07002802 /**
2803 * Temporary for settings.
2804 */
2805 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
2806 int reqUid) {
2807 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2808 }
2809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002811 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07002812 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002813 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2814 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2815 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816
2817 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2818 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
2819 final long totalRealtime = computeRealtime(rawRealtime, which);
2820 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002821 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2822 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2823 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002824 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
2825 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07002828
2829 SparseArray<? extends Uid> uidStats = getUidStats();
2830 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002831
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002832 sb.setLength(0);
2833 sb.append(prefix);
2834 sb.append(" Time on battery: ");
2835 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
2836 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
2837 sb.append(") realtime, ");
2838 formatTimeMs(sb, whichBatteryUptime / 1000);
2839 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
2840 sb.append(") uptime");
2841 pw.println(sb.toString());
2842 sb.setLength(0);
2843 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002844 sb.append(" Time on battery screen off: ");
2845 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
2846 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
2847 sb.append(") realtime, ");
2848 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
2849 sb.append("(");
2850 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
2851 sb.append(") uptime");
2852 pw.println(sb.toString());
2853 sb.setLength(0);
2854 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002855 sb.append(" Total run time: ");
2856 formatTimeMs(sb, totalRealtime / 1000);
2857 sb.append("realtime, ");
2858 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002859 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07002860 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002861 if (batteryTimeRemaining >= 0) {
2862 sb.setLength(0);
2863 sb.append(prefix);
2864 sb.append(" Battery time remaining: ");
2865 formatTimeMs(sb, batteryTimeRemaining / 1000);
2866 pw.println(sb.toString());
2867 }
2868 if (chargeTimeRemaining >= 0) {
2869 sb.setLength(0);
2870 sb.append(prefix);
2871 sb.append(" Charge time remaining: ");
2872 formatTimeMs(sb, chargeTimeRemaining / 1000);
2873 pw.println(sb.toString());
2874 }
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002875 pw.print(" Start clock time: ");
2876 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
2877
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002878 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002879 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002880 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
2881 final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002882 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
2883 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
2884 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2885 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002886 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002887 sb.append(prefix);
2888 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
2889 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002890 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002891 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
2892 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07002893 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002894 pw.println(sb.toString());
2895 sb.setLength(0);
2896 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002897 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002898 boolean didOne = false;
2899 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002900 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002901 if (time == 0) {
2902 continue;
2903 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002904 sb.append("\n ");
2905 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002906 didOne = true;
2907 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
2908 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002909 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002910 sb.append("(");
2911 sb.append(formatRatioLocked(time, screenOnTime));
2912 sb.append(")");
2913 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002914 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002915 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002916 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002917 sb.setLength(0);
2918 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002919 sb.append(" Power save mode enabled: ");
2920 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002921 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002922 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002923 sb.append(")");
2924 pw.println(sb.toString());
2925 }
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002926 if (deviceIdleModeEnabledTime != 0) {
2927 sb.setLength(0);
2928 sb.append(prefix);
2929 sb.append(" Device idling: ");
2930 formatTimeMs(sb, deviceIdleModeEnabledTime / 1000);
2931 sb.append("(");
2932 sb.append(formatRatioLocked(deviceIdleModeEnabledTime, whichBatteryRealtime));
2933 sb.append(") "); sb.append(getDeviceIdleModeEnabledCount(which));
2934 sb.append("x");
2935 pw.println(sb.toString());
2936 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002937 if (phoneOnTime != 0) {
2938 sb.setLength(0);
2939 sb.append(prefix);
2940 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
2941 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002942 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002943 }
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002944 int connChanges = getNumConnectivityChange(which);
2945 if (connChanges != 0) {
2946 pw.print(prefix);
2947 pw.print(" Connectivity changes: "); pw.println(connChanges);
2948 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002949
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002950 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002951 long fullWakeLockTimeTotalMicros = 0;
2952 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08002953
Dianne Hackborn81038902012-11-26 17:04:09 -08002954 final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>();
2955
Evan Millar22ac0432009-03-31 11:33:18 -07002956 for (int iu = 0; iu < NU; iu++) {
2957 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002958
Evan Millar22ac0432009-03-31 11:33:18 -07002959 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
2960 if (wakelocks.size() > 0) {
2961 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
2962 : wakelocks.entrySet()) {
2963 Uid.Wakelock wl = ent.getValue();
2964
2965 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2966 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07002967 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002968 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002969 }
2970
2971 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2972 if (partialWakeTimer != null) {
Dianne Hackborn81038902012-11-26 17:04:09 -08002973 long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002974 rawRealtime, which);
Dianne Hackborn81038902012-11-26 17:04:09 -08002975 if (totalTimeMicros > 0) {
2976 if (reqUid < 0) {
2977 // Only show the ordered list of all wake
2978 // locks if the caller is not asking for data
2979 // about a specific uid.
2980 timers.add(new TimerEntry(ent.getKey(), u.getUid(),
2981 partialWakeTimer, totalTimeMicros));
2982 }
2983 partialWakeLockTimeTotalMicros += totalTimeMicros;
2984 }
Evan Millar22ac0432009-03-31 11:33:18 -07002985 }
2986 }
2987 }
2988 }
2989
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002990 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2991 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2992 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2993 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2994 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2995 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2996 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2997 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
2998
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002999 if (fullWakeLockTimeTotalMicros != 0) {
3000 sb.setLength(0);
3001 sb.append(prefix);
3002 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3003 (fullWakeLockTimeTotalMicros + 500) / 1000);
3004 pw.println(sb.toString());
3005 }
3006
3007 if (partialWakeLockTimeTotalMicros != 0) {
3008 sb.setLength(0);
3009 sb.append(prefix);
3010 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3011 (partialWakeLockTimeTotalMicros + 500) / 1000);
3012 pw.println(sb.toString());
3013 }
3014
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003015 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003016 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3017 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3018 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3019 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003020 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003021 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003022 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003023 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003024 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003025 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003026 if (time == 0) {
3027 continue;
3028 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003029 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003030 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003031 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003032 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003033 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003034 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003035 sb.append("(");
3036 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003037 sb.append(") ");
3038 sb.append(getPhoneSignalStrengthCount(i, which));
3039 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003040 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003041 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003042 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003043
3044 sb.setLength(0);
3045 sb.append(prefix);
3046 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003047 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003048 pw.println(sb.toString());
3049
Dianne Hackborn627bba72009-03-24 22:32:56 -07003050 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003051 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003052 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003053 didOne = false;
3054 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003055 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003056 if (time == 0) {
3057 continue;
3058 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003059 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003060 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003061 didOne = true;
3062 sb.append(DATA_CONNECTION_NAMES[i]);
3063 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003064 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003065 sb.append("(");
3066 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003067 sb.append(") ");
3068 sb.append(getPhoneDataConnectionCount(i, which));
3069 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003070 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003071 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003072 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003073
3074 sb.setLength(0);
3075 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003076 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003077 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003078 formatTimeMs(sb, mobileActiveTime / 1000);
3079 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3080 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3081 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003082 pw.println(sb.toString());
3083
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003084 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3085 if (mobileActiveUnknownTime != 0) {
3086 sb.setLength(0);
3087 sb.append(prefix);
3088 sb.append(" Mobile radio active unknown time: ");
3089 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3090 sb.append("(");
3091 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3092 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3093 sb.append("x");
3094 pw.println(sb.toString());
3095 }
3096
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003097 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3098 if (mobileActiveAdjustedTime != 0) {
3099 sb.setLength(0);
3100 sb.append(prefix);
3101 sb.append(" Mobile radio active adjusted time: ");
3102 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3103 sb.append("(");
3104 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3105 sb.append(")");
3106 pw.println(sb.toString());
3107 }
3108
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003109 pw.print(prefix);
3110 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3111 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3112 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3113 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003114 sb.setLength(0);
3115 sb.append(prefix);
3116 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3117 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3118 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3119 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003120 sb.append(")");
3121 pw.println(sb.toString());
3122
3123 sb.setLength(0);
3124 sb.append(prefix);
3125 sb.append(" Wifi states:");
3126 didOne = false;
3127 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003128 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003129 if (time == 0) {
3130 continue;
3131 }
3132 sb.append("\n ");
3133 didOne = true;
3134 sb.append(WIFI_STATE_NAMES[i]);
3135 sb.append(" ");
3136 formatTimeMs(sb, time/1000);
3137 sb.append("(");
3138 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3139 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003140 sb.append(getWifiStateCount(i, which));
3141 sb.append("x");
3142 }
3143 if (!didOne) sb.append(" (no activity)");
3144 pw.println(sb.toString());
3145
3146 sb.setLength(0);
3147 sb.append(prefix);
3148 sb.append(" Wifi supplicant states:");
3149 didOne = false;
3150 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3151 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3152 if (time == 0) {
3153 continue;
3154 }
3155 sb.append("\n ");
3156 didOne = true;
3157 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3158 sb.append(" ");
3159 formatTimeMs(sb, time/1000);
3160 sb.append("(");
3161 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3162 sb.append(") ");
3163 sb.append(getWifiSupplStateCount(i, which));
3164 sb.append("x");
3165 }
3166 if (!didOne) sb.append(" (no activity)");
3167 pw.println(sb.toString());
3168
3169 sb.setLength(0);
3170 sb.append(prefix);
3171 sb.append(" Wifi signal levels:");
3172 didOne = false;
3173 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3174 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3175 if (time == 0) {
3176 continue;
3177 }
3178 sb.append("\n ");
3179 sb.append(prefix);
3180 didOne = true;
3181 sb.append("level(");
3182 sb.append(i);
3183 sb.append(") ");
3184 formatTimeMs(sb, time/1000);
3185 sb.append("(");
3186 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3187 sb.append(") ");
3188 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003189 sb.append("x");
3190 }
3191 if (!didOne) sb.append(" (no activity)");
3192 pw.println(sb.toString());
3193
Adam Lesinski33dac552015-03-09 15:24:48 -07003194 final long wifiIdleTimeMs = getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which);
3195 final long wifiRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which);
3196 final long wifiTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which);
3197 final long wifiTotalTimeMs = wifiIdleTimeMs + wifiRxTimeMs + wifiTxTimeMs;
3198
3199 sb.setLength(0);
3200 sb.append(prefix);
3201 sb.append(" WiFi Idle time: "); formatTimeMs(sb, wifiIdleTimeMs);
3202 sb.append(" (");
3203 sb.append(formatRatioLocked(wifiIdleTimeMs, wifiTotalTimeMs));
3204 sb.append(")");
3205 pw.println(sb.toString());
3206
3207 sb.setLength(0);
3208 sb.append(prefix);
3209 sb.append(" WiFi Rx time: "); formatTimeMs(sb, wifiRxTimeMs);
3210 sb.append(" (");
3211 sb.append(formatRatioLocked(wifiRxTimeMs, wifiTotalTimeMs));
3212 sb.append(")");
3213 pw.println(sb.toString());
3214
3215 sb.setLength(0);
3216 sb.append(prefix);
3217 sb.append(" WiFi Tx time: "); formatTimeMs(sb, wifiTxTimeMs);
3218 sb.append(" (");
3219 sb.append(formatRatioLocked(wifiTxTimeMs, wifiTotalTimeMs));
3220 sb.append(")");
3221 pw.println(sb.toString());
3222
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003223 sb.setLength(0);
3224 sb.append(prefix);
3225 sb.append(" Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003226 sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime));
3227 sb.append(")");
3228 pw.println(sb.toString());
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003229
3230 sb.setLength(0);
3231 sb.append(prefix);
3232 sb.append(" Bluetooth states:");
3233 didOne = false;
3234 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003235 final long time = getBluetoothStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003236 if (time == 0) {
3237 continue;
3238 }
3239 sb.append("\n ");
3240 didOne = true;
3241 sb.append(BLUETOOTH_STATE_NAMES[i]);
3242 sb.append(" ");
3243 formatTimeMs(sb, time/1000);
3244 sb.append("(");
3245 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3246 sb.append(") ");
3247 sb.append(getPhoneDataConnectionCount(i, which));
3248 sb.append("x");
3249 }
Adam Lesinski33dac552015-03-09 15:24:48 -07003250
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003251 if (!didOne) sb.append(" (no activity)");
3252 pw.println(sb.toString());
3253
Adam Lesinski33dac552015-03-09 15:24:48 -07003254 final long bluetoothIdleTimeMs =
3255 getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which);
3256 final long bluetoothRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which);
3257 final long bluetoothTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which);
3258 final long bluetoothTotalTimeMs = bluetoothIdleTimeMs + bluetoothRxTimeMs +
3259 bluetoothTxTimeMs;
3260
3261 sb.setLength(0);
3262 sb.append(prefix);
3263 sb.append(" Bluetooth Idle time: "); formatTimeMs(sb, bluetoothIdleTimeMs);
3264 sb.append(" (");
3265 sb.append(formatRatioLocked(bluetoothIdleTimeMs, bluetoothTotalTimeMs));
3266 sb.append(")");
3267 pw.println(sb.toString());
3268
3269 sb.setLength(0);
3270 sb.append(prefix);
3271 sb.append(" Bluetooth Rx time: "); formatTimeMs(sb, bluetoothRxTimeMs);
3272 sb.append(" (");
3273 sb.append(formatRatioLocked(bluetoothRxTimeMs, bluetoothTotalTimeMs));
3274 sb.append(")");
3275 pw.println(sb.toString());
3276
3277 sb.setLength(0);
3278 sb.append(prefix);
3279 sb.append(" Bluetooth Tx time: "); formatTimeMs(sb, bluetoothTxTimeMs);
3280 sb.append(" (");
3281 sb.append(formatRatioLocked(bluetoothTxTimeMs, bluetoothTotalTimeMs));
3282 sb.append(")");
3283 pw.println(sb.toString());
3284
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003285 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003286
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003287 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003288 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003289 pw.print(prefix); pw.println(" Device is currently unplugged");
3290 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3291 pw.println(getDischargeStartLevel());
3292 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3293 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003294 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003295 pw.print(prefix); pw.println(" Device is currently plugged into power");
3296 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3297 pw.println(getDischargeStartLevel());
3298 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3299 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003300 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003301 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3302 pw.println(getDischargeAmountScreenOn());
3303 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3304 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003305 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003306 } else {
3307 pw.print(prefix); pw.println(" Device battery use since last full charge");
3308 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3309 pw.println(getLowDischargeAmountSinceCharge());
3310 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3311 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003312 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3313 pw.println(getDischargeAmountScreenOnSinceCharge());
3314 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3315 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003316 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003317 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003318
Dianne Hackbornd953c532014-08-16 18:17:38 -07003319 BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003320 helper.create(this);
3321 helper.refreshStats(which, UserHandle.USER_ALL);
3322 List<BatterySipper> sippers = helper.getUsageList();
3323 if (sippers != null && sippers.size() > 0) {
3324 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3325 pw.print(prefix); pw.print(" Capacity: ");
3326 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003327 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003328 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3329 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3330 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3331 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003332 pw.println();
3333 for (int i=0; i<sippers.size(); i++) {
3334 BatterySipper bs = sippers.get(i);
3335 switch (bs.drainType) {
3336 case IDLE:
3337 pw.print(prefix); pw.print(" Idle: "); printmAh(pw, bs.value);
3338 pw.println();
3339 break;
3340 case CELL:
3341 pw.print(prefix); pw.print(" Cell standby: "); printmAh(pw, bs.value);
3342 pw.println();
3343 break;
3344 case PHONE:
3345 pw.print(prefix); pw.print(" Phone calls: "); printmAh(pw, bs.value);
3346 pw.println();
3347 break;
3348 case WIFI:
3349 pw.print(prefix); pw.print(" Wifi: "); printmAh(pw, bs.value);
3350 pw.println();
3351 break;
3352 case BLUETOOTH:
3353 pw.print(prefix); pw.print(" Bluetooth: "); printmAh(pw, bs.value);
3354 pw.println();
3355 break;
3356 case SCREEN:
3357 pw.print(prefix); pw.print(" Screen: "); printmAh(pw, bs.value);
3358 pw.println();
3359 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003360 case FLASHLIGHT:
3361 pw.print(prefix); pw.print(" Flashlight: "); printmAh(pw, bs.value);
3362 pw.println();
3363 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003364 case APP:
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003365 pw.print(prefix); pw.print(" Uid ");
3366 UserHandle.formatUid(pw, bs.uidObj.getUid());
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003367 pw.print(": "); printmAh(pw, bs.value); pw.println();
3368 break;
3369 case USER:
3370 pw.print(prefix); pw.print(" User "); pw.print(bs.userId);
3371 pw.print(": "); printmAh(pw, bs.value); pw.println();
3372 break;
3373 case UNACCOUNTED:
3374 pw.print(prefix); pw.print(" Unaccounted: "); printmAh(pw, bs.value);
3375 pw.println();
3376 break;
3377 case OVERCOUNTED:
3378 pw.print(prefix); pw.print(" Over-counted: "); printmAh(pw, bs.value);
3379 pw.println();
3380 break;
3381 }
3382 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08003383 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003384 }
3385
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003386 sippers = helper.getMobilemsppList();
3387 if (sippers != null && sippers.size() > 0) {
3388 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003389 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003390 for (int i=0; i<sippers.size(); i++) {
3391 BatterySipper bs = sippers.get(i);
3392 sb.setLength(0);
3393 sb.append(prefix); sb.append(" Uid ");
3394 UserHandle.formatUid(sb, bs.uidObj.getUid());
3395 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
3396 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
3397 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003398 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003399 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003400 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003401 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003402 sb.setLength(0);
3403 sb.append(prefix);
3404 sb.append(" TOTAL TIME: ");
3405 formatTimeMs(sb, totalTime);
3406 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
3407 sb.append(")");
3408 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003409 pw.println();
3410 }
3411
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003412 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
3413 @Override
3414 public int compare(TimerEntry lhs, TimerEntry rhs) {
3415 long lhsTime = lhs.mTime;
3416 long rhsTime = rhs.mTime;
3417 if (lhsTime < rhsTime) {
3418 return 1;
3419 }
3420 if (lhsTime > rhsTime) {
3421 return -1;
3422 }
3423 return 0;
3424 }
3425 };
3426
3427 if (reqUid < 0) {
3428 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
3429 if (kernelWakelocks.size() > 0) {
3430 final ArrayList<TimerEntry> ktimers = new ArrayList<TimerEntry>();
3431 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
3432 BatteryStats.Timer timer = ent.getValue();
3433 long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
3434 if (totalTimeMillis > 0) {
3435 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
3436 }
3437 }
3438 if (ktimers.size() > 0) {
3439 Collections.sort(ktimers, timerComparator);
3440 pw.print(prefix); pw.println(" All kernel wake locks:");
3441 for (int i=0; i<ktimers.size(); i++) {
3442 TimerEntry timer = ktimers.get(i);
3443 String linePrefix = ": ";
3444 sb.setLength(0);
3445 sb.append(prefix);
3446 sb.append(" Kernel Wake lock ");
3447 sb.append(timer.mName);
3448 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
3449 which, linePrefix);
3450 if (!linePrefix.equals(": ")) {
3451 sb.append(" realtime");
3452 // Only print out wake locks that were held
3453 pw.println(sb.toString());
3454 }
3455 }
3456 pw.println();
3457 }
3458 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003459
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003460 if (timers.size() > 0) {
3461 Collections.sort(timers, timerComparator);
3462 pw.print(prefix); pw.println(" All partial wake locks:");
3463 for (int i=0; i<timers.size(); i++) {
3464 TimerEntry timer = timers.get(i);
3465 sb.setLength(0);
3466 sb.append(" Wake lock ");
3467 UserHandle.formatUid(sb, timer.mId);
3468 sb.append(" ");
3469 sb.append(timer.mName);
3470 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3471 sb.append(" realtime");
3472 pw.println(sb.toString());
3473 }
3474 timers.clear();
3475 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08003476 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003477
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003478 Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003479 if (wakeupReasons.size() > 0) {
3480 pw.print(prefix); pw.println(" All wakeup reasons:");
3481 final ArrayList<TimerEntry> reasons = new ArrayList<TimerEntry>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003482 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3483 Timer timer = ent.getValue();
3484 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
3485 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003486 }
3487 Collections.sort(reasons, timerComparator);
3488 for (int i=0; i<reasons.size(); i++) {
3489 TimerEntry timer = reasons.get(i);
3490 String linePrefix = ": ";
3491 sb.setLength(0);
3492 sb.append(prefix);
3493 sb.append(" Wakeup reason ");
3494 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003495 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3496 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003497 pw.println(sb.toString());
3498 }
3499 pw.println();
3500 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003501 }
Evan Millar22ac0432009-03-31 11:33:18 -07003502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003503 for (int iu=0; iu<NU; iu++) {
3504 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08003505 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003506 continue;
3507 }
3508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003509 Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07003510
3511 pw.print(prefix);
3512 pw.print(" ");
3513 UserHandle.formatUid(pw, uid);
3514 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003516
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003517 long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3518 long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3519 long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3520 long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3521 long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3522 long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003523 long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
3524 int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003525 long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3526 long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003527 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3528 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003529 int wifiScanCount = u.getWifiScanCount(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003530 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003531
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003532 if (mobileRxBytes > 0 || mobileTxBytes > 0
3533 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003534 pw.print(prefix); pw.print(" Mobile network: ");
3535 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003536 pw.print(formatBytesLocked(mobileTxBytes));
3537 pw.print(" sent (packets "); pw.print(mobileRxPackets);
3538 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003539 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003540 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
3541 sb.setLength(0);
3542 sb.append(prefix); sb.append(" Mobile radio active: ");
3543 formatTimeMs(sb, uidMobileActiveTime / 1000);
3544 sb.append("(");
3545 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
3546 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
3547 long packets = mobileRxPackets + mobileTxPackets;
3548 if (packets == 0) {
3549 packets = 1;
3550 }
3551 sb.append(" @ ");
3552 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
3553 sb.append(" mspp");
3554 pw.println(sb.toString());
3555 }
3556
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003557 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003558 pw.print(prefix); pw.print(" Wi-Fi network: ");
3559 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003560 pw.print(formatBytesLocked(wifiTxBytes));
3561 pw.print(" sent (packets "); pw.print(wifiRxPackets);
3562 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003563 }
3564
Dianne Hackborn62793e42015-03-09 11:15:41 -07003565 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003566 || uidWifiRunningTime != 0) {
3567 sb.setLength(0);
3568 sb.append(prefix); sb.append(" Wifi Running: ");
3569 formatTimeMs(sb, uidWifiRunningTime / 1000);
3570 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
3571 whichBatteryRealtime)); sb.append(")\n");
3572 sb.append(prefix); sb.append(" Full Wifi Lock: ");
3573 formatTimeMs(sb, fullWifiLockOnTime / 1000);
3574 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
3575 whichBatteryRealtime)); sb.append(")\n");
3576 sb.append(prefix); sb.append(" Wifi Scan: ");
3577 formatTimeMs(sb, wifiScanTime / 1000);
3578 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07003579 whichBatteryRealtime)); sb.append(") ");
3580 sb.append(wifiScanCount);
3581 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003582 pw.println(sb.toString());
3583 }
3584
Dianne Hackborn617f8772009-03-31 15:04:46 -07003585 if (u.hasUserActivity()) {
3586 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07003587 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003588 int val = u.getUserActivityCount(i, which);
3589 if (val != 0) {
3590 if (!hasData) {
3591 sb.setLength(0);
3592 sb.append(" User activity: ");
3593 hasData = true;
3594 } else {
3595 sb.append(", ");
3596 }
3597 sb.append(val);
3598 sb.append(" ");
3599 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
3600 }
3601 }
3602 if (hasData) {
3603 pw.println(sb.toString());
3604 }
3605 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606
3607 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
3608 if (wakelocks.size() > 0) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003609 long totalFull = 0, totalPartial = 0, totalWindow = 0;
3610 int count = 0;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003611 for (Map.Entry<String, ? extends Uid.Wakelock> ent : wakelocks.entrySet()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003612 Uid.Wakelock wl = ent.getValue();
3613 String linePrefix = ": ";
3614 sb.setLength(0);
3615 sb.append(prefix);
3616 sb.append(" Wake lock ");
3617 sb.append(ent.getKey());
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003618 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003619 "full", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003620 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003621 "partial", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003622 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623 "window", which, linePrefix);
Dianne Hackbornacc4a122014-08-18 16:33:44 -07003624 if (true || !linePrefix.equals(": ")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05003626 // Only print out wake locks that were held
3627 pw.println(sb.toString());
3628 uidActivity = true;
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003629 count++;
3630 }
3631 totalFull += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003632 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003633 totalPartial += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003634 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003635 totalWindow += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003636 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003637 }
3638 if (count > 1) {
3639 if (totalFull != 0 || totalPartial != 0 || totalWindow != 0) {
3640 sb.setLength(0);
3641 sb.append(prefix);
3642 sb.append(" TOTAL wake: ");
3643 boolean needComma = false;
3644 if (totalFull != 0) {
3645 needComma = true;
3646 formatTimeMs(sb, totalFull);
3647 sb.append("full");
3648 }
3649 if (totalPartial != 0) {
3650 if (needComma) {
3651 sb.append(", ");
3652 }
3653 needComma = true;
3654 formatTimeMs(sb, totalPartial);
3655 sb.append("partial");
3656 }
3657 if (totalWindow != 0) {
3658 if (needComma) {
3659 sb.append(", ");
3660 }
3661 needComma = true;
3662 formatTimeMs(sb, totalWindow);
3663 sb.append("window");
3664 }
3665 sb.append(" realtime");
3666 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 }
3669 }
3670
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003671 Map<String, ? extends Timer> syncs = u.getSyncStats();
3672 if (syncs.size() > 0) {
3673 for (Map.Entry<String, ? extends Timer> ent : syncs.entrySet()) {
3674 Timer timer = ent.getValue();
3675 // Convert from microseconds to milliseconds with rounding
3676 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3677 int count = timer.getCountLocked(which);
3678 sb.setLength(0);
3679 sb.append(prefix);
3680 sb.append(" Sync ");
3681 sb.append(ent.getKey());
3682 sb.append(": ");
3683 if (totalTime != 0) {
3684 formatTimeMs(sb, totalTime);
3685 sb.append("realtime (");
3686 sb.append(count);
3687 sb.append(" times)");
3688 } else {
3689 sb.append("(not used)");
3690 }
3691 pw.println(sb.toString());
3692 uidActivity = true;
3693 }
3694 }
3695
3696 Map<String, ? extends Timer> jobs = u.getJobStats();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003697 if (jobs.size() > 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003698 for (Map.Entry<String, ? extends Timer> ent : jobs.entrySet()) {
3699 Timer timer = ent.getValue();
3700 // Convert from microseconds to milliseconds with rounding
3701 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3702 int count = timer.getCountLocked(which);
3703 sb.setLength(0);
3704 sb.append(prefix);
3705 sb.append(" Job ");
3706 sb.append(ent.getKey());
3707 sb.append(": ");
3708 if (totalTime != 0) {
3709 formatTimeMs(sb, totalTime);
3710 sb.append("realtime (");
3711 sb.append(count);
3712 sb.append(" times)");
3713 } else {
3714 sb.append("(not used)");
3715 }
3716 pw.println(sb.toString());
3717 uidActivity = true;
3718 }
3719 }
3720
Dianne Hackborn61659e52014-07-09 16:13:01 -07003721 SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3722 int NSE = sensors.size();
3723 for (int ise=0; ise<NSE; ise++) {
3724 Uid.Sensor se = sensors.valueAt(ise);
3725 int sensorNumber = sensors.keyAt(ise);
3726 sb.setLength(0);
3727 sb.append(prefix);
3728 sb.append(" Sensor ");
3729 int handle = se.getHandle();
3730 if (handle == Uid.Sensor.GPS) {
3731 sb.append("GPS");
3732 } else {
3733 sb.append(handle);
3734 }
3735 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736
Dianne Hackborn61659e52014-07-09 16:13:01 -07003737 Timer timer = se.getSensorTime();
3738 if (timer != null) {
3739 // Convert from microseconds to milliseconds with rounding
3740 long totalTime = (timer.getTotalTimeLocked(
3741 rawRealtime, which) + 500) / 1000;
3742 int count = timer.getCountLocked(which);
3743 //timer.logState();
3744 if (totalTime != 0) {
3745 formatTimeMs(sb, totalTime);
3746 sb.append("realtime (");
3747 sb.append(count);
3748 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749 } else {
3750 sb.append("(not used)");
3751 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003752 } else {
3753 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003755
3756 pw.println(sb.toString());
3757 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 }
3759
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003760 Timer vibTimer = u.getVibratorOnTimer();
3761 if (vibTimer != null) {
3762 // Convert from microseconds to milliseconds with rounding
3763 long totalTime = (vibTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003764 rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003765 int count = vibTimer.getCountLocked(which);
3766 //timer.logState();
3767 if (totalTime != 0) {
3768 sb.setLength(0);
3769 sb.append(prefix);
3770 sb.append(" Vibrator: ");
3771 formatTimeMs(sb, totalTime);
3772 sb.append("realtime (");
3773 sb.append(count);
3774 sb.append(" times)");
3775 pw.println(sb.toString());
3776 uidActivity = true;
3777 }
3778 }
3779
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003780 Timer fgTimer = u.getForegroundActivityTimer();
3781 if (fgTimer != null) {
3782 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003783 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003784 int count = fgTimer.getCountLocked(which);
3785 if (totalTime != 0) {
3786 sb.setLength(0);
3787 sb.append(prefix);
3788 sb.append(" Foreground activities: ");
3789 formatTimeMs(sb, totalTime);
3790 sb.append("realtime (");
3791 sb.append(count);
3792 sb.append(" times)");
3793 pw.println(sb.toString());
3794 uidActivity = true;
3795 }
3796 }
3797
Dianne Hackborn61659e52014-07-09 16:13:01 -07003798 long totalStateTime = 0;
3799 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
3800 long time = u.getProcessStateTime(ips, rawRealtime, which);
3801 if (time > 0) {
3802 totalStateTime += time;
3803 sb.setLength(0);
3804 sb.append(prefix);
3805 sb.append(" ");
3806 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
3807 sb.append(" for: ");
3808 formatTimeMs(sb, (totalStateTime + 500) / 1000);
3809 pw.println(sb.toString());
3810 uidActivity = true;
3811 }
3812 }
3813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003814 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
3815 if (processStats.size() > 0) {
3816 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
3817 : processStats.entrySet()) {
3818 Uid.Proc ps = ent.getValue();
3819 long userTime;
3820 long systemTime;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003821 long foregroundTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003822 int starts;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003823 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824
3825 userTime = ps.getUserTime(which);
3826 systemTime = ps.getSystemTime(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003827 foregroundTime = ps.getForegroundTime(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003828 starts = ps.getStarts(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003829 final int numCrashes = ps.getNumCrashes(which);
3830 final int numAnrs = ps.getNumAnrs(which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003831 numExcessive = which == STATS_SINCE_CHARGED
Dianne Hackborn287952c2010-09-22 22:34:31 -07003832 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003834 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003835 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003836 sb.setLength(0);
3837 sb.append(prefix); sb.append(" Proc ");
3838 sb.append(ent.getKey()); sb.append(":\n");
3839 sb.append(prefix); sb.append(" CPU: ");
Dianne Hackborn62793e42015-03-09 11:15:41 -07003840 formatTimeMs(sb, userTime); sb.append("usr + ");
3841 formatTimeMs(sb, systemTime); sb.append("krn ; ");
3842 formatTimeMs(sb, foregroundTime); sb.append("fg");
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003843 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
Dianne Hackbornb8071d792010-09-09 16:45:15 -07003844 sb.append("\n"); sb.append(prefix); sb.append(" ");
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003845 boolean hasOne = false;
3846 if (starts != 0) {
3847 hasOne = true;
3848 sb.append(starts); sb.append(" starts");
3849 }
3850 if (numCrashes != 0) {
3851 if (hasOne) {
3852 sb.append(", ");
3853 }
3854 hasOne = true;
3855 sb.append(numCrashes); sb.append(" crashes");
3856 }
3857 if (numAnrs != 0) {
3858 if (hasOne) {
3859 sb.append(", ");
3860 }
3861 sb.append(numAnrs); sb.append(" anrs");
3862 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -07003863 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003864 pw.println(sb.toString());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003865 for (int e=0; e<numExcessive; e++) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07003866 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003867 if (ew != null) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07003868 pw.print(prefix); pw.print(" * Killed for ");
3869 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
3870 pw.print("wake lock");
3871 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
3872 pw.print("cpu");
3873 } else {
3874 pw.print("unknown");
3875 }
3876 pw.print(" use: ");
Dianne Hackborn1ebccf52010-08-15 13:04:34 -07003877 TimeUtils.formatDuration(ew.usedTime, pw);
3878 pw.print(" over ");
3879 TimeUtils.formatDuration(ew.overTime, pw);
Robert Greenwalta029ea12013-09-25 16:38:12 -07003880 if (ew.overTime != 0) {
3881 pw.print(" (");
3882 pw.print((ew.usedTime*100)/ew.overTime);
3883 pw.println("%)");
3884 }
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003885 }
3886 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003887 uidActivity = true;
3888 }
3889 }
3890 }
3891
3892 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
3893 if (packageStats.size() > 0) {
3894 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
3895 : packageStats.entrySet()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003896 pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003897 boolean apkActivity = false;
3898 Uid.Pkg ps = ent.getValue();
3899 int wakeups = ps.getWakeups(which);
3900 if (wakeups != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003901 pw.print(prefix); pw.print(" ");
3902 pw.print(wakeups); pw.println(" wakeup alarms");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003903 apkActivity = true;
3904 }
3905 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3906 if (serviceStats.size() > 0) {
3907 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
3908 : serviceStats.entrySet()) {
3909 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
3910 long startTime = ss.getStartTime(batteryUptime, which);
3911 int starts = ss.getStarts(which);
3912 int launches = ss.getLaunches(which);
3913 if (startTime != 0 || starts != 0 || launches != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003914 sb.setLength(0);
3915 sb.append(prefix); sb.append(" Service ");
3916 sb.append(sent.getKey()); sb.append(":\n");
3917 sb.append(prefix); sb.append(" Created for: ");
3918 formatTimeMs(sb, startTime / 1000);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003919 sb.append("uptime\n");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003920 sb.append(prefix); sb.append(" Starts: ");
3921 sb.append(starts);
3922 sb.append(", launches: "); sb.append(launches);
3923 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003924 apkActivity = true;
3925 }
3926 }
3927 }
3928 if (!apkActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003929 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 }
3931 uidActivity = true;
3932 }
3933 }
3934 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003935 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003936 }
3937 }
3938 }
3939
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003940 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003941 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003942 int diff = oldval ^ newval;
3943 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003944 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003945 for (int i=0; i<descriptions.length; i++) {
3946 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003947 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003948 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003949 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003950 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003951 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003952 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
3953 didWake = true;
3954 pw.print("=");
3955 if (longNames) {
3956 UserHandle.formatUid(pw, wakelockTag.uid);
3957 pw.print(":\"");
3958 pw.print(wakelockTag.string);
3959 pw.print("\"");
3960 } else {
3961 pw.print(wakelockTag.poolIdx);
3962 }
3963 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003964 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003965 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003966 pw.print("=");
3967 int val = (newval&bd.mask)>>bd.shift;
3968 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003969 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003970 } else {
3971 pw.print(val);
3972 }
3973 }
3974 }
3975 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003976 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07003977 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003978 if (longNames) {
3979 UserHandle.formatUid(pw, wakelockTag.uid);
3980 pw.print(":\"");
3981 pw.print(wakelockTag.string);
3982 pw.print("\"");
3983 } else {
3984 pw.print(wakelockTag.poolIdx);
3985 }
3986 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003987 }
3988
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003989 public void prepareForDumpLocked() {
3990 }
3991
3992 public static class HistoryPrinter {
3993 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003994 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003995 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003996 int oldStatus = -1;
3997 int oldHealth = -1;
3998 int oldPlug = -1;
3999 int oldTemp = -1;
4000 int oldVolt = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004001 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004002
Dianne Hackborn3251b902014-06-20 14:40:53 -07004003 void reset() {
4004 oldState = oldState2 = 0;
4005 oldLevel = -1;
4006 oldStatus = -1;
4007 oldHealth = -1;
4008 oldPlug = -1;
4009 oldTemp = -1;
4010 oldVolt = -1;
4011 }
4012
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004013 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004014 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004015 if (!checkin) {
4016 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004017 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004018 pw.print(" (");
4019 pw.print(rec.numReadInts);
4020 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004021 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004022 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4023 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004024 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004025 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004026 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004027 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004028 }
4029 lastTime = rec.time;
4030 }
4031 if (rec.cmd == HistoryItem.CMD_START) {
4032 if (checkin) {
4033 pw.print(":");
4034 }
4035 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004036 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004037 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4038 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004039 if (checkin) {
4040 pw.print(":");
4041 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004042 if (rec.cmd == HistoryItem.CMD_RESET) {
4043 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004044 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004045 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004046 pw.print("TIME:");
4047 if (checkin) {
4048 pw.println(rec.currentTime);
4049 } else {
4050 pw.print(" ");
4051 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4052 rec.currentTime).toString());
4053 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004054 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4055 if (checkin) {
4056 pw.print(":");
4057 }
4058 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004059 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4060 if (checkin) {
4061 pw.print(":");
4062 }
4063 pw.println("*OVERFLOW*");
4064 } else {
4065 if (!checkin) {
4066 if (rec.batteryLevel < 10) pw.print("00");
4067 else if (rec.batteryLevel < 100) pw.print("0");
4068 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004069 if (verbose) {
4070 pw.print(" ");
4071 if (rec.states < 0) ;
4072 else if (rec.states < 0x10) pw.print("0000000");
4073 else if (rec.states < 0x100) pw.print("000000");
4074 else if (rec.states < 0x1000) pw.print("00000");
4075 else if (rec.states < 0x10000) pw.print("0000");
4076 else if (rec.states < 0x100000) pw.print("000");
4077 else if (rec.states < 0x1000000) pw.print("00");
4078 else if (rec.states < 0x10000000) pw.print("0");
4079 pw.print(Integer.toHexString(rec.states));
4080 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004081 } else {
4082 if (oldLevel != rec.batteryLevel) {
4083 oldLevel = rec.batteryLevel;
4084 pw.print(",Bl="); pw.print(rec.batteryLevel);
4085 }
4086 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004087 if (oldStatus != rec.batteryStatus) {
4088 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004089 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004090 switch (oldStatus) {
4091 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004092 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004093 break;
4094 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004095 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004096 break;
4097 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004098 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004099 break;
4100 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004101 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004102 break;
4103 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004104 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004105 break;
4106 default:
4107 pw.print(oldStatus);
4108 break;
4109 }
4110 }
4111 if (oldHealth != rec.batteryHealth) {
4112 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004113 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004114 switch (oldHealth) {
4115 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004116 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004117 break;
4118 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004119 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004120 break;
4121 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004122 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004123 break;
4124 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004125 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004126 break;
4127 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004128 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004129 break;
4130 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004131 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004132 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004133 case BatteryManager.BATTERY_HEALTH_COLD:
4134 pw.print(checkin ? "c" : "cold");
4135 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004136 default:
4137 pw.print(oldHealth);
4138 break;
4139 }
4140 }
4141 if (oldPlug != rec.batteryPlugType) {
4142 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004143 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004144 switch (oldPlug) {
4145 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004146 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004147 break;
4148 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004149 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004150 break;
4151 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004152 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004153 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004154 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004155 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004156 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004157 default:
4158 pw.print(oldPlug);
4159 break;
4160 }
4161 }
4162 if (oldTemp != rec.batteryTemperature) {
4163 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004164 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004165 pw.print(oldTemp);
4166 }
4167 if (oldVolt != rec.batteryVoltage) {
4168 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004169 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004170 pw.print(oldVolt);
4171 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004172 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004173 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004174 printBitDescriptions(pw, oldState2, rec.states2, null,
4175 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004176 if (rec.wakeReasonTag != null) {
4177 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004178 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004179 pw.print(rec.wakeReasonTag.poolIdx);
4180 } else {
4181 pw.print(" wake_reason=");
4182 pw.print(rec.wakeReasonTag.uid);
4183 pw.print(":\"");
4184 pw.print(rec.wakeReasonTag.string);
4185 pw.print("\"");
4186 }
4187 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004188 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004189 pw.print(checkin ? "," : " ");
4190 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4191 pw.print("+");
4192 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4193 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004194 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004195 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4196 : HISTORY_EVENT_NAMES;
4197 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4198 | HistoryItem.EVENT_FLAG_FINISH);
4199 if (idx >= 0 && idx < eventNames.length) {
4200 pw.print(eventNames[idx]);
4201 } else {
4202 pw.print(checkin ? "Ev" : "event");
4203 pw.print(idx);
4204 }
4205 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004206 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004207 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004208 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004209 UserHandle.formatUid(pw, rec.eventTag.uid);
4210 pw.print(":\"");
4211 pw.print(rec.eventTag.string);
4212 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004213 }
4214 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004215 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004216 if (rec.stepDetails != null) {
4217 if (!checkin) {
4218 pw.print(" Details: cpu=");
4219 pw.print(rec.stepDetails.userTime);
4220 pw.print("u+");
4221 pw.print(rec.stepDetails.systemTime);
4222 pw.print("s");
4223 if (rec.stepDetails.appCpuUid1 >= 0) {
4224 pw.print(" (");
4225 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4226 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4227 if (rec.stepDetails.appCpuUid2 >= 0) {
4228 pw.print(", ");
4229 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4230 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4231 }
4232 if (rec.stepDetails.appCpuUid3 >= 0) {
4233 pw.print(", ");
4234 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4235 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4236 }
4237 pw.print(')');
4238 }
4239 pw.println();
4240 pw.print(" /proc/stat=");
4241 pw.print(rec.stepDetails.statUserTime);
4242 pw.print(" usr, ");
4243 pw.print(rec.stepDetails.statSystemTime);
4244 pw.print(" sys, ");
4245 pw.print(rec.stepDetails.statIOWaitTime);
4246 pw.print(" io, ");
4247 pw.print(rec.stepDetails.statIrqTime);
4248 pw.print(" irq, ");
4249 pw.print(rec.stepDetails.statSoftIrqTime);
4250 pw.print(" sirq, ");
4251 pw.print(rec.stepDetails.statIdlTime);
4252 pw.print(" idle");
4253 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4254 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4255 + rec.stepDetails.statSoftIrqTime;
4256 int total = totalRun + rec.stepDetails.statIdlTime;
4257 if (total > 0) {
4258 pw.print(" (");
4259 float perc = ((float)totalRun) / ((float)total) * 100;
4260 pw.print(String.format("%.1f%%", perc));
4261 pw.print(" of ");
4262 StringBuilder sb = new StringBuilder(64);
4263 formatTimeMsNoSpace(sb, total*10);
4264 pw.print(sb);
4265 pw.print(")");
4266 }
4267 pw.println();
4268 } else {
4269 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4270 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4271 pw.print(rec.stepDetails.userTime);
4272 pw.print(":");
4273 pw.print(rec.stepDetails.systemTime);
4274 if (rec.stepDetails.appCpuUid1 >= 0) {
4275 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4276 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4277 if (rec.stepDetails.appCpuUid2 >= 0) {
4278 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4279 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4280 }
4281 if (rec.stepDetails.appCpuUid3 >= 0) {
4282 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4283 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4284 }
4285 }
4286 pw.println();
4287 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4288 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4289 pw.print(rec.stepDetails.statUserTime);
4290 pw.print(',');
4291 pw.print(rec.stepDetails.statSystemTime);
4292 pw.print(',');
4293 pw.print(rec.stepDetails.statIOWaitTime);
4294 pw.print(',');
4295 pw.print(rec.stepDetails.statIrqTime);
4296 pw.print(',');
4297 pw.print(rec.stepDetails.statSoftIrqTime);
4298 pw.print(',');
4299 pw.print(rec.stepDetails.statIdlTime);
4300 pw.println();
4301 }
4302 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004303 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004304 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004305 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004306 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004307
4308 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4309 UserHandle.formatUid(pw, uid);
4310 pw.print("=");
4311 pw.print(utime);
4312 pw.print("u+");
4313 pw.print(stime);
4314 pw.print("s");
4315 }
4316
4317 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
4318 pw.print('/');
4319 pw.print(uid);
4320 pw.print(":");
4321 pw.print(utime);
4322 pw.print(":");
4323 pw.print(stime);
4324 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004325 }
4326
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004327 private void printSizeValue(PrintWriter pw, long size) {
4328 float result = size;
4329 String suffix = "";
4330 if (result >= 10*1024) {
4331 suffix = "KB";
4332 result = result / 1024;
4333 }
4334 if (result >= 10*1024) {
4335 suffix = "MB";
4336 result = result / 1024;
4337 }
4338 if (result >= 10*1024) {
4339 suffix = "GB";
4340 result = result / 1024;
4341 }
4342 if (result >= 10*1024) {
4343 suffix = "TB";
4344 result = result / 1024;
4345 }
4346 if (result >= 10*1024) {
4347 suffix = "PB";
4348 result = result / 1024;
4349 }
4350 pw.print((int)result);
4351 pw.print(suffix);
4352 }
4353
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004354 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
4355 String label3, long estimatedTime) {
4356 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004357 return false;
4358 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004359 pw.print(label1);
4360 pw.print(label2);
4361 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004362 StringBuilder sb = new StringBuilder(64);
4363 formatTimeMs(sb, estimatedTime);
4364 pw.print(sb);
4365 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004366 return true;
4367 }
4368
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004369 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
4370 LevelStepTracker steps, boolean checkin) {
4371 if (steps == null) {
4372 return false;
4373 }
4374 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004375 if (count <= 0) {
4376 return false;
4377 }
4378 if (!checkin) {
4379 pw.println(header);
4380 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004381 String[] lineArgs = new String[4];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004382 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004383 long duration = steps.getDurationAt(i);
4384 int level = steps.getLevelAt(i);
4385 long initMode = steps.getInitModeAt(i);
4386 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004387 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004388 lineArgs[0] = Long.toString(duration);
4389 lineArgs[1] = Integer.toString(level);
4390 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4391 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4392 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
4393 case Display.STATE_ON: lineArgs[2] = "s+"; break;
4394 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
4395 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
4396 default: lineArgs[1] = "?"; break;
4397 }
4398 } else {
4399 lineArgs[2] = "";
4400 }
4401 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4402 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
4403 } else {
4404 lineArgs[3] = "";
4405 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004406 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
4407 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004408 pw.print(prefix);
4409 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004410 TimeUtils.formatDuration(duration, pw);
4411 pw.print(" to "); pw.print(level);
4412 boolean haveModes = false;
4413 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4414 pw.print(" (");
4415 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4416 case Display.STATE_OFF: pw.print("screen-off"); break;
4417 case Display.STATE_ON: pw.print("screen-on"); break;
4418 case Display.STATE_DOZE: pw.print("screen-doze"); break;
4419 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
4420 default: lineArgs[1] = "screen-?"; break;
4421 }
4422 haveModes = true;
4423 }
4424 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4425 pw.print(haveModes ? ", " : " (");
4426 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
4427 ? "power-save-on" : "power-save-off");
4428 haveModes = true;
4429 }
4430 if (haveModes) {
4431 pw.print(")");
4432 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004433 pw.println();
4434 }
4435 }
4436 return true;
4437 }
4438
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004439 public static final int DUMP_UNPLUGGED_ONLY = 1<<0;
4440 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004441 public static final int DUMP_DAILY_ONLY = 1<<2;
4442 public static final int DUMP_HISTORY_ONLY = 1<<3;
4443 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
4444 public static final int DUMP_VERBOSE = 1<<5;
4445 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004446
Dianne Hackborn37de0982014-05-09 09:32:18 -07004447 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
4448 final HistoryPrinter hprinter = new HistoryPrinter();
4449 final HistoryItem rec = new HistoryItem();
4450 long lastTime = -1;
4451 long baseTime = -1;
4452 boolean printed = false;
4453 HistoryEventTracker tracker = null;
4454 while (getNextHistoryLocked(rec)) {
4455 lastTime = rec.time;
4456 if (baseTime < 0) {
4457 baseTime = lastTime;
4458 }
4459 if (rec.time >= histStart) {
4460 if (histStart >= 0 && !printed) {
4461 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07004462 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004463 || rec.cmd == HistoryItem.CMD_START
4464 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004465 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004466 hprinter.printNextItem(pw, rec, baseTime, checkin,
4467 (flags&DUMP_VERBOSE) != 0);
4468 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004469 } else if (rec.currentTime != 0) {
4470 printed = true;
4471 byte cmd = rec.cmd;
4472 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004473 hprinter.printNextItem(pw, rec, baseTime, checkin,
4474 (flags&DUMP_VERBOSE) != 0);
4475 rec.cmd = cmd;
4476 }
4477 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004478 if (rec.cmd != HistoryItem.CMD_UPDATE) {
4479 hprinter.printNextItem(pw, rec, baseTime, checkin,
4480 (flags&DUMP_VERBOSE) != 0);
4481 rec.cmd = HistoryItem.CMD_UPDATE;
4482 }
4483 int oldEventCode = rec.eventCode;
4484 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004485 rec.eventTag = new HistoryTag();
4486 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
4487 HashMap<String, SparseIntArray> active
4488 = tracker.getStateForEvent(i);
4489 if (active == null) {
4490 continue;
4491 }
4492 for (HashMap.Entry<String, SparseIntArray> ent
4493 : active.entrySet()) {
4494 SparseIntArray uids = ent.getValue();
4495 for (int j=0; j<uids.size(); j++) {
4496 rec.eventCode = i;
4497 rec.eventTag.string = ent.getKey();
4498 rec.eventTag.uid = uids.keyAt(j);
4499 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07004500 hprinter.printNextItem(pw, rec, baseTime, checkin,
4501 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004502 rec.wakeReasonTag = null;
4503 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004504 }
4505 }
4506 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004507 rec.eventCode = oldEventCode;
4508 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004509 tracker = null;
4510 }
4511 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004512 hprinter.printNextItem(pw, rec, baseTime, checkin,
4513 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07004514 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
4515 // This is an attempt to aggregate the previous state and generate
4516 // fake events to reflect that state at the point where we start
4517 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07004518 if (tracker == null) {
4519 tracker = new HistoryEventTracker();
4520 }
4521 tracker.updateState(rec.eventCode, rec.eventTag.string,
4522 rec.eventTag.uid, rec.eventTag.poolIdx);
4523 }
4524 }
4525 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07004526 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004527 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
4528 }
4529 }
4530
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004531 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
4532 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
4533 if (steps == null) {
4534 return;
4535 }
4536 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
4537 if (timeRemaining >= 0) {
4538 pw.print(prefix); pw.print(label); pw.print(" total time: ");
4539 tmpSb.setLength(0);
4540 formatTimeMs(tmpSb, timeRemaining);
4541 pw.print(tmpSb);
4542 pw.print(" (from "); pw.print(tmpOutInt[0]);
4543 pw.println(" steps)");
4544 }
4545 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
4546 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
4547 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
4548 if (estimatedTime > 0) {
4549 pw.print(prefix); pw.print(label); pw.print(" ");
4550 pw.print(STEP_LEVEL_MODE_LABELS[i]);
4551 pw.print(" time: ");
4552 tmpSb.setLength(0);
4553 formatTimeMs(tmpSb, estimatedTime);
4554 pw.print(tmpSb);
4555 pw.print(" (from "); pw.print(tmpOutInt[0]);
4556 pw.println(" steps)");
4557 }
4558 }
4559 }
4560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004561 /**
4562 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
4563 *
4564 * @param pw a Printer to receive the dump output.
4565 */
4566 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004567 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004568 prepareForDumpLocked();
4569
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004570 final boolean filtering = (flags
4571 & (DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004572
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004573 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004574 final long historyTotalSize = getHistoryTotalSize();
4575 final long historyUsedSize = getHistoryUsedSize();
4576 if (startIteratingHistoryLocked()) {
4577 try {
4578 pw.print("Battery History (");
4579 pw.print((100*historyUsedSize)/historyTotalSize);
4580 pw.print("% used, ");
4581 printSizeValue(pw, historyUsedSize);
4582 pw.print(" used of ");
4583 printSizeValue(pw, historyTotalSize);
4584 pw.print(", ");
4585 pw.print(getHistoryStringPoolSize());
4586 pw.print(" strings using ");
4587 printSizeValue(pw, getHistoryStringPoolBytes());
4588 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07004589 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004590 pw.println();
4591 } finally {
4592 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004593 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004594 }
4595
4596 if (startIteratingOldHistoryLocked()) {
4597 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004598 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004599 pw.println("Old battery History:");
4600 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004601 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004602 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004603 if (baseTime < 0) {
4604 baseTime = rec.time;
4605 }
4606 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004607 }
4608 pw.println();
4609 } finally {
4610 finishIteratingOldHistoryLocked();
4611 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07004612 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004613 }
4614
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004615 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08004616 return;
4617 }
4618
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004619 if (!filtering) {
4620 SparseArray<? extends Uid> uidStats = getUidStats();
4621 final int NU = uidStats.size();
4622 boolean didPid = false;
4623 long nowRealtime = SystemClock.elapsedRealtime();
4624 for (int i=0; i<NU; i++) {
4625 Uid uid = uidStats.valueAt(i);
4626 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
4627 if (pids != null) {
4628 for (int j=0; j<pids.size(); j++) {
4629 Uid.Pid pid = pids.valueAt(j);
4630 if (!didPid) {
4631 pw.println("Per-PID Stats:");
4632 didPid = true;
4633 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004634 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
4635 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004636 pw.print(" PID "); pw.print(pids.keyAt(j));
4637 pw.print(" wake time: ");
4638 TimeUtils.formatDuration(time, pw);
4639 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004640 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004641 }
4642 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004643 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004644 pw.println();
4645 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004646 }
4647
4648 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004649 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
4650 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004651 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
4652 if (timeRemaining >= 0) {
4653 pw.print(" Estimated discharge time remaining: ");
4654 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4655 pw.println();
4656 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004657 final LevelStepTracker steps = getDischargeLevelStepTracker();
4658 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
4659 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
4660 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
4661 STEP_LEVEL_MODE_VALUES[i], null));
4662 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004663 pw.println();
4664 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004665 if (dumpDurationSteps(pw, " ", "Charge step durations:",
4666 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004667 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
4668 if (timeRemaining >= 0) {
4669 pw.print(" Estimated charge time remaining: ");
4670 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4671 pw.println();
4672 }
4673 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004674 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004675 }
4676 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
4677 pw.println("Daily stats:");
4678 pw.print(" Current start time: ");
4679 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4680 getCurrentDailyStartTime()).toString());
4681 pw.print(" Next min deadline: ");
4682 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4683 getNextMinDailyDeadline()).toString());
4684 pw.print(" Next max deadline: ");
4685 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4686 getNextMaxDailyDeadline()).toString());
4687 StringBuilder sb = new StringBuilder(64);
4688 int[] outInt = new int[1];
4689 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
4690 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
4691 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0) {
4692 if ((flags&DUMP_DAILY_ONLY) != 0) {
4693 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
4694 dsteps, false)) {
4695 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
4696 sb, outInt);
4697 }
4698 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
4699 csteps, false)) {
4700 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
4701 sb, outInt);
4702 }
4703 } else {
4704 pw.println(" Current daily steps:");
4705 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
4706 sb, outInt);
4707 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
4708 sb, outInt);
4709 }
4710 }
4711 DailyItem dit;
4712 int curIndex = 0;
4713 while ((dit=getDailyItemLocked(curIndex)) != null) {
4714 curIndex++;
4715 if ((flags&DUMP_DAILY_ONLY) != 0) {
4716 pw.println();
4717 }
4718 pw.print(" Daily from ");
4719 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
4720 pw.print(" to ");
4721 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
4722 pw.println(":");
4723 if ((flags&DUMP_DAILY_ONLY) != 0) {
4724 if (dumpDurationSteps(pw, " ",
4725 " Discharge step durations:", dit.mDischargeSteps, false)) {
4726 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
4727 sb, outInt);
4728 }
4729 if (dumpDurationSteps(pw, " ",
4730 " Charge step durations:", dit.mChargeSteps, false)) {
4731 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
4732 sb, outInt);
4733 }
4734 } else {
4735 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
4736 sb, outInt);
4737 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
4738 sb, outInt);
4739 }
4740 }
4741 pw.println();
4742 }
4743 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004744 pw.println("Statistics since last charge:");
4745 pw.println(" System starts: " + getStartCount()
4746 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07004747 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
4748 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004749 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004750 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004751 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
4752 pw.println("Statistics since last unplugged:");
Dianne Hackbornd953c532014-08-16 18:17:38 -07004753 dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid,
4754 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004755 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004756 }
4757
4758 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004759 public void dumpCheckinLocked(Context context, PrintWriter pw,
4760 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004761 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004762
4763 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004764 "13", getParcelVersion(), getStartPlatformVersion(), getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004765
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004766 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
4767
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004768 final boolean filtering = (flags &
4769 (DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004770
4771 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07004772 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004773 try {
4774 for (int i=0; i<getHistoryStringPoolSize(); i++) {
4775 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4776 pw.print(HISTORY_STRING_POOL); pw.print(',');
4777 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004778 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004779 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004780 pw.print(",\"");
4781 String str = getHistoryTagPoolString(i);
4782 str = str.replace("\\", "\\\\");
4783 str = str.replace("\"", "\\\"");
4784 pw.print(str);
4785 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004786 pw.println();
4787 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004788 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004789 } finally {
4790 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08004791 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004792 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004793 }
4794
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004795 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08004796 return;
4797 }
4798
Dianne Hackborne4a59512010-12-07 11:08:07 -08004799 if (apps != null) {
4800 SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
4801 for (int i=0; i<apps.size(); i++) {
4802 ApplicationInfo ai = apps.get(i);
4803 ArrayList<String> pkgs = uids.get(ai.uid);
4804 if (pkgs == null) {
4805 pkgs = new ArrayList<String>();
4806 uids.put(ai.uid, pkgs);
4807 }
4808 pkgs.add(ai.packageName);
4809 }
4810 SparseArray<? extends Uid> uidStats = getUidStats();
4811 final int NU = uidStats.size();
4812 String[] lineArgs = new String[2];
4813 for (int i=0; i<NU; i++) {
4814 int uid = uidStats.keyAt(i);
4815 ArrayList<String> pkgs = uids.get(uid);
4816 if (pkgs != null) {
4817 for (int j=0; j<pkgs.size(); j++) {
4818 lineArgs[0] = Integer.toString(uid);
4819 lineArgs[1] = pkgs.get(j);
4820 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
4821 (Object[])lineArgs);
4822 }
4823 }
4824 }
4825 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004826 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004827 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004828 String[] lineArgs = new String[1];
4829 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
4830 if (timeRemaining >= 0) {
4831 lineArgs[0] = Long.toString(timeRemaining);
4832 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
4833 (Object[])lineArgs);
4834 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004835 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004836 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
4837 if (timeRemaining >= 0) {
4838 lineArgs[0] = Long.toString(timeRemaining);
4839 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
4840 (Object[])lineArgs);
4841 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07004842 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
4843 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004844 }
4845 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
Dianne Hackbornd953c532014-08-16 18:17:38 -07004846 dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1,
4847 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 }
4849 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850}