blob: 26e6b85041fc39cab0c25558420dbbeb2e447dfe [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 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700616 if ((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
617 out.append('i');
618 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800619 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
620 case Display.STATE_OFF: out.append('F'); break;
621 case Display.STATE_ON: out.append('O'); break;
622 case Display.STATE_DOZE: out.append('D'); break;
623 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
624 }
625 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
626 out.append('P');
627 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700628 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0) {
629 out.append('I');
630 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800631 out.append('-');
632 appendHex(level, 4, out);
633 out.append('-');
634 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
635 }
636
637 public void decodeEntryAt(int index, String value) {
638 final int N = value.length();
639 int i = 0;
640 char c;
641 long out = 0;
642 while (i < N && (c=value.charAt(i)) != '-') {
643 i++;
644 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800645 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800646 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800647 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800648 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800649 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800650 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800651 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
652 << STEP_LEVEL_INITIAL_MODE_SHIFT);
653 break;
654 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
655 << STEP_LEVEL_INITIAL_MODE_SHIFT);
656 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700657 case 'i': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
658 << STEP_LEVEL_INITIAL_MODE_SHIFT);
659 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800660 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
661 break;
662 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
663 break;
664 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
665 break;
666 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
667 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
668 break;
669 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
670 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800671 break;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700672 case 'I': out |= (((long)STEP_LEVEL_MODE_DEVICE_IDLE)
673 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
674 break;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800675 }
676 }
677 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800678 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800679 while (i < N && (c=value.charAt(i)) != '-') {
680 i++;
681 level <<= 4;
682 if (c >= '0' && c <= '9') {
683 level += c - '0';
684 } else if (c >= 'a' && c <= 'f') {
685 level += c - 'a' + 10;
686 } else if (c >= 'A' && c <= 'F') {
687 level += c - 'A' + 10;
688 }
689 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800690 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800691 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
692 long duration = 0;
693 while (i < N && (c=value.charAt(i)) != '-') {
694 i++;
695 duration <<= 4;
696 if (c >= '0' && c <= '9') {
697 duration += c - '0';
698 } else if (c >= 'a' && c <= 'f') {
699 duration += c - 'a' + 10;
700 } else if (c >= 'A' && c <= 'F') {
701 duration += c - 'A' + 10;
702 }
703 }
704 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
705 }
706
707 public void init() {
708 mLastStepTime = -1;
709 mNumStepDurations = 0;
710 }
711
712 public void clearTime() {
713 mLastStepTime = -1;
714 }
715
716 public long computeTimePerLevel() {
717 final long[] steps = mStepDurations;
718 final int numSteps = mNumStepDurations;
719
720 // For now we'll do a simple average across all steps.
721 if (numSteps <= 0) {
722 return -1;
723 }
724 long total = 0;
725 for (int i=0; i<numSteps; i++) {
726 total += steps[i] & STEP_LEVEL_TIME_MASK;
727 }
728 return total / numSteps;
729 /*
730 long[] buckets = new long[numSteps];
731 int numBuckets = 0;
732 int numToAverage = 4;
733 int i = 0;
734 while (i < numSteps) {
735 long totalTime = 0;
736 int num = 0;
737 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
738 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
739 num++;
740 }
741 buckets[numBuckets] = totalTime / num;
742 numBuckets++;
743 numToAverage *= 2;
744 i += num;
745 }
746 if (numBuckets < 1) {
747 return -1;
748 }
749 long averageTime = buckets[numBuckets-1];
750 for (i=numBuckets-2; i>=0; i--) {
751 averageTime = (averageTime + buckets[i]) / 2;
752 }
753 return averageTime;
754 */
755 }
756
757 public long computeTimeEstimate(long modesOfInterest, long modeValues,
758 int[] outNumOfInterest) {
759 final long[] steps = mStepDurations;
760 final int count = mNumStepDurations;
761 if (count <= 0) {
762 return -1;
763 }
764 long total = 0;
765 int numOfInterest = 0;
766 for (int i=0; i<count; i++) {
767 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
768 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
769 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
770 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
771 // If the modes of interest didn't change during this step period...
772 if ((modMode&modesOfInterest) == 0) {
773 // And the mode values during this period match those we are measuring...
774 if ((initMode&modesOfInterest) == modeValues) {
775 // Then this can be used to estimate the total time!
776 numOfInterest++;
777 total += steps[i] & STEP_LEVEL_TIME_MASK;
778 }
779 }
780 }
781 if (numOfInterest <= 0) {
782 return -1;
783 }
784
785 if (outNumOfInterest != null) {
786 outNumOfInterest[0] = numOfInterest;
787 }
788
789 // The estimated time is the average time we spend in each level, multipled
790 // by 100 -- the total number of battery levels
791 return (total / numOfInterest) * 100;
792 }
793
794 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
795 int stepCount = mNumStepDurations;
796 final long lastStepTime = mLastStepTime;
797 if (lastStepTime >= 0 && numStepLevels > 0) {
798 final long[] steps = mStepDurations;
799 long duration = elapsedRealtime - lastStepTime;
800 for (int i=0; i<numStepLevels; i++) {
801 System.arraycopy(steps, 0, steps, 1, steps.length-1);
802 long thisDuration = duration / (numStepLevels-i);
803 duration -= thisDuration;
804 if (thisDuration > STEP_LEVEL_TIME_MASK) {
805 thisDuration = STEP_LEVEL_TIME_MASK;
806 }
807 steps[0] = thisDuration | modeBits;
808 }
809 stepCount += numStepLevels;
810 if (stepCount > steps.length) {
811 stepCount = steps.length;
812 }
813 }
814 mNumStepDurations = stepCount;
815 mLastStepTime = elapsedRealtime;
816 }
817
818 public void readFromParcel(Parcel in) {
819 final int N = in.readInt();
820 mNumStepDurations = N;
821 for (int i=0; i<N; i++) {
822 mStepDurations[i] = in.readLong();
823 }
824 }
825
826 public void writeToParcel(Parcel out) {
827 final int N = mNumStepDurations;
828 out.writeInt(N);
829 for (int i=0; i<N; i++) {
830 out.writeLong(mStepDurations[i]);
831 }
832 }
833 }
834
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700835 public static final class PackageChange {
836 public String mPackageName;
837 public boolean mUpdate;
838 public int mVersionCode;
839 }
840
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800841 public static final class DailyItem {
842 public long mStartTime;
843 public long mEndTime;
844 public LevelStepTracker mDischargeSteps;
845 public LevelStepTracker mChargeSteps;
Dianne Hackborn88e98df2015-03-23 13:29:14 -0700846 public ArrayList<PackageChange> mPackageChanges;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800847 }
848
849 public abstract DailyItem getDailyItemLocked(int daysAgo);
850
851 public abstract long getCurrentDailyStartTime();
852
853 public abstract long getNextMinDailyDeadline();
854
855 public abstract long getNextMaxDailyDeadline();
856
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800857 public final static class HistoryTag {
858 public String string;
859 public int uid;
860
861 public int poolIdx;
862
863 public void setTo(HistoryTag o) {
864 string = o.string;
865 uid = o.uid;
866 poolIdx = o.poolIdx;
867 }
868
869 public void setTo(String _string, int _uid) {
870 string = _string;
871 uid = _uid;
872 poolIdx = -1;
873 }
874
875 public void writeToParcel(Parcel dest, int flags) {
876 dest.writeString(string);
877 dest.writeInt(uid);
878 }
879
880 public void readFromParcel(Parcel src) {
881 string = src.readString();
882 uid = src.readInt();
883 poolIdx = -1;
884 }
885
886 @Override
887 public boolean equals(Object o) {
888 if (this == o) return true;
889 if (o == null || getClass() != o.getClass()) return false;
890
891 HistoryTag that = (HistoryTag) o;
892
893 if (uid != that.uid) return false;
894 if (!string.equals(that.string)) return false;
895
896 return true;
897 }
898
899 @Override
900 public int hashCode() {
901 int result = string.hashCode();
902 result = 31 * result + uid;
903 return result;
904 }
905 }
906
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -0800907 /**
908 * Optional detailed information that can go into a history step. This is typically
909 * generated each time the battery level changes.
910 */
911 public final static class HistoryStepDetails {
912 // Time (in 1/100 second) spent in user space and the kernel since the last step.
913 public int userTime;
914 public int systemTime;
915
916 // Top three apps using CPU in the last step, with times in 1/100 second.
917 public int appCpuUid1;
918 public int appCpuUTime1;
919 public int appCpuSTime1;
920 public int appCpuUid2;
921 public int appCpuUTime2;
922 public int appCpuSTime2;
923 public int appCpuUid3;
924 public int appCpuUTime3;
925 public int appCpuSTime3;
926
927 // Information from /proc/stat
928 public int statUserTime;
929 public int statSystemTime;
930 public int statIOWaitTime;
931 public int statIrqTime;
932 public int statSoftIrqTime;
933 public int statIdlTime;
934
935 public HistoryStepDetails() {
936 clear();
937 }
938
939 public void clear() {
940 userTime = systemTime = 0;
941 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
942 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
943 = appCpuUTime3 = appCpuSTime3 = 0;
944 }
945
946 public void writeToParcel(Parcel out) {
947 out.writeInt(userTime);
948 out.writeInt(systemTime);
949 out.writeInt(appCpuUid1);
950 out.writeInt(appCpuUTime1);
951 out.writeInt(appCpuSTime1);
952 out.writeInt(appCpuUid2);
953 out.writeInt(appCpuUTime2);
954 out.writeInt(appCpuSTime2);
955 out.writeInt(appCpuUid3);
956 out.writeInt(appCpuUTime3);
957 out.writeInt(appCpuSTime3);
958 out.writeInt(statUserTime);
959 out.writeInt(statSystemTime);
960 out.writeInt(statIOWaitTime);
961 out.writeInt(statIrqTime);
962 out.writeInt(statSoftIrqTime);
963 out.writeInt(statIdlTime);
964 }
965
966 public void readFromParcel(Parcel in) {
967 userTime = in.readInt();
968 systemTime = in.readInt();
969 appCpuUid1 = in.readInt();
970 appCpuUTime1 = in.readInt();
971 appCpuSTime1 = in.readInt();
972 appCpuUid2 = in.readInt();
973 appCpuUTime2 = in.readInt();
974 appCpuSTime2 = in.readInt();
975 appCpuUid3 = in.readInt();
976 appCpuUTime3 = in.readInt();
977 appCpuSTime3 = in.readInt();
978 statUserTime = in.readInt();
979 statSystemTime = in.readInt();
980 statIOWaitTime = in.readInt();
981 statIrqTime = in.readInt();
982 statSoftIrqTime = in.readInt();
983 statIdlTime = in.readInt();
984 }
985 }
986
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700987 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700988 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -0700989
990 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700991 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800992
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800993 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800994 public static final byte CMD_NULL = -1;
995 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800996 public static final byte CMD_CURRENT_TIME = 5;
997 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -0700998 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -0800999 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001000
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001001 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001002
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001003 /**
1004 * Return whether the command code is a delta data update.
1005 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001006 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001007 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001008 }
1009
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001010 public byte batteryLevel;
1011 public byte batteryStatus;
1012 public byte batteryHealth;
1013 public byte batteryPlugType;
1014
Sungmin Choic7e9e8b2013-01-16 12:57:36 +09001015 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001016 public char batteryVoltage;
1017
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001018 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001019 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001020 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001021 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001022 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1023 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001024 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001025 public static final int STATE_PHONE_STATE_SHIFT = 6;
1026 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001027 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001028 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001029 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001030
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001031 // These states always appear directly in the first int token
1032 // of a delta change; they should be ones that change relatively
1033 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001034 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1035 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001036 public static final int STATE_GPS_ON_FLAG = 1<<29;
1037 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001038 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001039 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001040 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001041 // These are on the lower bits used for the command; if they change
1042 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001043 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001044 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001045 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001046 public static final int STATE_SCREEN_ON_FLAG = 1<<20;
1047 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19;
1048 public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001049 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001050
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001051 public static final int MOST_INTERESTING_STATES =
1052 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
Dianne Hackborn3251b902014-06-20 14:40:53 -07001053 | STATE_PHONE_IN_CALL_FLAG | STATE_BLUETOOTH_ON_FLAG;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001054
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001055 public int states;
1056
Dianne Hackborn3251b902014-06-20 14:40:53 -07001057 // Constants from WIFI_SUPPL_STATE_*
1058 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1059 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1060 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1061 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1062 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1063 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1064
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001065 public static final int STATE2_POWER_SAVE_FLAG = 1<<31;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001066 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1067 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1068 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001069 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001070 public static final int STATE2_DEVICE_IDLE_FLAG = 1<<26;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001071
1072 public static final int MOST_INTERESTING_STATES2 =
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001073 STATE2_POWER_SAVE_FLAG | STATE2_WIFI_ON_FLAG | STATE2_DEVICE_IDLE_FLAG;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001074
Dianne Hackborn40c87252014-03-19 16:55:40 -07001075 public int states2;
1076
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001077 // The wake lock that was acquired at this point.
1078 public HistoryTag wakelockTag;
1079
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001080 // Kernel wakeup reason at this point.
1081 public HistoryTag wakeReasonTag;
1082
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001083 // Non-null when there is more detailed information at this step.
1084 public HistoryStepDetails stepDetails;
1085
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001086 public static final int EVENT_FLAG_START = 0x8000;
1087 public static final int EVENT_FLAG_FINISH = 0x4000;
1088
1089 // No event in this item.
1090 public static final int EVENT_NONE = 0x0000;
1091 // Event is about a process that is running.
1092 public static final int EVENT_PROC = 0x0001;
1093 // Event is about an application package that is in the foreground.
1094 public static final int EVENT_FOREGROUND = 0x0002;
1095 // Event is about an application package that is at the top of the screen.
1096 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001097 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001098 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001099 // Events for all additional wake locks aquired/release within a wake block.
1100 // These are not generated by default.
1101 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001102 // Event is about an application executing a scheduled job.
1103 public static final int EVENT_JOB = 0x0006;
1104 // Events for users running.
1105 public static final int EVENT_USER_RUNNING = 0x0007;
1106 // Events for foreground user.
1107 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001108 // Event for connectivity changed.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001109 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001110 // Event for significant motion taking us out of idle mode.
1111 public static final int EVENT_SIGNIFICANT_MOTION = 0x000a;
1112 // Event for becoming active taking us out of idle mode.
1113 public static final int EVENT_ACTIVE = 0x000b;
1114 // Event for a package being installed.
1115 public static final int EVENT_PACKAGE_INSTALLED = 0x000c;
1116 // Event for a package being uninstalled.
1117 public static final int EVENT_PACKAGE_UNINSTALLED = 0x000d;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001118 // Number of event types.
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001119 public static final int EVENT_COUNT = 0x000e;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001120 // Mask to extract out only the type part of the event.
1121 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001122
1123 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1124 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1125 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1126 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1127 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1128 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001129 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1130 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001131 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1132 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001133 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1134 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1135 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1136 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1137 public static final int EVENT_USER_FOREGROUND_START =
1138 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1139 public static final int EVENT_USER_FOREGROUND_FINISH =
1140 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001141
1142 // For CMD_EVENT.
1143 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001144 public HistoryTag eventTag;
1145
Dianne Hackborn9a755432014-05-15 17:05:22 -07001146 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001147 public long currentTime;
1148
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001149 // Meta-data when reading.
1150 public int numReadInts;
1151
1152 // Pre-allocated objects.
1153 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001154 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001155 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001156
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001157 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001158 }
1159
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001160 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001161 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001162 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001163 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001164 }
1165
1166 public int describeContents() {
1167 return 0;
1168 }
1169
1170 public void writeToParcel(Parcel dest, int flags) {
1171 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001172 int bat = (((int)cmd)&0xff)
1173 | ((((int)batteryLevel)<<8)&0xff00)
1174 | ((((int)batteryStatus)<<16)&0xf0000)
1175 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001176 | ((((int)batteryPlugType)<<24)&0xf000000)
1177 | (wakelockTag != null ? 0x10000000 : 0)
1178 | (wakeReasonTag != null ? 0x20000000 : 0)
1179 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001180 dest.writeInt(bat);
1181 bat = (((int)batteryTemperature)&0xffff)
1182 | ((((int)batteryVoltage)<<16)&0xffff0000);
1183 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001184 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001185 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001186 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001187 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001188 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001189 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001190 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001191 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001192 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001193 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001194 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001195 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001196 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001197 dest.writeLong(currentTime);
1198 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001199 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001200
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001201 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001202 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001203 int bat = src.readInt();
1204 cmd = (byte)(bat&0xff);
1205 batteryLevel = (byte)((bat>>8)&0xff);
1206 batteryStatus = (byte)((bat>>16)&0xf);
1207 batteryHealth = (byte)((bat>>20)&0xf);
1208 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001209 int bat2 = src.readInt();
1210 batteryTemperature = (short)(bat2&0xffff);
1211 batteryVoltage = (char)((bat2>>16)&0xffff);
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001212 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001213 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001214 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001215 wakelockTag = localWakelockTag;
1216 wakelockTag.readFromParcel(src);
1217 } else {
1218 wakelockTag = null;
1219 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001220 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001221 wakeReasonTag = localWakeReasonTag;
1222 wakeReasonTag.readFromParcel(src);
1223 } else {
1224 wakeReasonTag = null;
1225 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001226 if ((bat&0x40000000) != 0) {
1227 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001228 eventTag = localEventTag;
1229 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001230 } else {
1231 eventCode = EVENT_NONE;
1232 eventTag = null;
1233 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001234 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001235 currentTime = src.readLong();
1236 } else {
1237 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001238 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001239 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001240 }
1241
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001242 public void clear() {
1243 time = 0;
1244 cmd = CMD_NULL;
1245 batteryLevel = 0;
1246 batteryStatus = 0;
1247 batteryHealth = 0;
1248 batteryPlugType = 0;
1249 batteryTemperature = 0;
1250 batteryVoltage = 0;
1251 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001252 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001253 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001254 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001255 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001256 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001257 }
1258
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001259 public void setTo(HistoryItem o) {
1260 time = o.time;
1261 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001262 setToCommon(o);
1263 }
1264
1265 public void setTo(long time, byte cmd, HistoryItem o) {
1266 this.time = time;
1267 this.cmd = cmd;
1268 setToCommon(o);
1269 }
1270
1271 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001272 batteryLevel = o.batteryLevel;
1273 batteryStatus = o.batteryStatus;
1274 batteryHealth = o.batteryHealth;
1275 batteryPlugType = o.batteryPlugType;
1276 batteryTemperature = o.batteryTemperature;
1277 batteryVoltage = o.batteryVoltage;
1278 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001279 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001280 if (o.wakelockTag != null) {
1281 wakelockTag = localWakelockTag;
1282 wakelockTag.setTo(o.wakelockTag);
1283 } else {
1284 wakelockTag = null;
1285 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001286 if (o.wakeReasonTag != null) {
1287 wakeReasonTag = localWakeReasonTag;
1288 wakeReasonTag.setTo(o.wakeReasonTag);
1289 } else {
1290 wakeReasonTag = null;
1291 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001292 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001293 if (o.eventTag != null) {
1294 eventTag = localEventTag;
1295 eventTag.setTo(o.eventTag);
1296 } else {
1297 eventTag = null;
1298 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001299 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001300 }
1301
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001302 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001303 return batteryLevel == o.batteryLevel
1304 && batteryStatus == o.batteryStatus
1305 && batteryHealth == o.batteryHealth
1306 && batteryPlugType == o.batteryPlugType
1307 && batteryTemperature == o.batteryTemperature
1308 && batteryVoltage == o.batteryVoltage
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001309 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001310 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001311 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001312 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001313
1314 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001315 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001316 return false;
1317 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001318 if (wakelockTag != o.wakelockTag) {
1319 if (wakelockTag == null || o.wakelockTag == null) {
1320 return false;
1321 }
1322 if (!wakelockTag.equals(o.wakelockTag)) {
1323 return false;
1324 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001325 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001326 if (wakeReasonTag != o.wakeReasonTag) {
1327 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1328 return false;
1329 }
1330 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1331 return false;
1332 }
1333 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001334 if (eventTag != o.eventTag) {
1335 if (eventTag == null || o.eventTag == null) {
1336 return false;
1337 }
1338 if (!eventTag.equals(o.eventTag)) {
1339 return false;
1340 }
1341 }
1342 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001343 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001344 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001345
1346 public final static class HistoryEventTracker {
1347 private final HashMap<String, SparseIntArray>[] mActiveEvents
1348 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1349
1350 public boolean updateState(int code, String name, int uid, int poolIdx) {
1351 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1352 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1353 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1354 if (active == null) {
1355 active = new HashMap<String, SparseIntArray>();
1356 mActiveEvents[idx] = active;
1357 }
1358 SparseIntArray uids = active.get(name);
1359 if (uids == null) {
1360 uids = new SparseIntArray();
1361 active.put(name, uids);
1362 }
1363 if (uids.indexOfKey(uid) >= 0) {
1364 // Already set, nothing to do!
1365 return false;
1366 }
1367 uids.put(uid, poolIdx);
1368 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1369 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1370 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1371 if (active == null) {
1372 // not currently active, nothing to do.
1373 return false;
1374 }
1375 SparseIntArray uids = active.get(name);
1376 if (uids == null) {
1377 // not currently active, nothing to do.
1378 return false;
1379 }
1380 idx = uids.indexOfKey(uid);
1381 if (idx < 0) {
1382 // not currently active, nothing to do.
1383 return false;
1384 }
1385 uids.removeAt(idx);
1386 if (uids.size() <= 0) {
1387 active.remove(name);
1388 }
1389 }
1390 return true;
1391 }
1392
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001393 public void removeEvents(int code) {
1394 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1395 mActiveEvents[idx] = null;
1396 }
1397
Dianne Hackborn37de0982014-05-09 09:32:18 -07001398 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1399 return mActiveEvents[code];
1400 }
1401 }
1402
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001403 public static final class BitDescription {
1404 public final int mask;
1405 public final int shift;
1406 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001407 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001408 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001409 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001410
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001411 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001412 this.mask = mask;
1413 this.shift = -1;
1414 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001415 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001416 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001417 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001418 }
1419
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001420 public BitDescription(int mask, int shift, String name, String shortName,
1421 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001422 this.mask = mask;
1423 this.shift = shift;
1424 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001425 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001426 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001427 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001428 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001429 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001430
Dianne Hackbornfc064132014-06-02 12:42:12 -07001431 /**
1432 * Don't allow any more batching in to the current history event. This
1433 * is called when printing partial histories, so to ensure that the next
1434 * history event will go in to a new batch after what was printed in the
1435 * last partial history.
1436 */
1437 public abstract void commitCurrentHistoryBatchLocked();
1438
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001439 public abstract int getHistoryTotalSize();
1440
1441 public abstract int getHistoryUsedSize();
1442
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001443 public abstract boolean startIteratingHistoryLocked();
1444
Dianne Hackborn099bc622014-01-22 13:39:16 -08001445 public abstract int getHistoryStringPoolSize();
1446
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001447 public abstract int getHistoryStringPoolBytes();
1448
1449 public abstract String getHistoryTagPoolString(int index);
1450
1451 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001452
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001453 public abstract boolean getNextHistoryLocked(HistoryItem out);
1454
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001455 public abstract void finishIteratingHistoryLocked();
1456
1457 public abstract boolean startIteratingOldHistoryLocked();
1458
1459 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1460
1461 public abstract void finishIteratingOldHistoryLocked();
1462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001464 * Return the base time offset for the battery history.
1465 */
1466 public abstract long getHistoryBaseTime();
1467
1468 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 * Returns the number of times the device has been started.
1470 */
1471 public abstract int getStartCount();
1472
1473 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001474 * 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 -08001475 * running on battery.
1476 *
1477 * {@hide}
1478 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001479 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001481 /**
1482 * Returns the number of times the screen was turned on.
1483 *
1484 * {@hide}
1485 */
1486 public abstract int getScreenOnCount(int which);
1487
Jeff Browne95c3cd2014-05-02 16:59:26 -07001488 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1489
Dianne Hackborn617f8772009-03-31 15:04:46 -07001490 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1491 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1492 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1493 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1494 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1495
1496 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1497 "dark", "dim", "medium", "light", "bright"
1498 };
1499
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001500 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1501 "0", "1", "2", "3", "4"
1502 };
1503
Dianne Hackborn617f8772009-03-31 15:04:46 -07001504 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001505
Dianne Hackborn617f8772009-03-31 15:04:46 -07001506 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001507 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001508 * the given brightness
1509 *
1510 * {@hide}
1511 */
1512 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001513 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001516 * Returns the time in microseconds that power save mode has been enabled while the device was
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001517 * running on battery.
1518 *
1519 * {@hide}
1520 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001521 public abstract long getPowerSaveModeEnabledTime(long elapsedRealtimeUs, int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001522
1523 /**
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001524 * Returns the number of times that power save mode was enabled.
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001525 *
1526 * {@hide}
1527 */
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001528 public abstract int getPowerSaveModeEnabledCount(int which);
1529
1530 /**
1531 * Returns the time in microseconds that device has been in idle mode while
1532 * running on battery.
1533 *
1534 * {@hide}
1535 */
1536 public abstract long getDeviceIdleModeEnabledTime(long elapsedRealtimeUs, int which);
1537
1538 /**
1539 * Returns the number of times that the devie has gone in to idle mode.
1540 *
1541 * {@hide}
1542 */
1543 public abstract int getDeviceIdleModeEnabledCount(int which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001544
1545 /**
Dianne Hackborn88e98df2015-03-23 13:29:14 -07001546 * Returns the time in microseconds that device has been in idling while on
1547 * battery. This is broader than {@link #getDeviceIdleModeEnabledTime} -- it
1548 * counts all of the time that we consider the device to be idle, whether or not
1549 * it is currently in the actual device idle mode.
1550 *
1551 * {@hide}
1552 */
1553 public abstract long getDeviceIdlingTime(long elapsedRealtimeUs, int which);
1554
1555 /**
1556 * Returns the number of times that the devie has started idling.
1557 *
1558 * {@hide}
1559 */
1560 public abstract int getDeviceIdlingCount(int which);
1561
1562 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001563 * Returns the number of times that connectivity state changed.
1564 *
1565 * {@hide}
1566 */
1567 public abstract int getNumConnectivityChange(int which);
1568
1569 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001570 * 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 -08001571 * running on battery.
1572 *
1573 * {@hide}
1574 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001575 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001576
1577 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001578 * Returns the number of times a phone call was activated.
1579 *
1580 * {@hide}
1581 */
1582 public abstract int getPhoneOnCount(int which);
1583
1584 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001585 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001586 * the given signal strength.
1587 *
1588 * {@hide}
1589 */
1590 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001591 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001592
Dianne Hackborn617f8772009-03-31 15:04:46 -07001593 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001594 * Returns the time in microseconds that the phone has been trying to
1595 * acquire a signal.
1596 *
1597 * {@hide}
1598 */
1599 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001600 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001601
1602 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001603 * Returns the number of times the phone has entered the given signal strength.
1604 *
1605 * {@hide}
1606 */
1607 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1608
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001609 /**
1610 * Returns the time in microseconds that the mobile network has been active
1611 * (in a high power state).
1612 *
1613 * {@hide}
1614 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001615 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001616
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001617 /**
1618 * Returns the number of times that the mobile network has transitioned to the
1619 * active state.
1620 *
1621 * {@hide}
1622 */
1623 public abstract int getMobileRadioActiveCount(int which);
1624
1625 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001626 * Returns the time in microseconds that is the difference between the mobile radio
1627 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1628 * from the radio.
1629 *
1630 * {@hide}
1631 */
1632 public abstract long getMobileRadioActiveAdjustedTime(int which);
1633
1634 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001635 * Returns the time in microseconds that the mobile network has been active
1636 * (in a high power state) but not being able to blame on an app.
1637 *
1638 * {@hide}
1639 */
1640 public abstract long getMobileRadioActiveUnknownTime(int which);
1641
1642 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001643 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001644 *
1645 * {@hide}
1646 */
1647 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001648
Dianne Hackborn627bba72009-03-24 22:32:56 -07001649 public static final int DATA_CONNECTION_NONE = 0;
1650 public static final int DATA_CONNECTION_GPRS = 1;
1651 public static final int DATA_CONNECTION_EDGE = 2;
1652 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001653 public static final int DATA_CONNECTION_CDMA = 4;
1654 public static final int DATA_CONNECTION_EVDO_0 = 5;
1655 public static final int DATA_CONNECTION_EVDO_A = 6;
1656 public static final int DATA_CONNECTION_1xRTT = 7;
1657 public static final int DATA_CONNECTION_HSDPA = 8;
1658 public static final int DATA_CONNECTION_HSUPA = 9;
1659 public static final int DATA_CONNECTION_HSPA = 10;
1660 public static final int DATA_CONNECTION_IDEN = 11;
1661 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001662 public static final int DATA_CONNECTION_LTE = 13;
1663 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001664 public static final int DATA_CONNECTION_HSPAP = 15;
1665 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001666
Dianne Hackborn627bba72009-03-24 22:32:56 -07001667 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001668 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001669 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001670 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001671 };
1672
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001673 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001674
1675 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001676 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001677 * the given data connection.
1678 *
1679 * {@hide}
1680 */
1681 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001682 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001684 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001685 * Returns the number of times the phone has entered the given data
1686 * connection type.
1687 *
1688 * {@hide}
1689 */
1690 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001691
Dianne Hackborn3251b902014-06-20 14:40:53 -07001692 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1693 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1694 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1695 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1696 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1697 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1698 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1699 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1700 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1701 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1702 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1703 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1704 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1705
1706 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1707
1708 static final String[] WIFI_SUPPL_STATE_NAMES = {
1709 "invalid", "disconn", "disabled", "inactive", "scanning",
1710 "authenticating", "associating", "associated", "4-way-handshake",
1711 "group-handshake", "completed", "dormant", "uninit"
1712 };
1713
1714 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1715 "inv", "dsc", "dis", "inact", "scan",
1716 "auth", "ascing", "asced", "4-way",
1717 "group", "compl", "dorm", "uninit"
1718 };
1719
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001720 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1721 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001722 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001723 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1724 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001725 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001726 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1727 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1728 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001729 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001730 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001731 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001732 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1733 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
1734 new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001735 new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
1736 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1737 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1738 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1739 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1740 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1741 new String[] {"in", "out", "emergency", "off"},
1742 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001743 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1744 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1745 SignalStrength.SIGNAL_STRENGTH_NAMES,
1746 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001747 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1748 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1749 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001750 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001751
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001752 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1753 = new BitDescription[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001754 new BitDescription(HistoryItem.STATE2_POWER_SAVE_FLAG, "power_save", "ps"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001755 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
1756 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Wr"),
1757 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001758 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001759 new BitDescription(HistoryItem.STATE2_DEVICE_IDLE_FLAG, "device_idle", "di"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001760 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1761 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1762 new String[] { "0", "1", "2", "3", "4" },
1763 new String[] { "0", "1", "2", "3", "4" }),
1764 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1765 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1766 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001767 };
1768
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001769 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001770 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn",
1771 "motion", "active", "pkginst", "pkgunin"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001772 };
1773
1774 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07001775 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
1776 "Esm", "Eac", "Epi", "Epu"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001777 };
1778
Dianne Hackborn617f8772009-03-31 15:04:46 -07001779 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001780 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001781 * running on battery.
1782 *
1783 * {@hide}
1784 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001785 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001786
1787 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001788 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001789 * been in the running state while the device was running on battery.
1790 *
1791 * {@hide}
1792 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001793 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001794
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001795 public static final int WIFI_STATE_OFF = 0;
1796 public static final int WIFI_STATE_OFF_SCANNING = 1;
1797 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
1798 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
1799 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
1800 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
1801 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
1802 public static final int WIFI_STATE_SOFT_AP = 7;
1803
1804 static final String[] WIFI_STATE_NAMES = {
1805 "off", "scanning", "no_net", "disconn",
1806 "sta", "p2p", "sta_p2p", "soft_ap"
1807 };
1808
1809 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
1810
1811 /**
1812 * Returns the time in microseconds that WiFi has been running in the given state.
1813 *
1814 * {@hide}
1815 */
1816 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001817 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001818
1819 /**
1820 * Returns the number of times that WiFi has entered the given state.
1821 *
1822 * {@hide}
1823 */
1824 public abstract int getWifiStateCount(int wifiState, int which);
1825
The Android Open Source Project10592532009-03-18 17:39:46 -07001826 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07001827 * Returns the time in microseconds that the wifi supplicant has been
1828 * in a given state.
1829 *
1830 * {@hide}
1831 */
1832 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
1833
1834 /**
1835 * Returns the number of times that the wifi supplicant has transitioned
1836 * to a given state.
1837 *
1838 * {@hide}
1839 */
1840 public abstract int getWifiSupplStateCount(int state, int which);
1841
1842 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
1843
1844 /**
1845 * Returns the time in microseconds that WIFI has been running with
1846 * the given signal strength.
1847 *
1848 * {@hide}
1849 */
1850 public abstract long getWifiSignalStrengthTime(int strengthBin,
1851 long elapsedRealtimeUs, int which);
1852
1853 /**
1854 * Returns the number of times WIFI has entered the given signal strength.
1855 *
1856 * {@hide}
1857 */
1858 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
1859
1860 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001861 * Returns the time in microseconds that bluetooth has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001862 * running on battery.
1863 *
1864 * {@hide}
1865 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001866 public abstract long getBluetoothOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001867
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001868 public abstract int getBluetoothPingCount();
1869
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001870 public static final int BLUETOOTH_STATE_INACTIVE = 0;
1871 public static final int BLUETOOTH_STATE_LOW = 1;
1872 public static final int BLUETOOTH_STATE_MEDIUM = 2;
1873 public static final int BLUETOOTH_STATE_HIGH = 3;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001874
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001875 static final String[] BLUETOOTH_STATE_NAMES = {
1876 "inactive", "low", "med", "high"
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001877 };
1878
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001879 public static final int NUM_BLUETOOTH_STATES = BLUETOOTH_STATE_HIGH +1;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001880
1881 /**
1882 * Returns the time in microseconds that Bluetooth has been running in the
1883 * given active state.
1884 *
1885 * {@hide}
1886 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001887 public abstract long getBluetoothStateTime(int bluetoothState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001888 long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001889
1890 /**
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001891 * Returns the number of times that Bluetooth has entered the given active state.
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001892 *
1893 * {@hide}
1894 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001895 public abstract int getBluetoothStateCount(int bluetoothState, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001896
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001897 /**
1898 * Returns the time in microseconds that the flashlight has been on while the device was
1899 * running on battery.
1900 *
1901 * {@hide}
1902 */
1903 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
1904
1905 /**
1906 * Returns the number of times that the flashlight has been turned on while the device was
1907 * running on battery.
1908 *
1909 * {@hide}
1910 */
1911 public abstract long getFlashlightOnCount(int which);
1912
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001913 public static final int NETWORK_MOBILE_RX_DATA = 0;
1914 public static final int NETWORK_MOBILE_TX_DATA = 1;
1915 public static final int NETWORK_WIFI_RX_DATA = 2;
1916 public static final int NETWORK_WIFI_TX_DATA = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001917
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001918 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001919
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001920 public abstract long getNetworkActivityBytes(int type, int which);
1921 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001922
Adam Lesinski33dac552015-03-09 15:24:48 -07001923 public static final int CONTROLLER_IDLE_TIME = 0;
1924 public static final int CONTROLLER_RX_TIME = 1;
1925 public static final int CONTROLLER_TX_TIME = 2;
1926 public static final int CONTROLLER_ENERGY = 3;
1927 public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_ENERGY + 1;
1928
1929 public abstract long getBluetoothControllerActivity(int type, int which);
1930 public abstract long getWifiControllerActivity(int type, int which);
1931
The Android Open Source Project10592532009-03-18 17:39:46 -07001932 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08001933 * Return the wall clock time when battery stats data collection started.
1934 */
1935 public abstract long getStartClockTime();
1936
1937 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07001938 * Return platform version tag that we were running in when the battery stats started.
1939 */
1940 public abstract String getStartPlatformVersion();
1941
1942 /**
1943 * Return platform version tag that we were running in when the battery stats ended.
1944 */
1945 public abstract String getEndPlatformVersion();
1946
1947 /**
1948 * Return the internal version code of the parcelled format.
1949 */
1950 public abstract int getParcelVersion();
1951
1952 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953 * Return whether we are currently running on battery.
1954 */
1955 public abstract boolean getIsOnBattery();
1956
1957 /**
1958 * Returns a SparseArray containing the statistics for each uid.
1959 */
1960 public abstract SparseArray<? extends Uid> getUidStats();
1961
1962 /**
1963 * Returns the current battery uptime in microseconds.
1964 *
1965 * @param curTime the amount of elapsed realtime in microseconds.
1966 */
1967 public abstract long getBatteryUptime(long curTime);
1968
1969 /**
1970 * Returns the current battery realtime in microseconds.
1971 *
1972 * @param curTime the amount of elapsed realtime in microseconds.
1973 */
1974 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001975
1976 /**
Evan Millar633a1742009-04-02 16:36:33 -07001977 * Returns the battery percentage level at the last time the device was unplugged from power, or
1978 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07001979 */
Evan Millar633a1742009-04-02 16:36:33 -07001980 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07001981
1982 /**
Evan Millar633a1742009-04-02 16:36:33 -07001983 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
1984 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07001985 */
Evan Millar633a1742009-04-02 16:36:33 -07001986 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987
1988 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001989 * Get the amount the battery has discharged since the stats were
1990 * last reset after charging, as a lower-end approximation.
1991 */
1992 public abstract int getLowDischargeAmountSinceCharge();
1993
1994 /**
1995 * Get the amount the battery has discharged since the stats were
1996 * last reset after charging, as an upper-end approximation.
1997 */
1998 public abstract int getHighDischargeAmountSinceCharge();
1999
2000 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07002001 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
2002 */
2003 public abstract int getDischargeAmount(int which);
2004
2005 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002006 * Get the amount the battery has discharged while the screen was on,
2007 * since the last time power was unplugged.
2008 */
2009 public abstract int getDischargeAmountScreenOn();
2010
2011 /**
2012 * Get the amount the battery has discharged while the screen was on,
2013 * since the last time the device was charged.
2014 */
2015 public abstract int getDischargeAmountScreenOnSinceCharge();
2016
2017 /**
2018 * Get the amount the battery has discharged while the screen was off,
2019 * since the last time power was unplugged.
2020 */
2021 public abstract int getDischargeAmountScreenOff();
2022
2023 /**
2024 * Get the amount the battery has discharged while the screen was off,
2025 * since the last time the device was charged.
2026 */
2027 public abstract int getDischargeAmountScreenOffSinceCharge();
2028
2029 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 * Returns the total, last, or current battery uptime in microseconds.
2031 *
2032 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002033 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002034 */
2035 public abstract long computeBatteryUptime(long curTime, int which);
2036
2037 /**
2038 * Returns the total, last, or current battery realtime in microseconds.
2039 *
2040 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002041 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 */
2043 public abstract long computeBatteryRealtime(long curTime, int which);
2044
2045 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002046 * Returns the total, last, or current battery screen off uptime in microseconds.
2047 *
2048 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002049 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002050 */
2051 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
2052
2053 /**
2054 * Returns the total, last, or current battery screen off realtime in microseconds.
2055 *
2056 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002057 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002058 */
2059 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
2060
2061 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062 * Returns the total, last, or current uptime in microseconds.
2063 *
2064 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002065 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002066 */
2067 public abstract long computeUptime(long curTime, int which);
2068
2069 /**
2070 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002071 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002072 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002073 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 */
2075 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002076
2077 /**
2078 * Compute an approximation for how much run time (in microseconds) is remaining on
2079 * the battery. Returns -1 if no time can be computed: either there is not
2080 * enough current data to make a decision, or the battery is currently
2081 * charging.
2082 *
2083 * @param curTime The current elepsed realtime in microseconds.
2084 */
2085 public abstract long computeBatteryTimeRemaining(long curTime);
2086
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002087 // The part of a step duration that is the actual time.
2088 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2089
2090 // Bits in a step duration that are the new battery level we are at.
2091 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002092 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002093
2094 // Bits in a step duration that are the initial mode we were in at that step.
2095 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002096 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002097
2098 // Bits in a step duration that indicate which modes changed during that step.
2099 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002100 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002101
2102 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2103 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2104
2105 // Step duration mode: power save is on.
2106 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2107
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002108 // Step duration mode: device is currently in idle mode.
2109 public static final int STEP_LEVEL_MODE_DEVICE_IDLE = 0x08;
2110
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002111 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2112 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002113 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2114 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002115 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2116 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2117 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2118 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2119 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002120 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE|STEP_LEVEL_MODE_DEVICE_IDLE,
2121 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002122 };
2123 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2124 (Display.STATE_OFF-1),
2125 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002126 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002127 (Display.STATE_ON-1),
2128 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2129 (Display.STATE_DOZE-1),
2130 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2131 (Display.STATE_DOZE_SUSPEND-1),
2132 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002133 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_DEVICE_IDLE,
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002134 };
2135 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2136 "screen off",
2137 "screen off power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002138 "screen off device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002139 "screen on",
2140 "screen on power save",
2141 "screen doze",
2142 "screen doze power save",
2143 "screen doze-suspend",
2144 "screen doze-suspend power save",
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002145 "screen doze-suspend device idle",
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002146 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002147
2148 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002149 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002150 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002151 public abstract LevelStepTracker getDischargeLevelStepTracker();
2152
2153 /**
2154 * Return the array of daily discharge step durations.
2155 */
2156 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002157
2158 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002159 * Compute an approximation for how much time (in microseconds) remains until the battery
2160 * is fully charged. Returns -1 if no time can be computed: either there is not
2161 * enough current data to make a decision, or the battery is currently
2162 * discharging.
2163 *
2164 * @param curTime The current elepsed realtime in microseconds.
2165 */
2166 public abstract long computeChargeTimeRemaining(long curTime);
2167
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002168 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002169 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002170 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002171 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002172
2173 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002174 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002175 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002176 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002177
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002178 public abstract ArrayList<PackageChange> getDailyPackageChanges();
2179
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002180 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002181
Evan Millarc64edde2009-04-18 12:26:32 -07002182 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183
Amith Yamasanie43530a2009-08-21 13:11:37 -07002184 /** Returns the number of different speeds that the CPU can run at */
2185 public abstract int getCpuSpeedSteps();
2186
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002187 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2188
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002189 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 long days = seconds / (60 * 60 * 24);
2191 if (days != 0) {
2192 out.append(days);
2193 out.append("d ");
2194 }
2195 long used = days * 60 * 60 * 24;
2196
2197 long hours = (seconds - used) / (60 * 60);
2198 if (hours != 0 || used != 0) {
2199 out.append(hours);
2200 out.append("h ");
2201 }
2202 used += hours * 60 * 60;
2203
2204 long mins = (seconds-used) / 60;
2205 if (mins != 0 || used != 0) {
2206 out.append(mins);
2207 out.append("m ");
2208 }
2209 used += mins * 60;
2210
2211 if (seconds != 0 || used != 0) {
2212 out.append(seconds-used);
2213 out.append("s ");
2214 }
2215 }
2216
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002217 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002218 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002219 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220 sb.append(time - (sec * 1000));
2221 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 }
2223
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002224 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002225 long sec = time / 1000;
2226 formatTimeRaw(sb, sec);
2227 sb.append(time - (sec * 1000));
2228 sb.append("ms");
2229 }
2230
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002231 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002233 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002234 }
2235 float perc = ((float)num) / ((float)den) * 100;
2236 mFormatBuilder.setLength(0);
2237 mFormatter.format("%.1f%%", perc);
2238 return mFormatBuilder.toString();
2239 }
2240
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002241 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002242 mFormatBuilder.setLength(0);
2243
2244 if (bytes < BYTES_PER_KB) {
2245 return bytes + "B";
2246 } else if (bytes < BYTES_PER_MB) {
2247 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2248 return mFormatBuilder.toString();
2249 } else if (bytes < BYTES_PER_GB){
2250 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2251 return mFormatBuilder.toString();
2252 } else {
2253 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2254 return mFormatBuilder.toString();
2255 }
2256 }
2257
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002258 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002259 if (timer != null) {
2260 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002261 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002262 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2263 return totalTimeMillis;
2264 }
2265 return 0;
2266 }
2267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268 /**
2269 *
2270 * @param sb a StringBuilder object.
2271 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002272 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002274 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002275 * @param linePrefix a String to be prepended to each line of output.
2276 * @return the line prefix
2277 */
2278 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002279 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280
2281 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002282 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283
Evan Millarc64edde2009-04-18 12:26:32 -07002284 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 if (totalTimeMillis != 0) {
2286 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002287 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002288 if (name != null) {
2289 sb.append(name);
2290 sb.append(' ');
2291 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 sb.append('(');
2293 sb.append(count);
2294 sb.append(" times)");
2295 return ", ";
2296 }
2297 }
2298 return linePrefix;
2299 }
2300
2301 /**
2302 * Checkin version of wakelock printer. Prints simple comma-separated list.
2303 *
2304 * @param sb a StringBuilder object.
2305 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002306 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002307 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002308 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309 * @param linePrefix a String to be prepended to each line of output.
2310 * @return the line prefix
2311 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002312 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2313 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002314 long totalTimeMicros = 0;
2315 int count = 0;
2316 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002317 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002318 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 }
2320 sb.append(linePrefix);
2321 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2322 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002323 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 sb.append(count);
2325 return ",";
2326 }
2327
2328 /**
2329 * Dump a comma-separated line of values for terse checkin mode.
2330 *
2331 * @param pw the PageWriter to dump log to
2332 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2333 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2334 * @param args type-dependent data arguments
2335 */
2336 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2337 Object... args ) {
2338 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
2339 pw.print(uid); pw.print(',');
2340 pw.print(category); pw.print(',');
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002341 pw.print(type);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342
2343 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002344 pw.print(',');
2345 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002347 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002349
2350 /**
2351 * Temporary for settings.
2352 */
2353 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2354 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2355 }
2356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357 /**
2358 * Checkin server version of dump to produce more compact, computer-readable log.
2359 *
2360 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002361 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002362 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2363 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2365 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2366 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2368 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002369 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2370 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2371 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 final long totalRealtime = computeRealtime(rawRealtime, which);
2373 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002374 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002375 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002376 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
2377 final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002378 final long deviceIdlingTime = getDeviceIdlingTime(rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002379 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002380 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
2381 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2382 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
2383 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 StringBuilder sb = new StringBuilder(128);
2386
Evan Millar22ac0432009-03-31 11:33:18 -07002387 SparseArray<? extends Uid> uidStats = getUidStats();
2388 final int NU = uidStats.size();
2389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 // Dump "battery" stat
2393 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002394 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002395 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002396 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002397 getStartClockTime(),
2398 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002400 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002401 long fullWakeLockTimeTotal = 0;
2402 long partialWakeLockTimeTotal = 0;
2403
2404 for (int iu = 0; iu < NU; iu++) {
2405 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002406
Evan Millar22ac0432009-03-31 11:33:18 -07002407 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
2408 if (wakelocks.size() > 0) {
2409 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
2410 : wakelocks.entrySet()) {
2411 Uid.Wakelock wl = ent.getValue();
2412
2413 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2414 if (fullWakeTimer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002415 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2416 which);
Evan Millar22ac0432009-03-31 11:33:18 -07002417 }
2418
2419 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2420 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07002421 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002422 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002423 }
2424 }
2425 }
2426 }
2427
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002428 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2429 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2430 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2431 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2432 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2433 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2434 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2435 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
2436
2437 // Dump network stats
2438 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2439 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
2440 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets);
2441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 // Dump misc stats
2443 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002444 screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000,
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002445 wifiRunningTime / 1000, bluetoothOnTime / 1000,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002446 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002447 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
2448 0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which) / 1000,
2449 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002450 powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeEnabledTime / 1000,
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002451 getDeviceIdleModeEnabledCount(which), deviceIdlingTime / 1000,
2452 getDeviceIdlingCount(which));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002453
2454 // Dump screen brightness stats
2455 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2456 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002457 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002458 }
2459 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002460
Dianne Hackborn627bba72009-03-24 22:32:56 -07002461 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002462 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2463 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002464 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002465 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002466 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002467 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002468 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002469 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002470 args[i] = getPhoneSignalStrengthCount(i, which);
2471 }
2472 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002473
Dianne Hackborn627bba72009-03-24 22:32:56 -07002474 // Dump network type stats
2475 args = new Object[NUM_DATA_CONNECTION_TYPES];
2476 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002477 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002478 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002479 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2480 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2481 args[i] = getPhoneDataConnectionCount(i, which);
2482 }
2483 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002484
2485 // Dump wifi state stats
2486 args = new Object[NUM_WIFI_STATES];
2487 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002488 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002489 }
2490 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2491 for (int i=0; i<NUM_WIFI_STATES; i++) {
2492 args[i] = getWifiStateCount(i, which);
2493 }
2494 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2495
Dianne Hackborn3251b902014-06-20 14:40:53 -07002496 // Dump wifi suppl state stats
2497 args = new Object[NUM_WIFI_SUPPL_STATES];
2498 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2499 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2500 }
2501 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2502 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2503 args[i] = getWifiSupplStateCount(i, which);
2504 }
2505 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
2506
2507 // Dump wifi signal strength stats
2508 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
2509 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2510 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
2511 }
2512 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
2513 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2514 args[i] = getWifiSignalStrengthCount(i, which);
2515 }
2516 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
2517
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002518 // Dump bluetooth state stats
2519 args = new Object[NUM_BLUETOOTH_STATES];
2520 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002521 args[i] = getBluetoothStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002522 }
2523 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_TIME_DATA, args);
2524 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
2525 args[i] = getBluetoothStateCount(i, which);
2526 }
2527 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_COUNT_DATA, args);
2528
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002529 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002530 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07002531 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002534 if (which == STATS_SINCE_UNPLUGGED) {
2535 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2536 getDischargeStartLevel()-getDischargeCurrentLevel(),
2537 getDischargeStartLevel()-getDischargeCurrentLevel(),
2538 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
2539 } else {
2540 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2541 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002542 getDischargeAmountScreenOnSinceCharge(),
2543 getDischargeAmountScreenOffSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002544 }
2545
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002546 if (reqUid < 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002547 Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002548 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002549 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002550 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002551 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002552 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002553 sb.toString());
2554 }
Evan Millarc64edde2009-04-18 12:26:32 -07002555 }
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002556 Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002557 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002558 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
2559 // Not doing the regular wake lock formatting to remain compatible
2560 // with the old checkin format.
2561 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
2562 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002563 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002564 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002565 }
2566 }
Evan Millarc64edde2009-04-18 12:26:32 -07002567 }
2568
Dianne Hackbornd953c532014-08-16 18:17:38 -07002569 BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002570 helper.create(this);
2571 helper.refreshStats(which, UserHandle.USER_ALL);
2572 List<BatterySipper> sippers = helper.getUsageList();
2573 if (sippers != null && sippers.size() > 0) {
2574 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
2575 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08002576 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002577 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
2578 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
2579 for (int i=0; i<sippers.size(); i++) {
2580 BatterySipper bs = sippers.get(i);
2581 int uid = 0;
2582 String label;
2583 switch (bs.drainType) {
2584 case IDLE:
2585 label="idle";
2586 break;
2587 case CELL:
2588 label="cell";
2589 break;
2590 case PHONE:
2591 label="phone";
2592 break;
2593 case WIFI:
2594 label="wifi";
2595 break;
2596 case BLUETOOTH:
2597 label="blue";
2598 break;
2599 case SCREEN:
2600 label="scrn";
2601 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002602 case FLASHLIGHT:
2603 label="flashlight";
2604 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002605 case APP:
2606 uid = bs.uidObj.getUid();
2607 label = "uid";
2608 break;
2609 case USER:
2610 uid = UserHandle.getUid(bs.userId, 0);
2611 label = "user";
2612 break;
2613 case UNACCOUNTED:
2614 label = "unacc";
2615 break;
2616 case OVERCOUNTED:
2617 label = "over";
2618 break;
2619 default:
2620 label = "???";
2621 }
2622 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
2623 BatteryStatsHelper.makemAh(bs.value));
2624 }
2625 }
2626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 for (int iu = 0; iu < NU; iu++) {
2628 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002629 if (reqUid >= 0 && uid != reqUid) {
2630 continue;
2631 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632 Uid u = uidStats.valueAt(iu);
2633 // Dump Network stats per uid, if any
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002634 long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2635 long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2636 long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2637 long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2638 long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2639 long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002640 long mobileActiveTime = u.getMobileRadioActiveTime(which);
2641 int mobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002642 long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2643 long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002644 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
2645 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07002646 int wifiScanCount = u.getWifiScanCount(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002647 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002648
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002649 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
2650 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002651 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002652 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
2653 wifiBytesRx, wifiBytesTx,
2654 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002655 wifiPacketsRx, wifiPacketsTx,
2656 mobileActiveTime, mobileActiveCount);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002657 }
2658
Dianne Hackborn62793e42015-03-09 11:15:41 -07002659 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07002660 || uidWifiRunningTime != 0) {
Nick Pelly6ccaa542012-06-15 15:22:47 -07002661 dumpLine(pw, uid, category, WIFI_DATA,
Dianne Hackborn62793e42015-03-09 11:15:41 -07002662 fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime, wifiScanCount);
The Android Open Source Project10592532009-03-18 17:39:46 -07002663 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664
Dianne Hackborn617f8772009-03-31 15:04:46 -07002665 if (u.hasUserActivity()) {
2666 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
2667 boolean hasData = false;
2668 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
2669 int val = u.getUserActivityCount(i, which);
2670 args[i] = val;
2671 if (val != 0) hasData = true;
2672 }
2673 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07002674 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002675 }
2676 }
2677
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002678 Map<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002679 if (wakelocks.size() > 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002680 for (Map.Entry<String, ? extends Uid.Wakelock> ent : wakelocks.entrySet()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002681 Uid.Wakelock wl = ent.getValue();
2682 String linePrefix = "";
2683 sb.setLength(0);
Evan Millarc64edde2009-04-18 12:26:32 -07002684 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002685 rawRealtime, "f", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07002686 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002687 rawRealtime, "p", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07002688 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002689 rawRealtime, "w", which, linePrefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690
2691 // Only log if we had at lease one wakelock...
2692 if (sb.length() > 0) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002693 String name = ent.getKey();
2694 if (name.indexOf(',') >= 0) {
2695 name = name.replace(',', '_');
2696 }
2697 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 }
2699 }
2700 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07002701
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002702 Map<String, ? extends Timer> syncs = u.getSyncStats();
2703 if (syncs.size() > 0) {
2704 for (Map.Entry<String, ? extends Timer> ent : syncs.entrySet()) {
2705 Timer timer = ent.getValue();
2706 // Convert from microseconds to milliseconds with rounding
2707 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2708 int count = timer.getCountLocked(which);
2709 if (totalTime != 0) {
2710 dumpLine(pw, uid, category, SYNC_DATA, ent.getKey(), totalTime, count);
2711 }
2712 }
2713 }
2714
2715 Map<String, ? extends Timer> jobs = u.getJobStats();
2716 if (jobs.size() > 0) {
2717 for (Map.Entry<String, ? extends Timer> ent : jobs.entrySet()) {
2718 Timer timer = ent.getValue();
2719 // Convert from microseconds to milliseconds with rounding
2720 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2721 int count = timer.getCountLocked(which);
2722 if (totalTime != 0) {
2723 dumpLine(pw, uid, category, JOB_DATA, ent.getKey(), totalTime, count);
2724 }
2725 }
2726 }
2727
Dianne Hackborn61659e52014-07-09 16:13:01 -07002728 SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
2729 int NSE = sensors.size();
2730 for (int ise=0; ise<NSE; ise++) {
2731 Uid.Sensor se = sensors.valueAt(ise);
2732 int sensorNumber = sensors.keyAt(ise);
2733 Timer timer = se.getSensorTime();
2734 if (timer != null) {
2735 // Convert from microseconds to milliseconds with rounding
2736 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2737 int count = timer.getCountLocked(which);
2738 if (totalTime != 0) {
2739 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
2740 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002741 }
2742 }
2743
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002744 Timer vibTimer = u.getVibratorOnTimer();
2745 if (vibTimer != null) {
2746 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002747 long totalTime = (vibTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002748 int count = vibTimer.getCountLocked(which);
2749 if (totalTime != 0) {
2750 dumpLine(pw, uid, category, VIBRATOR_DATA, totalTime, count);
2751 }
2752 }
2753
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002754 Timer fgTimer = u.getForegroundActivityTimer();
2755 if (fgTimer != null) {
2756 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002757 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002758 int count = fgTimer.getCountLocked(which);
2759 if (totalTime != 0) {
2760 dumpLine(pw, uid, category, FOREGROUND_DATA, totalTime, count);
2761 }
2762 }
2763
Dianne Hackborn61659e52014-07-09 16:13:01 -07002764 Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
2765 long totalStateTime = 0;
2766 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
2767 totalStateTime += u.getProcessStateTime(ips, rawRealtime, which);
2768 stateTimes[ips] = (totalStateTime + 500) / 1000;
2769 }
2770 if (totalStateTime > 0) {
2771 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
2772 }
2773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
2775 if (processStats.size() > 0) {
2776 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
2777 : processStats.entrySet()) {
2778 Uid.Proc ps = ent.getValue();
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002779
Dianne Hackborn62793e42015-03-09 11:15:41 -07002780 final long userMillis = ps.getUserTime(which);
2781 final long systemMillis = ps.getSystemTime(which);
2782 final long foregroundMillis = ps.getForegroundTime(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002783 final int starts = ps.getStarts(which);
2784 final int numCrashes = ps.getNumCrashes(which);
2785 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002786
2787 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002788 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002789 dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis,
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002790 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002791 }
2792 }
2793 }
2794
2795 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
2796 if (packageStats.size() > 0) {
2797 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
2798 : packageStats.entrySet()) {
2799
2800 Uid.Pkg ps = ent.getValue();
2801 int wakeups = ps.getWakeups(which);
2802 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
2803 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
2804 : serviceStats.entrySet()) {
2805 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
2806 long startTime = ss.getStartTime(batteryUptime, which);
2807 int starts = ss.getStarts(which);
2808 int launches = ss.getLaunches(which);
2809 if (startTime != 0 || starts != 0 || launches != 0) {
2810 dumpLine(pw, uid, category, APK_DATA,
2811 wakeups, // wakeup alarms
2812 ent.getKey(), // Apk
2813 sent.getKey(), // service
2814 startTime / 1000, // time spent started, in ms
2815 starts,
2816 launches);
2817 }
2818 }
2819 }
2820 }
2821 }
2822 }
2823
Dianne Hackborn81038902012-11-26 17:04:09 -08002824 static final class TimerEntry {
2825 final String mName;
2826 final int mId;
2827 final BatteryStats.Timer mTimer;
2828 final long mTime;
2829 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
2830 mName = name;
2831 mId = id;
2832 mTimer = timer;
2833 mTime = time;
2834 }
2835 }
2836
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002837 private void printmAh(PrintWriter printer, double power) {
2838 printer.print(BatteryStatsHelper.makemAh(power));
2839 }
2840
Dianne Hackbornd953c532014-08-16 18:17:38 -07002841 /**
2842 * Temporary for settings.
2843 */
2844 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
2845 int reqUid) {
2846 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2847 }
2848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002849 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002850 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07002851 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2853 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2854 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855
2856 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2857 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
2858 final long totalRealtime = computeRealtime(rawRealtime, which);
2859 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002860 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2861 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2862 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002863 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
2864 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002865
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07002867
2868 SparseArray<? extends Uid> uidStats = getUidStats();
2869 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002870
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002871 sb.setLength(0);
2872 sb.append(prefix);
2873 sb.append(" Time on battery: ");
2874 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
2875 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
2876 sb.append(") realtime, ");
2877 formatTimeMs(sb, whichBatteryUptime / 1000);
2878 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
2879 sb.append(") uptime");
2880 pw.println(sb.toString());
2881 sb.setLength(0);
2882 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002883 sb.append(" Time on battery screen off: ");
2884 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
2885 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
2886 sb.append(") realtime, ");
2887 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
2888 sb.append("(");
2889 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
2890 sb.append(") uptime");
2891 pw.println(sb.toString());
2892 sb.setLength(0);
2893 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002894 sb.append(" Total run time: ");
2895 formatTimeMs(sb, totalRealtime / 1000);
2896 sb.append("realtime, ");
2897 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002898 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07002899 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002900 if (batteryTimeRemaining >= 0) {
2901 sb.setLength(0);
2902 sb.append(prefix);
2903 sb.append(" Battery time remaining: ");
2904 formatTimeMs(sb, batteryTimeRemaining / 1000);
2905 pw.println(sb.toString());
2906 }
2907 if (chargeTimeRemaining >= 0) {
2908 sb.setLength(0);
2909 sb.append(prefix);
2910 sb.append(" Charge time remaining: ");
2911 formatTimeMs(sb, chargeTimeRemaining / 1000);
2912 pw.println(sb.toString());
2913 }
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002914 pw.print(" Start clock time: ");
2915 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
2916
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002917 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002918 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002919 final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
2920 final long deviceIdleModeEnabledTime = getDeviceIdleModeEnabledTime(rawRealtime, which);
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002921 final long deviceIdlingTime = getDeviceIdlingTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002922 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
2923 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
2924 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2925 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002926 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002927 sb.append(prefix);
2928 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
2929 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002930 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002931 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
2932 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07002933 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002934 pw.println(sb.toString());
2935 sb.setLength(0);
2936 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002937 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002938 boolean didOne = false;
2939 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002940 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002941 if (time == 0) {
2942 continue;
2943 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002944 sb.append("\n ");
2945 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002946 didOne = true;
2947 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
2948 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002949 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002950 sb.append("(");
2951 sb.append(formatRatioLocked(time, screenOnTime));
2952 sb.append(")");
2953 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002954 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002955 pw.println(sb.toString());
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002956 if (powerSaveModeEnabledTime != 0) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002957 sb.setLength(0);
2958 sb.append(prefix);
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002959 sb.append(" Power save mode enabled: ");
2960 formatTimeMs(sb, powerSaveModeEnabledTime / 1000);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002961 sb.append("(");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002962 sb.append(formatRatioLocked(powerSaveModeEnabledTime, whichBatteryRealtime));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002963 sb.append(")");
2964 pw.println(sb.toString());
2965 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002966 if (deviceIdlingTime != 0) {
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002967 sb.setLength(0);
2968 sb.append(prefix);
2969 sb.append(" Device idling: ");
Dianne Hackborn88e98df2015-03-23 13:29:14 -07002970 formatTimeMs(sb, deviceIdlingTime / 1000);
2971 sb.append("(");
2972 sb.append(formatRatioLocked(deviceIdlingTime, whichBatteryRealtime));
2973 sb.append(") "); sb.append(getDeviceIdlingCount(which));
2974 sb.append("x");
2975 pw.println(sb.toString());
2976 }
2977 if (deviceIdleModeEnabledTime != 0) {
2978 sb.setLength(0);
2979 sb.append(prefix);
2980 sb.append(" Idle mode time: ");
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002981 formatTimeMs(sb, deviceIdleModeEnabledTime / 1000);
2982 sb.append("(");
2983 sb.append(formatRatioLocked(deviceIdleModeEnabledTime, whichBatteryRealtime));
2984 sb.append(") "); sb.append(getDeviceIdleModeEnabledCount(which));
2985 sb.append("x");
2986 pw.println(sb.toString());
2987 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002988 if (phoneOnTime != 0) {
2989 sb.setLength(0);
2990 sb.append(prefix);
2991 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
2992 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07002993 sb.append(") "); sb.append(getPhoneOnCount(which)); sb.append("x");
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002994 }
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002995 int connChanges = getNumConnectivityChange(which);
2996 if (connChanges != 0) {
2997 pw.print(prefix);
2998 pw.print(" Connectivity changes: "); pw.println(connChanges);
2999 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003000
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003001 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07003002 long fullWakeLockTimeTotalMicros = 0;
3003 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08003004
Dianne Hackborn81038902012-11-26 17:04:09 -08003005 final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>();
3006
Evan Millar22ac0432009-03-31 11:33:18 -07003007 for (int iu = 0; iu < NU; iu++) {
3008 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003009
Evan Millar22ac0432009-03-31 11:33:18 -07003010 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
3011 if (wakelocks.size() > 0) {
3012 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
3013 : wakelocks.entrySet()) {
3014 Uid.Wakelock wl = ent.getValue();
3015
3016 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
3017 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07003018 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003019 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07003020 }
3021
3022 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
3023 if (partialWakeTimer != null) {
Dianne Hackborn81038902012-11-26 17:04:09 -08003024 long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003025 rawRealtime, which);
Dianne Hackborn81038902012-11-26 17:04:09 -08003026 if (totalTimeMicros > 0) {
3027 if (reqUid < 0) {
3028 // Only show the ordered list of all wake
3029 // locks if the caller is not asking for data
3030 // about a specific uid.
3031 timers.add(new TimerEntry(ent.getKey(), u.getUid(),
3032 partialWakeTimer, totalTimeMicros));
3033 }
3034 partialWakeLockTimeTotalMicros += totalTimeMicros;
3035 }
Evan Millar22ac0432009-03-31 11:33:18 -07003036 }
3037 }
3038 }
3039 }
3040
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003041 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3042 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3043 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3044 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3045 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3046 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
3047 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3048 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
3049
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003050 if (fullWakeLockTimeTotalMicros != 0) {
3051 sb.setLength(0);
3052 sb.append(prefix);
3053 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
3054 (fullWakeLockTimeTotalMicros + 500) / 1000);
3055 pw.println(sb.toString());
3056 }
3057
3058 if (partialWakeLockTimeTotalMicros != 0) {
3059 sb.setLength(0);
3060 sb.append(prefix);
3061 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
3062 (partialWakeLockTimeTotalMicros + 500) / 1000);
3063 pw.println(sb.toString());
3064 }
3065
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003066 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003067 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
3068 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
3069 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
3070 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003071 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003072 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07003073 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07003074 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08003075 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003076 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003077 if (time == 0) {
3078 continue;
3079 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003080 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003081 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003082 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08003083 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003084 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003085 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003086 sb.append("(");
3087 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003088 sb.append(") ");
3089 sb.append(getPhoneSignalStrengthCount(i, which));
3090 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003091 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003092 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003093 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003094
3095 sb.setLength(0);
3096 sb.append(prefix);
3097 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003098 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003099 pw.println(sb.toString());
3100
Dianne Hackborn627bba72009-03-24 22:32:56 -07003101 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003102 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003103 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003104 didOne = false;
3105 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003106 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003107 if (time == 0) {
3108 continue;
3109 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003110 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003111 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003112 didOne = true;
3113 sb.append(DATA_CONNECTION_NAMES[i]);
3114 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003115 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003116 sb.append("(");
3117 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003118 sb.append(") ");
3119 sb.append(getPhoneDataConnectionCount(i, which));
3120 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003121 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003122 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003123 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003124
3125 sb.setLength(0);
3126 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003127 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003128 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003129 formatTimeMs(sb, mobileActiveTime / 1000);
3130 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3131 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3132 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003133 pw.println(sb.toString());
3134
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003135 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3136 if (mobileActiveUnknownTime != 0) {
3137 sb.setLength(0);
3138 sb.append(prefix);
3139 sb.append(" Mobile radio active unknown time: ");
3140 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3141 sb.append("(");
3142 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3143 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3144 sb.append("x");
3145 pw.println(sb.toString());
3146 }
3147
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003148 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3149 if (mobileActiveAdjustedTime != 0) {
3150 sb.setLength(0);
3151 sb.append(prefix);
3152 sb.append(" Mobile radio active adjusted time: ");
3153 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3154 sb.append("(");
3155 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3156 sb.append(")");
3157 pw.println(sb.toString());
3158 }
3159
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003160 pw.print(prefix);
3161 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3162 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3163 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3164 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003165 sb.setLength(0);
3166 sb.append(prefix);
3167 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3168 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3169 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3170 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003171 sb.append(")");
3172 pw.println(sb.toString());
3173
3174 sb.setLength(0);
3175 sb.append(prefix);
3176 sb.append(" Wifi states:");
3177 didOne = false;
3178 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003179 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003180 if (time == 0) {
3181 continue;
3182 }
3183 sb.append("\n ");
3184 didOne = true;
3185 sb.append(WIFI_STATE_NAMES[i]);
3186 sb.append(" ");
3187 formatTimeMs(sb, time/1000);
3188 sb.append("(");
3189 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3190 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003191 sb.append(getWifiStateCount(i, which));
3192 sb.append("x");
3193 }
3194 if (!didOne) sb.append(" (no activity)");
3195 pw.println(sb.toString());
3196
3197 sb.setLength(0);
3198 sb.append(prefix);
3199 sb.append(" Wifi supplicant states:");
3200 didOne = false;
3201 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3202 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3203 if (time == 0) {
3204 continue;
3205 }
3206 sb.append("\n ");
3207 didOne = true;
3208 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3209 sb.append(" ");
3210 formatTimeMs(sb, time/1000);
3211 sb.append("(");
3212 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3213 sb.append(") ");
3214 sb.append(getWifiSupplStateCount(i, which));
3215 sb.append("x");
3216 }
3217 if (!didOne) sb.append(" (no activity)");
3218 pw.println(sb.toString());
3219
3220 sb.setLength(0);
3221 sb.append(prefix);
3222 sb.append(" Wifi signal levels:");
3223 didOne = false;
3224 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3225 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3226 if (time == 0) {
3227 continue;
3228 }
3229 sb.append("\n ");
3230 sb.append(prefix);
3231 didOne = true;
3232 sb.append("level(");
3233 sb.append(i);
3234 sb.append(") ");
3235 formatTimeMs(sb, time/1000);
3236 sb.append("(");
3237 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3238 sb.append(") ");
3239 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003240 sb.append("x");
3241 }
3242 if (!didOne) sb.append(" (no activity)");
3243 pw.println(sb.toString());
3244
Adam Lesinski33dac552015-03-09 15:24:48 -07003245 final long wifiIdleTimeMs = getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which);
3246 final long wifiRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which);
3247 final long wifiTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which);
3248 final long wifiTotalTimeMs = wifiIdleTimeMs + wifiRxTimeMs + wifiTxTimeMs;
3249
3250 sb.setLength(0);
3251 sb.append(prefix);
3252 sb.append(" WiFi Idle time: "); formatTimeMs(sb, wifiIdleTimeMs);
3253 sb.append(" (");
3254 sb.append(formatRatioLocked(wifiIdleTimeMs, wifiTotalTimeMs));
3255 sb.append(")");
3256 pw.println(sb.toString());
3257
3258 sb.setLength(0);
3259 sb.append(prefix);
3260 sb.append(" WiFi Rx time: "); formatTimeMs(sb, wifiRxTimeMs);
3261 sb.append(" (");
3262 sb.append(formatRatioLocked(wifiRxTimeMs, wifiTotalTimeMs));
3263 sb.append(")");
3264 pw.println(sb.toString());
3265
3266 sb.setLength(0);
3267 sb.append(prefix);
3268 sb.append(" WiFi Tx time: "); formatTimeMs(sb, wifiTxTimeMs);
3269 sb.append(" (");
3270 sb.append(formatRatioLocked(wifiTxTimeMs, wifiTotalTimeMs));
3271 sb.append(")");
3272 pw.println(sb.toString());
3273
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003274 sb.setLength(0);
3275 sb.append(prefix);
3276 sb.append(" Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003277 sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime));
3278 sb.append(")");
3279 pw.println(sb.toString());
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003280
3281 sb.setLength(0);
3282 sb.append(prefix);
3283 sb.append(" Bluetooth states:");
3284 didOne = false;
3285 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003286 final long time = getBluetoothStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003287 if (time == 0) {
3288 continue;
3289 }
3290 sb.append("\n ");
3291 didOne = true;
3292 sb.append(BLUETOOTH_STATE_NAMES[i]);
3293 sb.append(" ");
3294 formatTimeMs(sb, time/1000);
3295 sb.append("(");
3296 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3297 sb.append(") ");
3298 sb.append(getPhoneDataConnectionCount(i, which));
3299 sb.append("x");
3300 }
Adam Lesinski33dac552015-03-09 15:24:48 -07003301
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003302 if (!didOne) sb.append(" (no activity)");
3303 pw.println(sb.toString());
3304
Adam Lesinski33dac552015-03-09 15:24:48 -07003305 final long bluetoothIdleTimeMs =
3306 getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which);
3307 final long bluetoothRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which);
3308 final long bluetoothTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which);
3309 final long bluetoothTotalTimeMs = bluetoothIdleTimeMs + bluetoothRxTimeMs +
3310 bluetoothTxTimeMs;
3311
3312 sb.setLength(0);
3313 sb.append(prefix);
3314 sb.append(" Bluetooth Idle time: "); formatTimeMs(sb, bluetoothIdleTimeMs);
3315 sb.append(" (");
3316 sb.append(formatRatioLocked(bluetoothIdleTimeMs, bluetoothTotalTimeMs));
3317 sb.append(")");
3318 pw.println(sb.toString());
3319
3320 sb.setLength(0);
3321 sb.append(prefix);
3322 sb.append(" Bluetooth Rx time: "); formatTimeMs(sb, bluetoothRxTimeMs);
3323 sb.append(" (");
3324 sb.append(formatRatioLocked(bluetoothRxTimeMs, bluetoothTotalTimeMs));
3325 sb.append(")");
3326 pw.println(sb.toString());
3327
3328 sb.setLength(0);
3329 sb.append(prefix);
3330 sb.append(" Bluetooth Tx time: "); formatTimeMs(sb, bluetoothTxTimeMs);
3331 sb.append(" (");
3332 sb.append(formatRatioLocked(bluetoothTxTimeMs, bluetoothTotalTimeMs));
3333 sb.append(")");
3334 pw.println(sb.toString());
3335
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003336 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003337
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003338 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003339 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003340 pw.print(prefix); pw.println(" Device is currently unplugged");
3341 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3342 pw.println(getDischargeStartLevel());
3343 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3344 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003345 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003346 pw.print(prefix); pw.println(" Device is currently plugged into power");
3347 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3348 pw.println(getDischargeStartLevel());
3349 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3350 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003351 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003352 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3353 pw.println(getDischargeAmountScreenOn());
3354 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3355 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003356 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003357 } else {
3358 pw.print(prefix); pw.println(" Device battery use since last full charge");
3359 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3360 pw.println(getLowDischargeAmountSinceCharge());
3361 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3362 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003363 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3364 pw.println(getDischargeAmountScreenOnSinceCharge());
3365 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3366 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003367 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003368 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003369
Dianne Hackbornd953c532014-08-16 18:17:38 -07003370 BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003371 helper.create(this);
3372 helper.refreshStats(which, UserHandle.USER_ALL);
3373 List<BatterySipper> sippers = helper.getUsageList();
3374 if (sippers != null && sippers.size() > 0) {
3375 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3376 pw.print(prefix); pw.print(" Capacity: ");
3377 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003378 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003379 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3380 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3381 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3382 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003383 pw.println();
3384 for (int i=0; i<sippers.size(); i++) {
3385 BatterySipper bs = sippers.get(i);
3386 switch (bs.drainType) {
3387 case IDLE:
3388 pw.print(prefix); pw.print(" Idle: "); printmAh(pw, bs.value);
3389 pw.println();
3390 break;
3391 case CELL:
3392 pw.print(prefix); pw.print(" Cell standby: "); printmAh(pw, bs.value);
3393 pw.println();
3394 break;
3395 case PHONE:
3396 pw.print(prefix); pw.print(" Phone calls: "); printmAh(pw, bs.value);
3397 pw.println();
3398 break;
3399 case WIFI:
3400 pw.print(prefix); pw.print(" Wifi: "); printmAh(pw, bs.value);
3401 pw.println();
3402 break;
3403 case BLUETOOTH:
3404 pw.print(prefix); pw.print(" Bluetooth: "); printmAh(pw, bs.value);
3405 pw.println();
3406 break;
3407 case SCREEN:
3408 pw.print(prefix); pw.print(" Screen: "); printmAh(pw, bs.value);
3409 pw.println();
3410 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003411 case FLASHLIGHT:
3412 pw.print(prefix); pw.print(" Flashlight: "); printmAh(pw, bs.value);
3413 pw.println();
3414 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003415 case APP:
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003416 pw.print(prefix); pw.print(" Uid ");
3417 UserHandle.formatUid(pw, bs.uidObj.getUid());
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003418 pw.print(": "); printmAh(pw, bs.value); pw.println();
3419 break;
3420 case USER:
3421 pw.print(prefix); pw.print(" User "); pw.print(bs.userId);
3422 pw.print(": "); printmAh(pw, bs.value); pw.println();
3423 break;
3424 case UNACCOUNTED:
3425 pw.print(prefix); pw.print(" Unaccounted: "); printmAh(pw, bs.value);
3426 pw.println();
3427 break;
3428 case OVERCOUNTED:
3429 pw.print(prefix); pw.print(" Over-counted: "); printmAh(pw, bs.value);
3430 pw.println();
3431 break;
3432 }
3433 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08003434 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003435 }
3436
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003437 sippers = helper.getMobilemsppList();
3438 if (sippers != null && sippers.size() > 0) {
3439 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003440 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003441 for (int i=0; i<sippers.size(); i++) {
3442 BatterySipper bs = sippers.get(i);
3443 sb.setLength(0);
3444 sb.append(prefix); sb.append(" Uid ");
3445 UserHandle.formatUid(sb, bs.uidObj.getUid());
3446 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
3447 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
3448 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003449 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003450 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003451 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003452 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003453 sb.setLength(0);
3454 sb.append(prefix);
3455 sb.append(" TOTAL TIME: ");
3456 formatTimeMs(sb, totalTime);
3457 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
3458 sb.append(")");
3459 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003460 pw.println();
3461 }
3462
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003463 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
3464 @Override
3465 public int compare(TimerEntry lhs, TimerEntry rhs) {
3466 long lhsTime = lhs.mTime;
3467 long rhsTime = rhs.mTime;
3468 if (lhsTime < rhsTime) {
3469 return 1;
3470 }
3471 if (lhsTime > rhsTime) {
3472 return -1;
3473 }
3474 return 0;
3475 }
3476 };
3477
3478 if (reqUid < 0) {
3479 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
3480 if (kernelWakelocks.size() > 0) {
3481 final ArrayList<TimerEntry> ktimers = new ArrayList<TimerEntry>();
3482 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
3483 BatteryStats.Timer timer = ent.getValue();
3484 long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
3485 if (totalTimeMillis > 0) {
3486 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
3487 }
3488 }
3489 if (ktimers.size() > 0) {
3490 Collections.sort(ktimers, timerComparator);
3491 pw.print(prefix); pw.println(" All kernel wake locks:");
3492 for (int i=0; i<ktimers.size(); i++) {
3493 TimerEntry timer = ktimers.get(i);
3494 String linePrefix = ": ";
3495 sb.setLength(0);
3496 sb.append(prefix);
3497 sb.append(" Kernel Wake lock ");
3498 sb.append(timer.mName);
3499 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
3500 which, linePrefix);
3501 if (!linePrefix.equals(": ")) {
3502 sb.append(" realtime");
3503 // Only print out wake locks that were held
3504 pw.println(sb.toString());
3505 }
3506 }
3507 pw.println();
3508 }
3509 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003510
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003511 if (timers.size() > 0) {
3512 Collections.sort(timers, timerComparator);
3513 pw.print(prefix); pw.println(" All partial wake locks:");
3514 for (int i=0; i<timers.size(); i++) {
3515 TimerEntry timer = timers.get(i);
3516 sb.setLength(0);
3517 sb.append(" Wake lock ");
3518 UserHandle.formatUid(sb, timer.mId);
3519 sb.append(" ");
3520 sb.append(timer.mName);
3521 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3522 sb.append(" realtime");
3523 pw.println(sb.toString());
3524 }
3525 timers.clear();
3526 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08003527 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003528
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003529 Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003530 if (wakeupReasons.size() > 0) {
3531 pw.print(prefix); pw.println(" All wakeup reasons:");
3532 final ArrayList<TimerEntry> reasons = new ArrayList<TimerEntry>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003533 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3534 Timer timer = ent.getValue();
3535 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
3536 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003537 }
3538 Collections.sort(reasons, timerComparator);
3539 for (int i=0; i<reasons.size(); i++) {
3540 TimerEntry timer = reasons.get(i);
3541 String linePrefix = ": ";
3542 sb.setLength(0);
3543 sb.append(prefix);
3544 sb.append(" Wakeup reason ");
3545 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003546 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3547 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003548 pw.println(sb.toString());
3549 }
3550 pw.println();
3551 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003552 }
Evan Millar22ac0432009-03-31 11:33:18 -07003553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 for (int iu=0; iu<NU; iu++) {
3555 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08003556 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003557 continue;
3558 }
3559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003560 Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07003561
3562 pw.print(prefix);
3563 pw.print(" ");
3564 UserHandle.formatUid(pw, uid);
3565 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003567
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003568 long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3569 long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3570 long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3571 long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3572 long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3573 long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003574 long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
3575 int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003576 long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3577 long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003578 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3579 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003580 int wifiScanCount = u.getWifiScanCount(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003581 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003582
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003583 if (mobileRxBytes > 0 || mobileTxBytes > 0
3584 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003585 pw.print(prefix); pw.print(" Mobile network: ");
3586 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003587 pw.print(formatBytesLocked(mobileTxBytes));
3588 pw.print(" sent (packets "); pw.print(mobileRxPackets);
3589 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003590 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003591 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
3592 sb.setLength(0);
3593 sb.append(prefix); sb.append(" Mobile radio active: ");
3594 formatTimeMs(sb, uidMobileActiveTime / 1000);
3595 sb.append("(");
3596 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
3597 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
3598 long packets = mobileRxPackets + mobileTxPackets;
3599 if (packets == 0) {
3600 packets = 1;
3601 }
3602 sb.append(" @ ");
3603 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
3604 sb.append(" mspp");
3605 pw.println(sb.toString());
3606 }
3607
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003608 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003609 pw.print(prefix); pw.print(" Wi-Fi network: ");
3610 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003611 pw.print(formatBytesLocked(wifiTxBytes));
3612 pw.print(" sent (packets "); pw.print(wifiRxPackets);
3613 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003614 }
3615
Dianne Hackborn62793e42015-03-09 11:15:41 -07003616 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003617 || uidWifiRunningTime != 0) {
3618 sb.setLength(0);
3619 sb.append(prefix); sb.append(" Wifi Running: ");
3620 formatTimeMs(sb, uidWifiRunningTime / 1000);
3621 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
3622 whichBatteryRealtime)); sb.append(")\n");
3623 sb.append(prefix); sb.append(" Full Wifi Lock: ");
3624 formatTimeMs(sb, fullWifiLockOnTime / 1000);
3625 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
3626 whichBatteryRealtime)); sb.append(")\n");
3627 sb.append(prefix); sb.append(" Wifi Scan: ");
3628 formatTimeMs(sb, wifiScanTime / 1000);
3629 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07003630 whichBatteryRealtime)); sb.append(") ");
3631 sb.append(wifiScanCount);
3632 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003633 pw.println(sb.toString());
3634 }
3635
Dianne Hackborn617f8772009-03-31 15:04:46 -07003636 if (u.hasUserActivity()) {
3637 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07003638 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003639 int val = u.getUserActivityCount(i, which);
3640 if (val != 0) {
3641 if (!hasData) {
3642 sb.setLength(0);
3643 sb.append(" User activity: ");
3644 hasData = true;
3645 } else {
3646 sb.append(", ");
3647 }
3648 sb.append(val);
3649 sb.append(" ");
3650 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
3651 }
3652 }
3653 if (hasData) {
3654 pw.println(sb.toString());
3655 }
3656 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657
3658 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
3659 if (wakelocks.size() > 0) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003660 long totalFull = 0, totalPartial = 0, totalWindow = 0;
3661 int count = 0;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003662 for (Map.Entry<String, ? extends Uid.Wakelock> ent : wakelocks.entrySet()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 Uid.Wakelock wl = ent.getValue();
3664 String linePrefix = ": ";
3665 sb.setLength(0);
3666 sb.append(prefix);
3667 sb.append(" Wake lock ");
3668 sb.append(ent.getKey());
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003669 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 "full", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003671 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003672 "partial", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003673 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 "window", which, linePrefix);
Dianne Hackbornacc4a122014-08-18 16:33:44 -07003675 if (true || !linePrefix.equals(": ")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003676 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05003677 // Only print out wake locks that were held
3678 pw.println(sb.toString());
3679 uidActivity = true;
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003680 count++;
3681 }
3682 totalFull += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003683 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003684 totalPartial += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003685 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003686 totalWindow += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003687 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003688 }
3689 if (count > 1) {
3690 if (totalFull != 0 || totalPartial != 0 || totalWindow != 0) {
3691 sb.setLength(0);
3692 sb.append(prefix);
3693 sb.append(" TOTAL wake: ");
3694 boolean needComma = false;
3695 if (totalFull != 0) {
3696 needComma = true;
3697 formatTimeMs(sb, totalFull);
3698 sb.append("full");
3699 }
3700 if (totalPartial != 0) {
3701 if (needComma) {
3702 sb.append(", ");
3703 }
3704 needComma = true;
3705 formatTimeMs(sb, totalPartial);
3706 sb.append("partial");
3707 }
3708 if (totalWindow != 0) {
3709 if (needComma) {
3710 sb.append(", ");
3711 }
3712 needComma = true;
3713 formatTimeMs(sb, totalWindow);
3714 sb.append("window");
3715 }
3716 sb.append(" realtime");
3717 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003718 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003719 }
3720 }
3721
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003722 Map<String, ? extends Timer> syncs = u.getSyncStats();
3723 if (syncs.size() > 0) {
3724 for (Map.Entry<String, ? extends Timer> ent : syncs.entrySet()) {
3725 Timer timer = ent.getValue();
3726 // Convert from microseconds to milliseconds with rounding
3727 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3728 int count = timer.getCountLocked(which);
3729 sb.setLength(0);
3730 sb.append(prefix);
3731 sb.append(" Sync ");
3732 sb.append(ent.getKey());
3733 sb.append(": ");
3734 if (totalTime != 0) {
3735 formatTimeMs(sb, totalTime);
3736 sb.append("realtime (");
3737 sb.append(count);
3738 sb.append(" times)");
3739 } else {
3740 sb.append("(not used)");
3741 }
3742 pw.println(sb.toString());
3743 uidActivity = true;
3744 }
3745 }
3746
3747 Map<String, ? extends Timer> jobs = u.getJobStats();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003748 if (jobs.size() > 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003749 for (Map.Entry<String, ? extends Timer> ent : jobs.entrySet()) {
3750 Timer timer = ent.getValue();
3751 // Convert from microseconds to milliseconds with rounding
3752 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3753 int count = timer.getCountLocked(which);
3754 sb.setLength(0);
3755 sb.append(prefix);
3756 sb.append(" Job ");
3757 sb.append(ent.getKey());
3758 sb.append(": ");
3759 if (totalTime != 0) {
3760 formatTimeMs(sb, totalTime);
3761 sb.append("realtime (");
3762 sb.append(count);
3763 sb.append(" times)");
3764 } else {
3765 sb.append("(not used)");
3766 }
3767 pw.println(sb.toString());
3768 uidActivity = true;
3769 }
3770 }
3771
Dianne Hackborn61659e52014-07-09 16:13:01 -07003772 SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3773 int NSE = sensors.size();
3774 for (int ise=0; ise<NSE; ise++) {
3775 Uid.Sensor se = sensors.valueAt(ise);
3776 int sensorNumber = sensors.keyAt(ise);
3777 sb.setLength(0);
3778 sb.append(prefix);
3779 sb.append(" Sensor ");
3780 int handle = se.getHandle();
3781 if (handle == Uid.Sensor.GPS) {
3782 sb.append("GPS");
3783 } else {
3784 sb.append(handle);
3785 }
3786 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003787
Dianne Hackborn61659e52014-07-09 16:13:01 -07003788 Timer timer = se.getSensorTime();
3789 if (timer != null) {
3790 // Convert from microseconds to milliseconds with rounding
3791 long totalTime = (timer.getTotalTimeLocked(
3792 rawRealtime, which) + 500) / 1000;
3793 int count = timer.getCountLocked(which);
3794 //timer.logState();
3795 if (totalTime != 0) {
3796 formatTimeMs(sb, totalTime);
3797 sb.append("realtime (");
3798 sb.append(count);
3799 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 } else {
3801 sb.append("(not used)");
3802 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003803 } else {
3804 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003806
3807 pw.println(sb.toString());
3808 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 }
3810
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003811 Timer vibTimer = u.getVibratorOnTimer();
3812 if (vibTimer != null) {
3813 // Convert from microseconds to milliseconds with rounding
3814 long totalTime = (vibTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003815 rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003816 int count = vibTimer.getCountLocked(which);
3817 //timer.logState();
3818 if (totalTime != 0) {
3819 sb.setLength(0);
3820 sb.append(prefix);
3821 sb.append(" Vibrator: ");
3822 formatTimeMs(sb, totalTime);
3823 sb.append("realtime (");
3824 sb.append(count);
3825 sb.append(" times)");
3826 pw.println(sb.toString());
3827 uidActivity = true;
3828 }
3829 }
3830
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003831 Timer fgTimer = u.getForegroundActivityTimer();
3832 if (fgTimer != null) {
3833 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003834 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003835 int count = fgTimer.getCountLocked(which);
3836 if (totalTime != 0) {
3837 sb.setLength(0);
3838 sb.append(prefix);
3839 sb.append(" Foreground activities: ");
3840 formatTimeMs(sb, totalTime);
3841 sb.append("realtime (");
3842 sb.append(count);
3843 sb.append(" times)");
3844 pw.println(sb.toString());
3845 uidActivity = true;
3846 }
3847 }
3848
Dianne Hackborn61659e52014-07-09 16:13:01 -07003849 long totalStateTime = 0;
3850 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
3851 long time = u.getProcessStateTime(ips, rawRealtime, which);
3852 if (time > 0) {
3853 totalStateTime += time;
3854 sb.setLength(0);
3855 sb.append(prefix);
3856 sb.append(" ");
3857 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
3858 sb.append(" for: ");
3859 formatTimeMs(sb, (totalStateTime + 500) / 1000);
3860 pw.println(sb.toString());
3861 uidActivity = true;
3862 }
3863 }
3864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
3866 if (processStats.size() > 0) {
3867 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
3868 : processStats.entrySet()) {
3869 Uid.Proc ps = ent.getValue();
3870 long userTime;
3871 long systemTime;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003872 long foregroundTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003873 int starts;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003874 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875
3876 userTime = ps.getUserTime(which);
3877 systemTime = ps.getSystemTime(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003878 foregroundTime = ps.getForegroundTime(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 starts = ps.getStarts(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003880 final int numCrashes = ps.getNumCrashes(which);
3881 final int numAnrs = ps.getNumAnrs(which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003882 numExcessive = which == STATS_SINCE_CHARGED
Dianne Hackborn287952c2010-09-22 22:34:31 -07003883 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003884
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003885 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003886 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003887 sb.setLength(0);
3888 sb.append(prefix); sb.append(" Proc ");
3889 sb.append(ent.getKey()); sb.append(":\n");
3890 sb.append(prefix); sb.append(" CPU: ");
Dianne Hackborn62793e42015-03-09 11:15:41 -07003891 formatTimeMs(sb, userTime); sb.append("usr + ");
3892 formatTimeMs(sb, systemTime); sb.append("krn ; ");
3893 formatTimeMs(sb, foregroundTime); sb.append("fg");
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003894 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
Dianne Hackbornb8071d792010-09-09 16:45:15 -07003895 sb.append("\n"); sb.append(prefix); sb.append(" ");
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003896 boolean hasOne = false;
3897 if (starts != 0) {
3898 hasOne = true;
3899 sb.append(starts); sb.append(" starts");
3900 }
3901 if (numCrashes != 0) {
3902 if (hasOne) {
3903 sb.append(", ");
3904 }
3905 hasOne = true;
3906 sb.append(numCrashes); sb.append(" crashes");
3907 }
3908 if (numAnrs != 0) {
3909 if (hasOne) {
3910 sb.append(", ");
3911 }
3912 sb.append(numAnrs); sb.append(" anrs");
3913 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -07003914 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003915 pw.println(sb.toString());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003916 for (int e=0; e<numExcessive; e++) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07003917 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003918 if (ew != null) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07003919 pw.print(prefix); pw.print(" * Killed for ");
3920 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
3921 pw.print("wake lock");
3922 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
3923 pw.print("cpu");
3924 } else {
3925 pw.print("unknown");
3926 }
3927 pw.print(" use: ");
Dianne Hackborn1ebccf52010-08-15 13:04:34 -07003928 TimeUtils.formatDuration(ew.usedTime, pw);
3929 pw.print(" over ");
3930 TimeUtils.formatDuration(ew.overTime, pw);
Robert Greenwalta029ea12013-09-25 16:38:12 -07003931 if (ew.overTime != 0) {
3932 pw.print(" (");
3933 pw.print((ew.usedTime*100)/ew.overTime);
3934 pw.println("%)");
3935 }
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003936 }
3937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003938 uidActivity = true;
3939 }
3940 }
3941 }
3942
3943 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
3944 if (packageStats.size() > 0) {
3945 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
3946 : packageStats.entrySet()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003947 pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 boolean apkActivity = false;
3949 Uid.Pkg ps = ent.getValue();
3950 int wakeups = ps.getWakeups(which);
3951 if (wakeups != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003952 pw.print(prefix); pw.print(" ");
3953 pw.print(wakeups); pw.println(" wakeup alarms");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003954 apkActivity = true;
3955 }
3956 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3957 if (serviceStats.size() > 0) {
3958 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
3959 : serviceStats.entrySet()) {
3960 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
3961 long startTime = ss.getStartTime(batteryUptime, which);
3962 int starts = ss.getStarts(which);
3963 int launches = ss.getLaunches(which);
3964 if (startTime != 0 || starts != 0 || launches != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003965 sb.setLength(0);
3966 sb.append(prefix); sb.append(" Service ");
3967 sb.append(sent.getKey()); sb.append(":\n");
3968 sb.append(prefix); sb.append(" Created for: ");
3969 formatTimeMs(sb, startTime / 1000);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003970 sb.append("uptime\n");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003971 sb.append(prefix); sb.append(" Starts: ");
3972 sb.append(starts);
3973 sb.append(", launches: "); sb.append(launches);
3974 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 apkActivity = true;
3976 }
3977 }
3978 }
3979 if (!apkActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003980 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 }
3982 uidActivity = true;
3983 }
3984 }
3985 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003986 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 }
3988 }
3989 }
3990
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003991 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003992 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003993 int diff = oldval ^ newval;
3994 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003995 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003996 for (int i=0; i<descriptions.length; i++) {
3997 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003998 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003999 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004000 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004001 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004002 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004003 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
4004 didWake = true;
4005 pw.print("=");
4006 if (longNames) {
4007 UserHandle.formatUid(pw, wakelockTag.uid);
4008 pw.print(":\"");
4009 pw.print(wakelockTag.string);
4010 pw.print("\"");
4011 } else {
4012 pw.print(wakelockTag.poolIdx);
4013 }
4014 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004015 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004016 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004017 pw.print("=");
4018 int val = (newval&bd.mask)>>bd.shift;
4019 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004020 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004021 } else {
4022 pw.print(val);
4023 }
4024 }
4025 }
4026 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004027 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07004028 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004029 if (longNames) {
4030 UserHandle.formatUid(pw, wakelockTag.uid);
4031 pw.print(":\"");
4032 pw.print(wakelockTag.string);
4033 pw.print("\"");
4034 } else {
4035 pw.print(wakelockTag.poolIdx);
4036 }
4037 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07004038 }
4039
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004040 public void prepareForDumpLocked() {
4041 }
4042
4043 public static class HistoryPrinter {
4044 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004045 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004046 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004047 int oldStatus = -1;
4048 int oldHealth = -1;
4049 int oldPlug = -1;
4050 int oldTemp = -1;
4051 int oldVolt = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004052 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004053
Dianne Hackborn3251b902014-06-20 14:40:53 -07004054 void reset() {
4055 oldState = oldState2 = 0;
4056 oldLevel = -1;
4057 oldStatus = -1;
4058 oldHealth = -1;
4059 oldPlug = -1;
4060 oldTemp = -1;
4061 oldVolt = -1;
4062 }
4063
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004064 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004065 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004066 if (!checkin) {
4067 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004068 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004069 pw.print(" (");
4070 pw.print(rec.numReadInts);
4071 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004072 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004073 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4074 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004075 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004076 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004077 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004078 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004079 }
4080 lastTime = rec.time;
4081 }
4082 if (rec.cmd == HistoryItem.CMD_START) {
4083 if (checkin) {
4084 pw.print(":");
4085 }
4086 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004087 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004088 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
4089 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004090 if (checkin) {
4091 pw.print(":");
4092 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004093 if (rec.cmd == HistoryItem.CMD_RESET) {
4094 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004095 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004096 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004097 pw.print("TIME:");
4098 if (checkin) {
4099 pw.println(rec.currentTime);
4100 } else {
4101 pw.print(" ");
4102 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4103 rec.currentTime).toString());
4104 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004105 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4106 if (checkin) {
4107 pw.print(":");
4108 }
4109 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004110 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4111 if (checkin) {
4112 pw.print(":");
4113 }
4114 pw.println("*OVERFLOW*");
4115 } else {
4116 if (!checkin) {
4117 if (rec.batteryLevel < 10) pw.print("00");
4118 else if (rec.batteryLevel < 100) pw.print("0");
4119 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004120 if (verbose) {
4121 pw.print(" ");
4122 if (rec.states < 0) ;
4123 else if (rec.states < 0x10) pw.print("0000000");
4124 else if (rec.states < 0x100) pw.print("000000");
4125 else if (rec.states < 0x1000) pw.print("00000");
4126 else if (rec.states < 0x10000) pw.print("0000");
4127 else if (rec.states < 0x100000) pw.print("000");
4128 else if (rec.states < 0x1000000) pw.print("00");
4129 else if (rec.states < 0x10000000) pw.print("0");
4130 pw.print(Integer.toHexString(rec.states));
4131 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004132 } else {
4133 if (oldLevel != rec.batteryLevel) {
4134 oldLevel = rec.batteryLevel;
4135 pw.print(",Bl="); pw.print(rec.batteryLevel);
4136 }
4137 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004138 if (oldStatus != rec.batteryStatus) {
4139 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004140 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004141 switch (oldStatus) {
4142 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004143 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004144 break;
4145 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004146 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004147 break;
4148 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004149 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004150 break;
4151 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004152 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004153 break;
4154 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004155 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004156 break;
4157 default:
4158 pw.print(oldStatus);
4159 break;
4160 }
4161 }
4162 if (oldHealth != rec.batteryHealth) {
4163 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004164 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004165 switch (oldHealth) {
4166 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004167 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004168 break;
4169 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004170 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004171 break;
4172 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004173 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004174 break;
4175 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004176 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004177 break;
4178 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004179 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004180 break;
4181 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004182 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004183 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004184 case BatteryManager.BATTERY_HEALTH_COLD:
4185 pw.print(checkin ? "c" : "cold");
4186 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004187 default:
4188 pw.print(oldHealth);
4189 break;
4190 }
4191 }
4192 if (oldPlug != rec.batteryPlugType) {
4193 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004194 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004195 switch (oldPlug) {
4196 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004197 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004198 break;
4199 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004200 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004201 break;
4202 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004203 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004204 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004205 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004206 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004207 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004208 default:
4209 pw.print(oldPlug);
4210 break;
4211 }
4212 }
4213 if (oldTemp != rec.batteryTemperature) {
4214 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004215 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004216 pw.print(oldTemp);
4217 }
4218 if (oldVolt != rec.batteryVoltage) {
4219 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004220 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004221 pw.print(oldVolt);
4222 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004223 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004224 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004225 printBitDescriptions(pw, oldState2, rec.states2, null,
4226 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004227 if (rec.wakeReasonTag != null) {
4228 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004229 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004230 pw.print(rec.wakeReasonTag.poolIdx);
4231 } else {
4232 pw.print(" wake_reason=");
4233 pw.print(rec.wakeReasonTag.uid);
4234 pw.print(":\"");
4235 pw.print(rec.wakeReasonTag.string);
4236 pw.print("\"");
4237 }
4238 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004239 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004240 pw.print(checkin ? "," : " ");
4241 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4242 pw.print("+");
4243 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4244 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004245 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004246 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4247 : HISTORY_EVENT_NAMES;
4248 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4249 | HistoryItem.EVENT_FLAG_FINISH);
4250 if (idx >= 0 && idx < eventNames.length) {
4251 pw.print(eventNames[idx]);
4252 } else {
4253 pw.print(checkin ? "Ev" : "event");
4254 pw.print(idx);
4255 }
4256 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004257 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004258 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004259 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004260 UserHandle.formatUid(pw, rec.eventTag.uid);
4261 pw.print(":\"");
4262 pw.print(rec.eventTag.string);
4263 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004264 }
4265 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004266 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004267 if (rec.stepDetails != null) {
4268 if (!checkin) {
4269 pw.print(" Details: cpu=");
4270 pw.print(rec.stepDetails.userTime);
4271 pw.print("u+");
4272 pw.print(rec.stepDetails.systemTime);
4273 pw.print("s");
4274 if (rec.stepDetails.appCpuUid1 >= 0) {
4275 pw.print(" (");
4276 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4277 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4278 if (rec.stepDetails.appCpuUid2 >= 0) {
4279 pw.print(", ");
4280 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4281 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4282 }
4283 if (rec.stepDetails.appCpuUid3 >= 0) {
4284 pw.print(", ");
4285 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4286 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4287 }
4288 pw.print(')');
4289 }
4290 pw.println();
4291 pw.print(" /proc/stat=");
4292 pw.print(rec.stepDetails.statUserTime);
4293 pw.print(" usr, ");
4294 pw.print(rec.stepDetails.statSystemTime);
4295 pw.print(" sys, ");
4296 pw.print(rec.stepDetails.statIOWaitTime);
4297 pw.print(" io, ");
4298 pw.print(rec.stepDetails.statIrqTime);
4299 pw.print(" irq, ");
4300 pw.print(rec.stepDetails.statSoftIrqTime);
4301 pw.print(" sirq, ");
4302 pw.print(rec.stepDetails.statIdlTime);
4303 pw.print(" idle");
4304 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4305 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4306 + rec.stepDetails.statSoftIrqTime;
4307 int total = totalRun + rec.stepDetails.statIdlTime;
4308 if (total > 0) {
4309 pw.print(" (");
4310 float perc = ((float)totalRun) / ((float)total) * 100;
4311 pw.print(String.format("%.1f%%", perc));
4312 pw.print(" of ");
4313 StringBuilder sb = new StringBuilder(64);
4314 formatTimeMsNoSpace(sb, total*10);
4315 pw.print(sb);
4316 pw.print(")");
4317 }
4318 pw.println();
4319 } else {
4320 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4321 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4322 pw.print(rec.stepDetails.userTime);
4323 pw.print(":");
4324 pw.print(rec.stepDetails.systemTime);
4325 if (rec.stepDetails.appCpuUid1 >= 0) {
4326 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4327 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4328 if (rec.stepDetails.appCpuUid2 >= 0) {
4329 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4330 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4331 }
4332 if (rec.stepDetails.appCpuUid3 >= 0) {
4333 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4334 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4335 }
4336 }
4337 pw.println();
4338 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4339 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4340 pw.print(rec.stepDetails.statUserTime);
4341 pw.print(',');
4342 pw.print(rec.stepDetails.statSystemTime);
4343 pw.print(',');
4344 pw.print(rec.stepDetails.statIOWaitTime);
4345 pw.print(',');
4346 pw.print(rec.stepDetails.statIrqTime);
4347 pw.print(',');
4348 pw.print(rec.stepDetails.statSoftIrqTime);
4349 pw.print(',');
4350 pw.print(rec.stepDetails.statIdlTime);
4351 pw.println();
4352 }
4353 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004354 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004355 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004356 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004357 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004358
4359 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4360 UserHandle.formatUid(pw, uid);
4361 pw.print("=");
4362 pw.print(utime);
4363 pw.print("u+");
4364 pw.print(stime);
4365 pw.print("s");
4366 }
4367
4368 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
4369 pw.print('/');
4370 pw.print(uid);
4371 pw.print(":");
4372 pw.print(utime);
4373 pw.print(":");
4374 pw.print(stime);
4375 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004376 }
4377
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004378 private void printSizeValue(PrintWriter pw, long size) {
4379 float result = size;
4380 String suffix = "";
4381 if (result >= 10*1024) {
4382 suffix = "KB";
4383 result = result / 1024;
4384 }
4385 if (result >= 10*1024) {
4386 suffix = "MB";
4387 result = result / 1024;
4388 }
4389 if (result >= 10*1024) {
4390 suffix = "GB";
4391 result = result / 1024;
4392 }
4393 if (result >= 10*1024) {
4394 suffix = "TB";
4395 result = result / 1024;
4396 }
4397 if (result >= 10*1024) {
4398 suffix = "PB";
4399 result = result / 1024;
4400 }
4401 pw.print((int)result);
4402 pw.print(suffix);
4403 }
4404
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004405 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
4406 String label3, long estimatedTime) {
4407 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004408 return false;
4409 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004410 pw.print(label1);
4411 pw.print(label2);
4412 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004413 StringBuilder sb = new StringBuilder(64);
4414 formatTimeMs(sb, estimatedTime);
4415 pw.print(sb);
4416 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004417 return true;
4418 }
4419
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004420 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
4421 LevelStepTracker steps, boolean checkin) {
4422 if (steps == null) {
4423 return false;
4424 }
4425 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004426 if (count <= 0) {
4427 return false;
4428 }
4429 if (!checkin) {
4430 pw.println(header);
4431 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004432 String[] lineArgs = new String[4];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004433 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004434 long duration = steps.getDurationAt(i);
4435 int level = steps.getLevelAt(i);
4436 long initMode = steps.getInitModeAt(i);
4437 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004438 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004439 lineArgs[0] = Long.toString(duration);
4440 lineArgs[1] = Integer.toString(level);
4441 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4442 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4443 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
4444 case Display.STATE_ON: lineArgs[2] = "s+"; break;
4445 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
4446 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
4447 default: lineArgs[1] = "?"; break;
4448 }
4449 } else {
4450 lineArgs[2] = "";
4451 }
4452 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4453 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
4454 } else {
4455 lineArgs[3] = "";
4456 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004457 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
4458 lineArgs[3] = (initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0 ? "i+" : "i-";
4459 } else {
4460 lineArgs[3] = "";
4461 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004462 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
4463 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004464 pw.print(prefix);
4465 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004466 TimeUtils.formatDuration(duration, pw);
4467 pw.print(" to "); pw.print(level);
4468 boolean haveModes = false;
4469 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4470 pw.print(" (");
4471 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4472 case Display.STATE_OFF: pw.print("screen-off"); break;
4473 case Display.STATE_ON: pw.print("screen-on"); break;
4474 case Display.STATE_DOZE: pw.print("screen-doze"); break;
4475 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
4476 default: lineArgs[1] = "screen-?"; break;
4477 }
4478 haveModes = true;
4479 }
4480 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4481 pw.print(haveModes ? ", " : " (");
4482 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
4483 ? "power-save-on" : "power-save-off");
4484 haveModes = true;
4485 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004486 if ((modMode&STEP_LEVEL_MODE_DEVICE_IDLE) == 0) {
4487 pw.print(haveModes ? ", " : " (");
4488 pw.print((initMode&STEP_LEVEL_MODE_DEVICE_IDLE) != 0
4489 ? "device-idle-on" : "device-idle-off");
4490 haveModes = true;
4491 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004492 if (haveModes) {
4493 pw.print(")");
4494 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004495 pw.println();
4496 }
4497 }
4498 return true;
4499 }
4500
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004501 public static final int DUMP_UNPLUGGED_ONLY = 1<<0;
4502 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004503 public static final int DUMP_DAILY_ONLY = 1<<2;
4504 public static final int DUMP_HISTORY_ONLY = 1<<3;
4505 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
4506 public static final int DUMP_VERBOSE = 1<<5;
4507 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004508
Dianne Hackborn37de0982014-05-09 09:32:18 -07004509 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
4510 final HistoryPrinter hprinter = new HistoryPrinter();
4511 final HistoryItem rec = new HistoryItem();
4512 long lastTime = -1;
4513 long baseTime = -1;
4514 boolean printed = false;
4515 HistoryEventTracker tracker = null;
4516 while (getNextHistoryLocked(rec)) {
4517 lastTime = rec.time;
4518 if (baseTime < 0) {
4519 baseTime = lastTime;
4520 }
4521 if (rec.time >= histStart) {
4522 if (histStart >= 0 && !printed) {
4523 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07004524 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004525 || rec.cmd == HistoryItem.CMD_START
4526 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004527 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004528 hprinter.printNextItem(pw, rec, baseTime, checkin,
4529 (flags&DUMP_VERBOSE) != 0);
4530 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004531 } else if (rec.currentTime != 0) {
4532 printed = true;
4533 byte cmd = rec.cmd;
4534 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004535 hprinter.printNextItem(pw, rec, baseTime, checkin,
4536 (flags&DUMP_VERBOSE) != 0);
4537 rec.cmd = cmd;
4538 }
4539 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004540 if (rec.cmd != HistoryItem.CMD_UPDATE) {
4541 hprinter.printNextItem(pw, rec, baseTime, checkin,
4542 (flags&DUMP_VERBOSE) != 0);
4543 rec.cmd = HistoryItem.CMD_UPDATE;
4544 }
4545 int oldEventCode = rec.eventCode;
4546 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004547 rec.eventTag = new HistoryTag();
4548 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
4549 HashMap<String, SparseIntArray> active
4550 = tracker.getStateForEvent(i);
4551 if (active == null) {
4552 continue;
4553 }
4554 for (HashMap.Entry<String, SparseIntArray> ent
4555 : active.entrySet()) {
4556 SparseIntArray uids = ent.getValue();
4557 for (int j=0; j<uids.size(); j++) {
4558 rec.eventCode = i;
4559 rec.eventTag.string = ent.getKey();
4560 rec.eventTag.uid = uids.keyAt(j);
4561 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07004562 hprinter.printNextItem(pw, rec, baseTime, checkin,
4563 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004564 rec.wakeReasonTag = null;
4565 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004566 }
4567 }
4568 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004569 rec.eventCode = oldEventCode;
4570 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004571 tracker = null;
4572 }
4573 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004574 hprinter.printNextItem(pw, rec, baseTime, checkin,
4575 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07004576 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
4577 // This is an attempt to aggregate the previous state and generate
4578 // fake events to reflect that state at the point where we start
4579 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07004580 if (tracker == null) {
4581 tracker = new HistoryEventTracker();
4582 }
4583 tracker.updateState(rec.eventCode, rec.eventTag.string,
4584 rec.eventTag.uid, rec.eventTag.poolIdx);
4585 }
4586 }
4587 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07004588 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004589 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
4590 }
4591 }
4592
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004593 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
4594 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
4595 if (steps == null) {
4596 return;
4597 }
4598 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
4599 if (timeRemaining >= 0) {
4600 pw.print(prefix); pw.print(label); pw.print(" total time: ");
4601 tmpSb.setLength(0);
4602 formatTimeMs(tmpSb, timeRemaining);
4603 pw.print(tmpSb);
4604 pw.print(" (from "); pw.print(tmpOutInt[0]);
4605 pw.println(" steps)");
4606 }
4607 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
4608 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
4609 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
4610 if (estimatedTime > 0) {
4611 pw.print(prefix); pw.print(label); pw.print(" ");
4612 pw.print(STEP_LEVEL_MODE_LABELS[i]);
4613 pw.print(" time: ");
4614 tmpSb.setLength(0);
4615 formatTimeMs(tmpSb, estimatedTime);
4616 pw.print(tmpSb);
4617 pw.print(" (from "); pw.print(tmpOutInt[0]);
4618 pw.println(" steps)");
4619 }
4620 }
4621 }
4622
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004623 private void dumpDailyPackageChanges(PrintWriter pw, String prefix,
4624 ArrayList<PackageChange> changes) {
4625 if (changes == null) {
4626 return;
4627 }
4628 pw.print(prefix); pw.println("Package changes:");
4629 for (int i=0; i<changes.size(); i++) {
4630 PackageChange pc = changes.get(i);
4631 if (pc.mUpdate) {
4632 pw.print(prefix); pw.print(" Update "); pw.print(pc.mPackageName);
4633 pw.print(" vers="); pw.println(pc.mVersionCode);
4634 } else {
4635 pw.print(prefix); pw.print(" Uninstall "); pw.println(pc.mPackageName);
4636 }
4637 }
4638 }
4639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004640 /**
4641 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
4642 *
4643 * @param pw a Printer to receive the dump output.
4644 */
4645 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004646 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004647 prepareForDumpLocked();
4648
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004649 final boolean filtering = (flags
4650 & (DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004651
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004652 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004653 final long historyTotalSize = getHistoryTotalSize();
4654 final long historyUsedSize = getHistoryUsedSize();
4655 if (startIteratingHistoryLocked()) {
4656 try {
4657 pw.print("Battery History (");
4658 pw.print((100*historyUsedSize)/historyTotalSize);
4659 pw.print("% used, ");
4660 printSizeValue(pw, historyUsedSize);
4661 pw.print(" used of ");
4662 printSizeValue(pw, historyTotalSize);
4663 pw.print(", ");
4664 pw.print(getHistoryStringPoolSize());
4665 pw.print(" strings using ");
4666 printSizeValue(pw, getHistoryStringPoolBytes());
4667 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07004668 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004669 pw.println();
4670 } finally {
4671 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004672 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004673 }
4674
4675 if (startIteratingOldHistoryLocked()) {
4676 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004677 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004678 pw.println("Old battery History:");
4679 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004680 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004681 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004682 if (baseTime < 0) {
4683 baseTime = rec.time;
4684 }
4685 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004686 }
4687 pw.println();
4688 } finally {
4689 finishIteratingOldHistoryLocked();
4690 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07004691 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004692 }
4693
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004694 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08004695 return;
4696 }
4697
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004698 if (!filtering) {
4699 SparseArray<? extends Uid> uidStats = getUidStats();
4700 final int NU = uidStats.size();
4701 boolean didPid = false;
4702 long nowRealtime = SystemClock.elapsedRealtime();
4703 for (int i=0; i<NU; i++) {
4704 Uid uid = uidStats.valueAt(i);
4705 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
4706 if (pids != null) {
4707 for (int j=0; j<pids.size(); j++) {
4708 Uid.Pid pid = pids.valueAt(j);
4709 if (!didPid) {
4710 pw.println("Per-PID Stats:");
4711 didPid = true;
4712 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004713 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
4714 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004715 pw.print(" PID "); pw.print(pids.keyAt(j));
4716 pw.print(" wake time: ");
4717 TimeUtils.formatDuration(time, pw);
4718 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004719 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004720 }
4721 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004722 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004723 pw.println();
4724 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004725 }
4726
4727 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004728 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
4729 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004730 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
4731 if (timeRemaining >= 0) {
4732 pw.print(" Estimated discharge time remaining: ");
4733 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4734 pw.println();
4735 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004736 final LevelStepTracker steps = getDischargeLevelStepTracker();
4737 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
4738 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
4739 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
4740 STEP_LEVEL_MODE_VALUES[i], null));
4741 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004742 pw.println();
4743 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004744 if (dumpDurationSteps(pw, " ", "Charge step durations:",
4745 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004746 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
4747 if (timeRemaining >= 0) {
4748 pw.print(" Estimated charge time remaining: ");
4749 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4750 pw.println();
4751 }
4752 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004753 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004754 }
4755 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
4756 pw.println("Daily stats:");
4757 pw.print(" Current start time: ");
4758 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4759 getCurrentDailyStartTime()).toString());
4760 pw.print(" Next min deadline: ");
4761 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4762 getNextMinDailyDeadline()).toString());
4763 pw.print(" Next max deadline: ");
4764 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4765 getNextMaxDailyDeadline()).toString());
4766 StringBuilder sb = new StringBuilder(64);
4767 int[] outInt = new int[1];
4768 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
4769 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004770 ArrayList<PackageChange> pkgc = getDailyPackageChanges();
4771 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0 || pkgc != null) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004772 if ((flags&DUMP_DAILY_ONLY) != 0) {
4773 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
4774 dsteps, false)) {
4775 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
4776 sb, outInt);
4777 }
4778 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
4779 csteps, false)) {
4780 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
4781 sb, outInt);
4782 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004783 dumpDailyPackageChanges(pw, " ", pkgc);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004784 } else {
4785 pw.println(" Current daily steps:");
4786 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
4787 sb, outInt);
4788 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
4789 sb, outInt);
4790 }
4791 }
4792 DailyItem dit;
4793 int curIndex = 0;
4794 while ((dit=getDailyItemLocked(curIndex)) != null) {
4795 curIndex++;
4796 if ((flags&DUMP_DAILY_ONLY) != 0) {
4797 pw.println();
4798 }
4799 pw.print(" Daily from ");
4800 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
4801 pw.print(" to ");
4802 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
4803 pw.println(":");
4804 if ((flags&DUMP_DAILY_ONLY) != 0) {
4805 if (dumpDurationSteps(pw, " ",
4806 " Discharge step durations:", dit.mDischargeSteps, false)) {
4807 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
4808 sb, outInt);
4809 }
4810 if (dumpDurationSteps(pw, " ",
4811 " Charge step durations:", dit.mChargeSteps, false)) {
4812 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
4813 sb, outInt);
4814 }
Dianne Hackborn88e98df2015-03-23 13:29:14 -07004815 dumpDailyPackageChanges(pw, " ", dit.mPackageChanges);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004816 } else {
4817 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
4818 sb, outInt);
4819 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
4820 sb, outInt);
4821 }
4822 }
4823 pw.println();
4824 }
4825 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004826 pw.println("Statistics since last charge:");
4827 pw.println(" System starts: " + getStartCount()
4828 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07004829 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
4830 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004831 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004832 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004833 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
4834 pw.println("Statistics since last unplugged:");
Dianne Hackbornd953c532014-08-16 18:17:38 -07004835 dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid,
4836 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004837 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004838 }
4839
4840 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004841 public void dumpCheckinLocked(Context context, PrintWriter pw,
4842 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004843 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004844
4845 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn8ad2af72015-03-17 17:00:24 -07004846 "13", getParcelVersion(), getStartPlatformVersion(), getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004847
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004848 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
4849
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004850 final boolean filtering = (flags &
4851 (DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004852
4853 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07004854 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004855 try {
4856 for (int i=0; i<getHistoryStringPoolSize(); i++) {
4857 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4858 pw.print(HISTORY_STRING_POOL); pw.print(',');
4859 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004860 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004861 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004862 pw.print(",\"");
4863 String str = getHistoryTagPoolString(i);
4864 str = str.replace("\\", "\\\\");
4865 str = str.replace("\"", "\\\"");
4866 pw.print(str);
4867 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004868 pw.println();
4869 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004870 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004871 } finally {
4872 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08004873 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004874 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004875 }
4876
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004877 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08004878 return;
4879 }
4880
Dianne Hackborne4a59512010-12-07 11:08:07 -08004881 if (apps != null) {
4882 SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
4883 for (int i=0; i<apps.size(); i++) {
4884 ApplicationInfo ai = apps.get(i);
4885 ArrayList<String> pkgs = uids.get(ai.uid);
4886 if (pkgs == null) {
4887 pkgs = new ArrayList<String>();
4888 uids.put(ai.uid, pkgs);
4889 }
4890 pkgs.add(ai.packageName);
4891 }
4892 SparseArray<? extends Uid> uidStats = getUidStats();
4893 final int NU = uidStats.size();
4894 String[] lineArgs = new String[2];
4895 for (int i=0; i<NU; i++) {
4896 int uid = uidStats.keyAt(i);
4897 ArrayList<String> pkgs = uids.get(uid);
4898 if (pkgs != null) {
4899 for (int j=0; j<pkgs.size(); j++) {
4900 lineArgs[0] = Integer.toString(uid);
4901 lineArgs[1] = pkgs.get(j);
4902 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
4903 (Object[])lineArgs);
4904 }
4905 }
4906 }
4907 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004908 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004909 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004910 String[] lineArgs = new String[1];
4911 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
4912 if (timeRemaining >= 0) {
4913 lineArgs[0] = Long.toString(timeRemaining);
4914 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
4915 (Object[])lineArgs);
4916 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004917 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004918 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
4919 if (timeRemaining >= 0) {
4920 lineArgs[0] = Long.toString(timeRemaining);
4921 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
4922 (Object[])lineArgs);
4923 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07004924 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
4925 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004926 }
4927 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
Dianne Hackbornd953c532014-08-16 18:17:38 -07004928 dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1,
4929 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 }
4931 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004932}