blob: 4dadda2d7a6e0bcb51792f52231f5798302a0cba [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
Robert Greenwalt5347bd42009-05-13 15:10:16 -070088 /**
89 * A constant indicating a wifi multicast timer
Robert Greenwalt5347bd42009-05-13 15:10:16 -070090 */
91 public static final int WIFI_MULTICAST_ENABLED = 7;
92
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);
355 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
356 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
357 public abstract long getAudioTurnedOnTime(long elapsedRealtimeUs, int which);
358 public abstract long getVideoTurnedOnTime(long elapsedRealtimeUs, int which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700359 public abstract Timer getForegroundActivityTimer();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700360
361 // Time this uid has any processes in foreground state.
362 public static final int PROCESS_STATE_FOREGROUND = 0;
363 // Time this uid has any process in active state (not cached).
364 public static final int PROCESS_STATE_ACTIVE = 1;
365 // Time this uid has any processes running at all.
366 public static final int PROCESS_STATE_RUNNING = 2;
367 // Total number of process states we track.
368 public static final int NUM_PROCESS_STATE = 3;
369
370 static final String[] PROCESS_STATE_NAMES = {
371 "Foreground", "Active", "Running"
372 };
373
374 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
375
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800376 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377
Robert Greenwalta029ea12013-09-25 16:38:12 -0700378 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
379
Dianne Hackborn617f8772009-03-31 15:04:46 -0700380 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700381 * Note that these must match the constants in android.os.PowerManager.
382 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
383 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700384 */
385 static final String[] USER_ACTIVITY_TYPES = {
Jeff Browndf693de2012-07-27 12:03:38 -0700386 "other", "button", "touch"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700387 };
388
Jeff Browndf693de2012-07-27 12:03:38 -0700389 public static final int NUM_USER_ACTIVITY_TYPES = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700390
Dianne Hackborn617f8772009-03-31 15:04:46 -0700391 public abstract void noteUserActivityLocked(int type);
392 public abstract boolean hasUserActivity();
393 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700394
395 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800396 public abstract long getNetworkActivityBytes(int type, int which);
397 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800398 public abstract long getMobileRadioActiveTime(int which);
399 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800402 /*
403 * FIXME: it's not correct to use this magic value because it
404 * could clash with a sensor handle (which are defined by
405 * the sensor HAL, and therefore out of our control
406 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 // Magic sensor number for the GPS.
408 public static final int GPS = -10000;
409
410 public abstract int getHandle();
411
412 public abstract Timer getSensorTime();
413 }
414
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700415 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800416 public int mWakeNesting;
417 public long mWakeSumMs;
418 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700419 }
420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 /**
422 * The statistics associated with a particular process.
423 */
424 public static abstract class Proc {
425
Dianne Hackborn287952c2010-09-22 22:34:31 -0700426 public static class ExcessivePower {
427 public static final int TYPE_WAKE = 1;
428 public static final int TYPE_CPU = 2;
429
430 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700431 public long overTime;
432 public long usedTime;
433 }
434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800436 * Returns true if this process is still active in the battery stats.
437 */
438 public abstract boolean isActive();
439
440 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 * Returns the total time (in 1/100 sec) spent executing in user code.
442 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700443 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 */
445 public abstract long getUserTime(int which);
446
447 /**
448 * Returns the total time (in 1/100 sec) spent executing in system code.
449 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700450 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 */
452 public abstract long getSystemTime(int which);
453
454 /**
455 * Returns the number of times the process has been started.
456 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700457 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 */
459 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700460
461 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800462 * Returns the number of times the process has crashed.
463 *
464 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
465 */
466 public abstract int getNumCrashes(int which);
467
468 /**
469 * Returns the number of times the process has ANRed.
470 *
471 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
472 */
473 public abstract int getNumAnrs(int which);
474
475 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700476 * Returns the cpu time spent in microseconds while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700477 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700478 * @return foreground cpu time in microseconds
479 */
480 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700481
482 /**
483 * Returns the approximate cpu time spent in microseconds, at a certain CPU speed.
484 * @param speedStep the index of the CPU speed. This is not the actual speed of the
485 * CPU.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700486 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanie43530a2009-08-21 13:11:37 -0700487 * @see BatteryStats#getCpuSpeedSteps()
488 */
489 public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700490
Dianne Hackborn287952c2010-09-22 22:34:31 -0700491 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700492
Dianne Hackborn287952c2010-09-22 22:34:31 -0700493 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 }
495
496 /**
497 * The statistics associated with a particular package.
498 */
499 public static abstract class Pkg {
500
501 /**
502 * Returns the number of times this package has done something that could wake up the
503 * device from sleep.
504 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700505 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 */
507 public abstract int getWakeups(int which);
508
509 /**
510 * Returns a mapping containing service statistics.
511 */
512 public abstract Map<String, ? extends Serv> getServiceStats();
513
514 /**
515 * The statistics associated with a particular service.
516 */
517 public abstract class Serv {
518
519 /**
520 * Returns the amount of time spent started.
521 *
522 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700523 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 * @return
525 */
526 public abstract long getStartTime(long batteryUptime, int which);
527
528 /**
529 * Returns the total number of times startService() has been called.
530 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700531 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 */
533 public abstract int getStarts(int which);
534
535 /**
536 * Returns the total number times the service has been launched.
537 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700538 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 */
540 public abstract int getLaunches(int which);
541 }
542 }
543 }
544
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800545 public final static class HistoryTag {
546 public String string;
547 public int uid;
548
549 public int poolIdx;
550
551 public void setTo(HistoryTag o) {
552 string = o.string;
553 uid = o.uid;
554 poolIdx = o.poolIdx;
555 }
556
557 public void setTo(String _string, int _uid) {
558 string = _string;
559 uid = _uid;
560 poolIdx = -1;
561 }
562
563 public void writeToParcel(Parcel dest, int flags) {
564 dest.writeString(string);
565 dest.writeInt(uid);
566 }
567
568 public void readFromParcel(Parcel src) {
569 string = src.readString();
570 uid = src.readInt();
571 poolIdx = -1;
572 }
573
574 @Override
575 public boolean equals(Object o) {
576 if (this == o) return true;
577 if (o == null || getClass() != o.getClass()) return false;
578
579 HistoryTag that = (HistoryTag) o;
580
581 if (uid != that.uid) return false;
582 if (!string.equals(that.string)) return false;
583
584 return true;
585 }
586
587 @Override
588 public int hashCode() {
589 int result = string.hashCode();
590 result = 31 * result + uid;
591 return result;
592 }
593 }
594
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -0800595 /**
596 * Optional detailed information that can go into a history step. This is typically
597 * generated each time the battery level changes.
598 */
599 public final static class HistoryStepDetails {
600 // Time (in 1/100 second) spent in user space and the kernel since the last step.
601 public int userTime;
602 public int systemTime;
603
604 // Top three apps using CPU in the last step, with times in 1/100 second.
605 public int appCpuUid1;
606 public int appCpuUTime1;
607 public int appCpuSTime1;
608 public int appCpuUid2;
609 public int appCpuUTime2;
610 public int appCpuSTime2;
611 public int appCpuUid3;
612 public int appCpuUTime3;
613 public int appCpuSTime3;
614
615 // Information from /proc/stat
616 public int statUserTime;
617 public int statSystemTime;
618 public int statIOWaitTime;
619 public int statIrqTime;
620 public int statSoftIrqTime;
621 public int statIdlTime;
622
623 public HistoryStepDetails() {
624 clear();
625 }
626
627 public void clear() {
628 userTime = systemTime = 0;
629 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
630 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
631 = appCpuUTime3 = appCpuSTime3 = 0;
632 }
633
634 public void writeToParcel(Parcel out) {
635 out.writeInt(userTime);
636 out.writeInt(systemTime);
637 out.writeInt(appCpuUid1);
638 out.writeInt(appCpuUTime1);
639 out.writeInt(appCpuSTime1);
640 out.writeInt(appCpuUid2);
641 out.writeInt(appCpuUTime2);
642 out.writeInt(appCpuSTime2);
643 out.writeInt(appCpuUid3);
644 out.writeInt(appCpuUTime3);
645 out.writeInt(appCpuSTime3);
646 out.writeInt(statUserTime);
647 out.writeInt(statSystemTime);
648 out.writeInt(statIOWaitTime);
649 out.writeInt(statIrqTime);
650 out.writeInt(statSoftIrqTime);
651 out.writeInt(statIdlTime);
652 }
653
654 public void readFromParcel(Parcel in) {
655 userTime = in.readInt();
656 systemTime = in.readInt();
657 appCpuUid1 = in.readInt();
658 appCpuUTime1 = in.readInt();
659 appCpuSTime1 = in.readInt();
660 appCpuUid2 = in.readInt();
661 appCpuUTime2 = in.readInt();
662 appCpuSTime2 = in.readInt();
663 appCpuUid3 = in.readInt();
664 appCpuUTime3 = in.readInt();
665 appCpuSTime3 = in.readInt();
666 statUserTime = in.readInt();
667 statSystemTime = in.readInt();
668 statIOWaitTime = in.readInt();
669 statIrqTime = in.readInt();
670 statSoftIrqTime = in.readInt();
671 statIdlTime = in.readInt();
672 }
673 }
674
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700675 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700676 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -0700677
678 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700679 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800680
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800681 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800682 public static final byte CMD_NULL = -1;
683 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800684 public static final byte CMD_CURRENT_TIME = 5;
685 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -0700686 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -0800687 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800688
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700689 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700690
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800691 /**
692 * Return whether the command code is a delta data update.
693 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800694 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800695 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800696 }
697
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700698 public byte batteryLevel;
699 public byte batteryStatus;
700 public byte batteryHealth;
701 public byte batteryPlugType;
702
Sungmin Choic7e9e8b2013-01-16 12:57:36 +0900703 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700704 public char batteryVoltage;
705
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700706 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700707 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800708 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700709 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -0700710 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
711 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700712 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800713 public static final int STATE_PHONE_STATE_SHIFT = 6;
714 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700715 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800716 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800717 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800718
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700719 // These states always appear directly in the first int token
720 // of a delta change; they should be ones that change relatively
721 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700722 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
723 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800724 public static final int STATE_GPS_ON_FLAG = 1<<29;
725 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -0800726 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800727 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -0800728 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700729 // These are on the lower bits used for the command; if they change
730 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700731 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700732 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700733 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700734 public static final int STATE_SCREEN_ON_FLAG = 1<<20;
735 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19;
736 public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700737 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -0700738
Dianne Hackbornf47d8f22010-10-08 10:46:55 -0700739 public static final int MOST_INTERESTING_STATES =
740 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
Dianne Hackborn3251b902014-06-20 14:40:53 -0700741 | STATE_PHONE_IN_CALL_FLAG | STATE_BLUETOOTH_ON_FLAG;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -0700742
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700743 public int states;
744
Dianne Hackborn3251b902014-06-20 14:40:53 -0700745 // Constants from WIFI_SUPPL_STATE_*
746 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
747 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
748 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
749 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
750 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
751 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
752
753 public static final int STATE2_LOW_POWER_FLAG = 1<<31;
754 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
755 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
756 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -0700757 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn3251b902014-06-20 14:40:53 -0700758
759 public static final int MOST_INTERESTING_STATES2 =
760 STATE2_LOW_POWER_FLAG | STATE2_WIFI_ON_FLAG;
761
Dianne Hackborn40c87252014-03-19 16:55:40 -0700762 public int states2;
763
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800764 // The wake lock that was acquired at this point.
765 public HistoryTag wakelockTag;
766
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800767 // Kernel wakeup reason at this point.
768 public HistoryTag wakeReasonTag;
769
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -0800770 // Non-null when there is more detailed information at this step.
771 public HistoryStepDetails stepDetails;
772
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800773 public static final int EVENT_FLAG_START = 0x8000;
774 public static final int EVENT_FLAG_FINISH = 0x4000;
775
776 // No event in this item.
777 public static final int EVENT_NONE = 0x0000;
778 // Event is about a process that is running.
779 public static final int EVENT_PROC = 0x0001;
780 // Event is about an application package that is in the foreground.
781 public static final int EVENT_FOREGROUND = 0x0002;
782 // Event is about an application package that is at the top of the screen.
783 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700784 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -0800785 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -0700786 // Events for all additional wake locks aquired/release within a wake block.
787 // These are not generated by default.
788 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700789 // Event is about an application executing a scheduled job.
790 public static final int EVENT_JOB = 0x0006;
791 // Events for users running.
792 public static final int EVENT_USER_RUNNING = 0x0007;
793 // Events for foreground user.
794 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800795 // Events for connectivity changed.
796 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800797 // Number of event types.
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800798 public static final int EVENT_COUNT = 0x000a;
Dianne Hackborn37de0982014-05-09 09:32:18 -0700799 // Mask to extract out only the type part of the event.
800 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800801
802 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
803 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
804 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
805 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
806 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
807 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -0800808 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
809 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -0700810 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
811 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700812 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
813 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
814 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
815 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
816 public static final int EVENT_USER_FOREGROUND_START =
817 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
818 public static final int EVENT_USER_FOREGROUND_FINISH =
819 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800820
821 // For CMD_EVENT.
822 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800823 public HistoryTag eventTag;
824
Dianne Hackborn9a755432014-05-15 17:05:22 -0700825 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800826 public long currentTime;
827
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800828 // Meta-data when reading.
829 public int numReadInts;
830
831 // Pre-allocated objects.
832 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800833 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800834 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800835
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700836 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700837 }
838
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700839 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700840 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800841 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700842 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700843 }
844
845 public int describeContents() {
846 return 0;
847 }
848
849 public void writeToParcel(Parcel dest, int flags) {
850 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700851 int bat = (((int)cmd)&0xff)
852 | ((((int)batteryLevel)<<8)&0xff00)
853 | ((((int)batteryStatus)<<16)&0xf0000)
854 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800855 | ((((int)batteryPlugType)<<24)&0xf000000)
856 | (wakelockTag != null ? 0x10000000 : 0)
857 | (wakeReasonTag != null ? 0x20000000 : 0)
858 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700859 dest.writeInt(bat);
860 bat = (((int)batteryTemperature)&0xffff)
861 | ((((int)batteryVoltage)<<16)&0xffff0000);
862 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700863 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700864 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800865 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800866 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800867 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800868 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800869 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800870 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800871 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800872 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800873 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800874 }
Dianne Hackborn37de0982014-05-09 09:32:18 -0700875 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800876 dest.writeLong(currentTime);
877 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700878 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700879
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800880 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800881 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700882 int bat = src.readInt();
883 cmd = (byte)(bat&0xff);
884 batteryLevel = (byte)((bat>>8)&0xff);
885 batteryStatus = (byte)((bat>>16)&0xf);
886 batteryHealth = (byte)((bat>>20)&0xf);
887 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800888 int bat2 = src.readInt();
889 batteryTemperature = (short)(bat2&0xffff);
890 batteryVoltage = (char)((bat2>>16)&0xffff);
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700891 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700892 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800893 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800894 wakelockTag = localWakelockTag;
895 wakelockTag.readFromParcel(src);
896 } else {
897 wakelockTag = null;
898 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800899 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800900 wakeReasonTag = localWakeReasonTag;
901 wakeReasonTag.readFromParcel(src);
902 } else {
903 wakeReasonTag = null;
904 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800905 if ((bat&0x40000000) != 0) {
906 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800907 eventTag = localEventTag;
908 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800909 } else {
910 eventCode = EVENT_NONE;
911 eventTag = null;
912 }
Dianne Hackborn37de0982014-05-09 09:32:18 -0700913 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800914 currentTime = src.readLong();
915 } else {
916 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700917 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800918 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700919 }
920
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700921 public void clear() {
922 time = 0;
923 cmd = CMD_NULL;
924 batteryLevel = 0;
925 batteryStatus = 0;
926 batteryHealth = 0;
927 batteryPlugType = 0;
928 batteryTemperature = 0;
929 batteryVoltage = 0;
930 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700931 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800932 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800933 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800934 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800935 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700936 }
937
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700938 public void setTo(HistoryItem o) {
939 time = o.time;
940 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800941 setToCommon(o);
942 }
943
944 public void setTo(long time, byte cmd, HistoryItem o) {
945 this.time = time;
946 this.cmd = cmd;
947 setToCommon(o);
948 }
949
950 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700951 batteryLevel = o.batteryLevel;
952 batteryStatus = o.batteryStatus;
953 batteryHealth = o.batteryHealth;
954 batteryPlugType = o.batteryPlugType;
955 batteryTemperature = o.batteryTemperature;
956 batteryVoltage = o.batteryVoltage;
957 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700958 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800959 if (o.wakelockTag != null) {
960 wakelockTag = localWakelockTag;
961 wakelockTag.setTo(o.wakelockTag);
962 } else {
963 wakelockTag = null;
964 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800965 if (o.wakeReasonTag != null) {
966 wakeReasonTag = localWakeReasonTag;
967 wakeReasonTag.setTo(o.wakeReasonTag);
968 } else {
969 wakeReasonTag = null;
970 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800971 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800972 if (o.eventTag != null) {
973 eventTag = localEventTag;
974 eventTag.setTo(o.eventTag);
975 } else {
976 eventTag = null;
977 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800978 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700979 }
980
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800981 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700982 return batteryLevel == o.batteryLevel
983 && batteryStatus == o.batteryStatus
984 && batteryHealth == o.batteryHealth
985 && batteryPlugType == o.batteryPlugType
986 && batteryTemperature == o.batteryTemperature
987 && batteryVoltage == o.batteryVoltage
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800988 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700989 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800990 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700991 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800992
993 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800994 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800995 return false;
996 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800997 if (wakelockTag != o.wakelockTag) {
998 if (wakelockTag == null || o.wakelockTag == null) {
999 return false;
1000 }
1001 if (!wakelockTag.equals(o.wakelockTag)) {
1002 return false;
1003 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001004 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001005 if (wakeReasonTag != o.wakeReasonTag) {
1006 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1007 return false;
1008 }
1009 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1010 return false;
1011 }
1012 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001013 if (eventTag != o.eventTag) {
1014 if (eventTag == null || o.eventTag == null) {
1015 return false;
1016 }
1017 if (!eventTag.equals(o.eventTag)) {
1018 return false;
1019 }
1020 }
1021 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001022 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001023 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001024
1025 public final static class HistoryEventTracker {
1026 private final HashMap<String, SparseIntArray>[] mActiveEvents
1027 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1028
1029 public boolean updateState(int code, String name, int uid, int poolIdx) {
1030 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1031 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1032 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1033 if (active == null) {
1034 active = new HashMap<String, SparseIntArray>();
1035 mActiveEvents[idx] = active;
1036 }
1037 SparseIntArray uids = active.get(name);
1038 if (uids == null) {
1039 uids = new SparseIntArray();
1040 active.put(name, uids);
1041 }
1042 if (uids.indexOfKey(uid) >= 0) {
1043 // Already set, nothing to do!
1044 return false;
1045 }
1046 uids.put(uid, poolIdx);
1047 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1048 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1049 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1050 if (active == null) {
1051 // not currently active, nothing to do.
1052 return false;
1053 }
1054 SparseIntArray uids = active.get(name);
1055 if (uids == null) {
1056 // not currently active, nothing to do.
1057 return false;
1058 }
1059 idx = uids.indexOfKey(uid);
1060 if (idx < 0) {
1061 // not currently active, nothing to do.
1062 return false;
1063 }
1064 uids.removeAt(idx);
1065 if (uids.size() <= 0) {
1066 active.remove(name);
1067 }
1068 }
1069 return true;
1070 }
1071
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001072 public void removeEvents(int code) {
1073 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1074 mActiveEvents[idx] = null;
1075 }
1076
Dianne Hackborn37de0982014-05-09 09:32:18 -07001077 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1078 return mActiveEvents[code];
1079 }
1080 }
1081
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001082 public static final class BitDescription {
1083 public final int mask;
1084 public final int shift;
1085 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001086 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001087 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001088 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001089
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001090 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001091 this.mask = mask;
1092 this.shift = -1;
1093 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001094 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001095 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001096 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001097 }
1098
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001099 public BitDescription(int mask, int shift, String name, String shortName,
1100 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001101 this.mask = mask;
1102 this.shift = shift;
1103 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001104 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001105 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001106 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001107 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001108 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001109
Dianne Hackbornfc064132014-06-02 12:42:12 -07001110 /**
1111 * Don't allow any more batching in to the current history event. This
1112 * is called when printing partial histories, so to ensure that the next
1113 * history event will go in to a new batch after what was printed in the
1114 * last partial history.
1115 */
1116 public abstract void commitCurrentHistoryBatchLocked();
1117
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001118 public abstract int getHistoryTotalSize();
1119
1120 public abstract int getHistoryUsedSize();
1121
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001122 public abstract boolean startIteratingHistoryLocked();
1123
Dianne Hackborn099bc622014-01-22 13:39:16 -08001124 public abstract int getHistoryStringPoolSize();
1125
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001126 public abstract int getHistoryStringPoolBytes();
1127
1128 public abstract String getHistoryTagPoolString(int index);
1129
1130 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001131
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001132 public abstract boolean getNextHistoryLocked(HistoryItem out);
1133
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001134 public abstract void finishIteratingHistoryLocked();
1135
1136 public abstract boolean startIteratingOldHistoryLocked();
1137
1138 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1139
1140 public abstract void finishIteratingOldHistoryLocked();
1141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001143 * Return the base time offset for the battery history.
1144 */
1145 public abstract long getHistoryBaseTime();
1146
1147 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 * Returns the number of times the device has been started.
1149 */
1150 public abstract int getStartCount();
1151
1152 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001153 * 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 -08001154 * running on battery.
1155 *
1156 * {@hide}
1157 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001158 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001160 /**
1161 * Returns the number of times the screen was turned on.
1162 *
1163 * {@hide}
1164 */
1165 public abstract int getScreenOnCount(int which);
1166
Jeff Browne95c3cd2014-05-02 16:59:26 -07001167 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1168
Dianne Hackborn617f8772009-03-31 15:04:46 -07001169 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1170 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1171 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1172 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1173 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1174
1175 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1176 "dark", "dim", "medium", "light", "bright"
1177 };
1178
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001179 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1180 "0", "1", "2", "3", "4"
1181 };
1182
Dianne Hackborn617f8772009-03-31 15:04:46 -07001183 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001184
Dianne Hackborn617f8772009-03-31 15:04:46 -07001185 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001186 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001187 * the given brightness
1188 *
1189 * {@hide}
1190 */
1191 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001192 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 /**
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001195 * Returns the time in microseconds that low power mode has been enabled while the device was
1196 * running on battery.
1197 *
1198 * {@hide}
1199 */
1200 public abstract long getLowPowerModeEnabledTime(long elapsedRealtimeUs, int which);
1201
1202 /**
1203 * Returns the number of times that low power mode was enabled.
1204 *
1205 * {@hide}
1206 */
1207 public abstract int getLowPowerModeEnabledCount(int which);
1208
1209 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001210 * Returns the number of times that connectivity state changed.
1211 *
1212 * {@hide}
1213 */
1214 public abstract int getNumConnectivityChange(int which);
1215
1216 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001217 * 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 -08001218 * running on battery.
1219 *
1220 * {@hide}
1221 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001222 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001223
1224 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001225 * Returns the number of times a phone call was activated.
1226 *
1227 * {@hide}
1228 */
1229 public abstract int getPhoneOnCount(int which);
1230
1231 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001232 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001233 * the given signal strength.
1234 *
1235 * {@hide}
1236 */
1237 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001238 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001239
Dianne Hackborn617f8772009-03-31 15:04:46 -07001240 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001241 * Returns the time in microseconds that the phone has been trying to
1242 * acquire a signal.
1243 *
1244 * {@hide}
1245 */
1246 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001247 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001248
1249 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001250 * Returns the number of times the phone has entered the given signal strength.
1251 *
1252 * {@hide}
1253 */
1254 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1255
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001256 /**
1257 * Returns the time in microseconds that the mobile network has been active
1258 * (in a high power state).
1259 *
1260 * {@hide}
1261 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001262 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001263
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001264 /**
1265 * Returns the number of times that the mobile network has transitioned to the
1266 * active state.
1267 *
1268 * {@hide}
1269 */
1270 public abstract int getMobileRadioActiveCount(int which);
1271
1272 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001273 * Returns the time in microseconds that is the difference between the mobile radio
1274 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1275 * from the radio.
1276 *
1277 * {@hide}
1278 */
1279 public abstract long getMobileRadioActiveAdjustedTime(int which);
1280
1281 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001282 * Returns the time in microseconds that the mobile network has been active
1283 * (in a high power state) but not being able to blame on an app.
1284 *
1285 * {@hide}
1286 */
1287 public abstract long getMobileRadioActiveUnknownTime(int which);
1288
1289 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001290 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001291 *
1292 * {@hide}
1293 */
1294 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001295
Dianne Hackborn627bba72009-03-24 22:32:56 -07001296 public static final int DATA_CONNECTION_NONE = 0;
1297 public static final int DATA_CONNECTION_GPRS = 1;
1298 public static final int DATA_CONNECTION_EDGE = 2;
1299 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001300 public static final int DATA_CONNECTION_CDMA = 4;
1301 public static final int DATA_CONNECTION_EVDO_0 = 5;
1302 public static final int DATA_CONNECTION_EVDO_A = 6;
1303 public static final int DATA_CONNECTION_1xRTT = 7;
1304 public static final int DATA_CONNECTION_HSDPA = 8;
1305 public static final int DATA_CONNECTION_HSUPA = 9;
1306 public static final int DATA_CONNECTION_HSPA = 10;
1307 public static final int DATA_CONNECTION_IDEN = 11;
1308 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001309 public static final int DATA_CONNECTION_LTE = 13;
1310 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001311 public static final int DATA_CONNECTION_HSPAP = 15;
1312 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001313
Dianne Hackborn627bba72009-03-24 22:32:56 -07001314 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001315 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001316 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001317 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001318 };
1319
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001320 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001321
1322 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001323 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001324 * the given data connection.
1325 *
1326 * {@hide}
1327 */
1328 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001329 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001332 * Returns the number of times the phone has entered the given data
1333 * connection type.
1334 *
1335 * {@hide}
1336 */
1337 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001338
Dianne Hackborn3251b902014-06-20 14:40:53 -07001339 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1340 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1341 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1342 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1343 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1344 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1345 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1346 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1347 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1348 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1349 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1350 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1351 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1352
1353 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1354
1355 static final String[] WIFI_SUPPL_STATE_NAMES = {
1356 "invalid", "disconn", "disabled", "inactive", "scanning",
1357 "authenticating", "associating", "associated", "4-way-handshake",
1358 "group-handshake", "completed", "dormant", "uninit"
1359 };
1360
1361 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1362 "inv", "dsc", "dis", "inact", "scan",
1363 "auth", "ascing", "asced", "4-way",
1364 "group", "compl", "dorm", "uninit"
1365 };
1366
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001367 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1368 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001369 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001370 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1371 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001372 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001373 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1374 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1375 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001376 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001377 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001378 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001379 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1380 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
1381 new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001382 new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
1383 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1384 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1385 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1386 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1387 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1388 new String[] {"in", "out", "emergency", "off"},
1389 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001390 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1391 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1392 SignalStrength.SIGNAL_STRENGTH_NAMES,
1393 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001394 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1395 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1396 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001397 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001398
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001399 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1400 = new BitDescription[] {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001401 new BitDescription(HistoryItem.STATE2_LOW_POWER_FLAG, "low_power", "lp"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001402 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
1403 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Wr"),
1404 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001405 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001406 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1407 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1408 new String[] { "0", "1", "2", "3", "4" },
1409 new String[] { "0", "1", "2", "3", "4" }),
1410 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1411 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1412 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001413 };
1414
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001415 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001416 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001417 };
1418
1419 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001420 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001421 };
1422
Dianne Hackborn617f8772009-03-31 15:04:46 -07001423 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001424 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001425 * running on battery.
1426 *
1427 * {@hide}
1428 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001429 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001430
1431 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001432 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001433 * been in the running state while the device was running on battery.
1434 *
1435 * {@hide}
1436 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001437 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001438
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001439 public static final int WIFI_STATE_OFF = 0;
1440 public static final int WIFI_STATE_OFF_SCANNING = 1;
1441 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
1442 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
1443 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
1444 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
1445 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
1446 public static final int WIFI_STATE_SOFT_AP = 7;
1447
1448 static final String[] WIFI_STATE_NAMES = {
1449 "off", "scanning", "no_net", "disconn",
1450 "sta", "p2p", "sta_p2p", "soft_ap"
1451 };
1452
1453 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
1454
1455 /**
1456 * Returns the time in microseconds that WiFi has been running in the given state.
1457 *
1458 * {@hide}
1459 */
1460 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001461 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001462
1463 /**
1464 * Returns the number of times that WiFi has entered the given state.
1465 *
1466 * {@hide}
1467 */
1468 public abstract int getWifiStateCount(int wifiState, int which);
1469
The Android Open Source Project10592532009-03-18 17:39:46 -07001470 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07001471 * Returns the time in microseconds that the wifi supplicant has been
1472 * in a given state.
1473 *
1474 * {@hide}
1475 */
1476 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
1477
1478 /**
1479 * Returns the number of times that the wifi supplicant has transitioned
1480 * to a given state.
1481 *
1482 * {@hide}
1483 */
1484 public abstract int getWifiSupplStateCount(int state, int which);
1485
1486 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
1487
1488 /**
1489 * Returns the time in microseconds that WIFI has been running with
1490 * the given signal strength.
1491 *
1492 * {@hide}
1493 */
1494 public abstract long getWifiSignalStrengthTime(int strengthBin,
1495 long elapsedRealtimeUs, int which);
1496
1497 /**
1498 * Returns the number of times WIFI has entered the given signal strength.
1499 *
1500 * {@hide}
1501 */
1502 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
1503
1504 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001505 * Returns the time in microseconds that bluetooth has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001506 * running on battery.
1507 *
1508 * {@hide}
1509 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001510 public abstract long getBluetoothOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001511
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001512 public abstract int getBluetoothPingCount();
1513
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001514 public static final int BLUETOOTH_STATE_INACTIVE = 0;
1515 public static final int BLUETOOTH_STATE_LOW = 1;
1516 public static final int BLUETOOTH_STATE_MEDIUM = 2;
1517 public static final int BLUETOOTH_STATE_HIGH = 3;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001518
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001519 static final String[] BLUETOOTH_STATE_NAMES = {
1520 "inactive", "low", "med", "high"
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001521 };
1522
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001523 public static final int NUM_BLUETOOTH_STATES = BLUETOOTH_STATE_HIGH +1;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001524
1525 /**
1526 * Returns the time in microseconds that Bluetooth has been running in the
1527 * given active state.
1528 *
1529 * {@hide}
1530 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001531 public abstract long getBluetoothStateTime(int bluetoothState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001532 long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001533
1534 /**
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001535 * Returns the number of times that Bluetooth has entered the given active state.
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001536 *
1537 * {@hide}
1538 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001539 public abstract int getBluetoothStateCount(int bluetoothState, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001540
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001541 /**
1542 * Returns the time in microseconds that the flashlight has been on while the device was
1543 * running on battery.
1544 *
1545 * {@hide}
1546 */
1547 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
1548
1549 /**
1550 * Returns the number of times that the flashlight has been turned on while the device was
1551 * running on battery.
1552 *
1553 * {@hide}
1554 */
1555 public abstract long getFlashlightOnCount(int which);
1556
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001557 public static final int NETWORK_MOBILE_RX_DATA = 0;
1558 public static final int NETWORK_MOBILE_TX_DATA = 1;
1559 public static final int NETWORK_WIFI_RX_DATA = 2;
1560 public static final int NETWORK_WIFI_TX_DATA = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001561
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001562 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001563
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001564 public abstract long getNetworkActivityBytes(int type, int which);
1565 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001566
The Android Open Source Project10592532009-03-18 17:39:46 -07001567 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08001568 * Return the wall clock time when battery stats data collection started.
1569 */
1570 public abstract long getStartClockTime();
1571
1572 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07001573 * Return platform version tag that we were running in when the battery stats started.
1574 */
1575 public abstract String getStartPlatformVersion();
1576
1577 /**
1578 * Return platform version tag that we were running in when the battery stats ended.
1579 */
1580 public abstract String getEndPlatformVersion();
1581
1582 /**
1583 * Return the internal version code of the parcelled format.
1584 */
1585 public abstract int getParcelVersion();
1586
1587 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 * Return whether we are currently running on battery.
1589 */
1590 public abstract boolean getIsOnBattery();
1591
1592 /**
1593 * Returns a SparseArray containing the statistics for each uid.
1594 */
1595 public abstract SparseArray<? extends Uid> getUidStats();
1596
1597 /**
1598 * Returns the current battery uptime in microseconds.
1599 *
1600 * @param curTime the amount of elapsed realtime in microseconds.
1601 */
1602 public abstract long getBatteryUptime(long curTime);
1603
1604 /**
1605 * Returns the current battery realtime in microseconds.
1606 *
1607 * @param curTime the amount of elapsed realtime in microseconds.
1608 */
1609 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001610
1611 /**
Evan Millar633a1742009-04-02 16:36:33 -07001612 * Returns the battery percentage level at the last time the device was unplugged from power, or
1613 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07001614 */
Evan Millar633a1742009-04-02 16:36:33 -07001615 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07001616
1617 /**
Evan Millar633a1742009-04-02 16:36:33 -07001618 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
1619 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07001620 */
Evan Millar633a1742009-04-02 16:36:33 -07001621 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001622
1623 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001624 * Get the amount the battery has discharged since the stats were
1625 * last reset after charging, as a lower-end approximation.
1626 */
1627 public abstract int getLowDischargeAmountSinceCharge();
1628
1629 /**
1630 * Get the amount the battery has discharged since the stats were
1631 * last reset after charging, as an upper-end approximation.
1632 */
1633 public abstract int getHighDischargeAmountSinceCharge();
1634
1635 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07001636 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
1637 */
1638 public abstract int getDischargeAmount(int which);
1639
1640 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08001641 * Get the amount the battery has discharged while the screen was on,
1642 * since the last time power was unplugged.
1643 */
1644 public abstract int getDischargeAmountScreenOn();
1645
1646 /**
1647 * Get the amount the battery has discharged while the screen was on,
1648 * since the last time the device was charged.
1649 */
1650 public abstract int getDischargeAmountScreenOnSinceCharge();
1651
1652 /**
1653 * Get the amount the battery has discharged while the screen was off,
1654 * since the last time power was unplugged.
1655 */
1656 public abstract int getDischargeAmountScreenOff();
1657
1658 /**
1659 * Get the amount the battery has discharged while the screen was off,
1660 * since the last time the device was charged.
1661 */
1662 public abstract int getDischargeAmountScreenOffSinceCharge();
1663
1664 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 * Returns the total, last, or current battery uptime in microseconds.
1666 *
1667 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001668 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 */
1670 public abstract long computeBatteryUptime(long curTime, int which);
1671
1672 /**
1673 * Returns the total, last, or current battery realtime in microseconds.
1674 *
1675 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001676 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 */
1678 public abstract long computeBatteryRealtime(long curTime, int which);
1679
1680 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001681 * Returns the total, last, or current battery screen off uptime in microseconds.
1682 *
1683 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001684 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001685 */
1686 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
1687
1688 /**
1689 * Returns the total, last, or current battery screen off realtime in microseconds.
1690 *
1691 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001692 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001693 */
1694 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
1695
1696 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 * Returns the total, last, or current uptime in microseconds.
1698 *
1699 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001700 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 */
1702 public abstract long computeUptime(long curTime, int which);
1703
1704 /**
1705 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001706 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001707 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001708 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001709 */
1710 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001711
1712 /**
1713 * Compute an approximation for how much run time (in microseconds) is remaining on
1714 * the battery. Returns -1 if no time can be computed: either there is not
1715 * enough current data to make a decision, or the battery is currently
1716 * charging.
1717 *
1718 * @param curTime The current elepsed realtime in microseconds.
1719 */
1720 public abstract long computeBatteryTimeRemaining(long curTime);
1721
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07001722 // The part of a step duration that is the actual time.
1723 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
1724
1725 // Bits in a step duration that are the new battery level we are at.
1726 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
1727 public static final long STEP_LEVEL_LEVEL_SHIFT = 40;
1728
1729 // Bits in a step duration that are the initial mode we were in at that step.
1730 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
1731 public static final long STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
1732
1733 // Bits in a step duration that indicate which modes changed during that step.
1734 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
1735 public static final long STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
1736
1737 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
1738 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
1739
1740 // Step duration mode: power save is on.
1741 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
1742
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001743 /**
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07001744 * Return the historical number of discharge steps we currently have.
1745 */
1746 public abstract int getNumDischargeStepDurations();
1747
1748 /**
1749 * Return the array of discharge step durations; the number of valid
1750 * items in it is returned by {@link #getNumDischargeStepDurations()}.
1751 * These values are in milliseconds.
1752 */
1753 public abstract long[] getDischargeStepDurationsArray();
1754
1755 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001756 * Compute an approximation for how much time (in microseconds) remains until the battery
1757 * is fully charged. Returns -1 if no time can be computed: either there is not
1758 * enough current data to make a decision, or the battery is currently
1759 * discharging.
1760 *
1761 * @param curTime The current elepsed realtime in microseconds.
1762 */
1763 public abstract long computeChargeTimeRemaining(long curTime);
1764
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07001765 /**
1766 * Return the historical number of charge steps we currently have.
1767 */
1768 public abstract int getNumChargeStepDurations();
1769
1770 /**
1771 * Return the array of charge step durations; the number of valid
1772 * items in it is returned by {@link #getNumChargeStepDurations()}.
1773 * These values are in milliseconds.
1774 */
1775 public abstract long[] getChargeStepDurationsArray();
1776
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07001777 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001778
Evan Millarc64edde2009-04-18 12:26:32 -07001779 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001780
Amith Yamasanie43530a2009-08-21 13:11:37 -07001781 /** Returns the number of different speeds that the CPU can run at */
1782 public abstract int getCpuSpeedSteps();
1783
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001784 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
1785
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001786 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001787 long days = seconds / (60 * 60 * 24);
1788 if (days != 0) {
1789 out.append(days);
1790 out.append("d ");
1791 }
1792 long used = days * 60 * 60 * 24;
1793
1794 long hours = (seconds - used) / (60 * 60);
1795 if (hours != 0 || used != 0) {
1796 out.append(hours);
1797 out.append("h ");
1798 }
1799 used += hours * 60 * 60;
1800
1801 long mins = (seconds-used) / 60;
1802 if (mins != 0 || used != 0) {
1803 out.append(mins);
1804 out.append("m ");
1805 }
1806 used += mins * 60;
1807
1808 if (seconds != 0 || used != 0) {
1809 out.append(seconds-used);
1810 out.append("s ");
1811 }
1812 }
1813
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001814 public final static void formatTime(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 long sec = time / 100;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001816 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 sb.append((time - (sec * 100)) * 10);
1818 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001819 }
1820
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001821 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001823 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001824 sb.append(time - (sec * 1000));
1825 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001826 }
1827
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001828 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001829 long sec = time / 1000;
1830 formatTimeRaw(sb, sec);
1831 sb.append(time - (sec * 1000));
1832 sb.append("ms");
1833 }
1834
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001835 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001837 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 }
1839 float perc = ((float)num) / ((float)den) * 100;
1840 mFormatBuilder.setLength(0);
1841 mFormatter.format("%.1f%%", perc);
1842 return mFormatBuilder.toString();
1843 }
1844
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001845 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07001846 mFormatBuilder.setLength(0);
1847
1848 if (bytes < BYTES_PER_KB) {
1849 return bytes + "B";
1850 } else if (bytes < BYTES_PER_MB) {
1851 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
1852 return mFormatBuilder.toString();
1853 } else if (bytes < BYTES_PER_GB){
1854 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
1855 return mFormatBuilder.toString();
1856 } else {
1857 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
1858 return mFormatBuilder.toString();
1859 }
1860 }
1861
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001862 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07001863 if (timer != null) {
1864 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001865 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07001866 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
1867 return totalTimeMillis;
1868 }
1869 return 0;
1870 }
1871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001872 /**
1873 *
1874 * @param sb a StringBuilder object.
1875 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001876 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001878 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879 * @param linePrefix a String to be prepended to each line of output.
1880 * @return the line prefix
1881 */
1882 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001883 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001884
1885 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001886 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887
Evan Millarc64edde2009-04-18 12:26:32 -07001888 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001889 if (totalTimeMillis != 0) {
1890 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001891 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08001892 if (name != null) {
1893 sb.append(name);
1894 sb.append(' ');
1895 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896 sb.append('(');
1897 sb.append(count);
1898 sb.append(" times)");
1899 return ", ";
1900 }
1901 }
1902 return linePrefix;
1903 }
1904
1905 /**
1906 * Checkin version of wakelock printer. Prints simple comma-separated list.
1907 *
1908 * @param sb a StringBuilder object.
1909 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001910 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001912 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 * @param linePrefix a String to be prepended to each line of output.
1914 * @return the line prefix
1915 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001916 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
1917 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 long totalTimeMicros = 0;
1919 int count = 0;
1920 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001921 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07001922 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001923 }
1924 sb.append(linePrefix);
1925 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
1926 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07001927 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 sb.append(count);
1929 return ",";
1930 }
1931
1932 /**
1933 * Dump a comma-separated line of values for terse checkin mode.
1934 *
1935 * @param pw the PageWriter to dump log to
1936 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
1937 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
1938 * @param args type-dependent data arguments
1939 */
1940 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
1941 Object... args ) {
1942 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
1943 pw.print(uid); pw.print(',');
1944 pw.print(category); pw.print(',');
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001945 pw.print(type);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001946
1947 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001948 pw.print(',');
1949 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001951 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07001953
1954 /**
1955 * Temporary for settings.
1956 */
1957 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
1958 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
1959 }
1960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001961 /**
1962 * Checkin server version of dump to produce more compact, computer-readable log.
1963 *
1964 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001965 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07001966 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
1967 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 final long rawUptime = SystemClock.uptimeMillis() * 1000;
1969 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
1970 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
1972 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001973 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
1974 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
1975 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001976 final long totalRealtime = computeRealtime(rawRealtime, which);
1977 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001978 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07001979 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001980 final long lowPowerModeEnabledTime = getLowPowerModeEnabledTime(rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001981 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001982 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
1983 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
1984 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
1985 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 StringBuilder sb = new StringBuilder(128);
1988
Evan Millar22ac0432009-03-31 11:33:18 -07001989 SparseArray<? extends Uid> uidStats = getUidStats();
1990 final int NU = uidStats.size();
1991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07001993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 // Dump "battery" stat
1995 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001996 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07001997 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08001998 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001999 getStartClockTime(),
2000 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002002 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002003 long fullWakeLockTimeTotal = 0;
2004 long partialWakeLockTimeTotal = 0;
2005
2006 for (int iu = 0; iu < NU; iu++) {
2007 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002008
Evan Millar22ac0432009-03-31 11:33:18 -07002009 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
2010 if (wakelocks.size() > 0) {
2011 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
2012 : wakelocks.entrySet()) {
2013 Uid.Wakelock wl = ent.getValue();
2014
2015 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2016 if (fullWakeTimer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002017 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2018 which);
Evan Millar22ac0432009-03-31 11:33:18 -07002019 }
2020
2021 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2022 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07002023 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002024 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002025 }
2026 }
2027 }
2028 }
2029
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002030 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2031 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2032 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2033 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2034 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2035 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2036 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2037 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
2038
2039 // Dump network stats
2040 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2041 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
2042 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets);
2043
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 // Dump misc stats
2045 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002046 screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000,
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002047 wifiRunningTime / 1000, bluetoothOnTime / 1000,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002048 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002049 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
2050 0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which) / 1000,
2051 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002052 lowPowerModeEnabledTime / 1000, connChanges);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002053
2054 // Dump screen brightness stats
2055 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2056 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002057 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002058 }
2059 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002060
Dianne Hackborn627bba72009-03-24 22:32:56 -07002061 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002062 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2063 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002064 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002065 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002066 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002067 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002068 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002069 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002070 args[i] = getPhoneSignalStrengthCount(i, which);
2071 }
2072 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002073
Dianne Hackborn627bba72009-03-24 22:32:56 -07002074 // Dump network type stats
2075 args = new Object[NUM_DATA_CONNECTION_TYPES];
2076 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002077 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002078 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002079 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2080 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2081 args[i] = getPhoneDataConnectionCount(i, which);
2082 }
2083 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002084
2085 // Dump wifi state stats
2086 args = new Object[NUM_WIFI_STATES];
2087 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002088 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002089 }
2090 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2091 for (int i=0; i<NUM_WIFI_STATES; i++) {
2092 args[i] = getWifiStateCount(i, which);
2093 }
2094 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2095
Dianne Hackborn3251b902014-06-20 14:40:53 -07002096 // Dump wifi suppl state stats
2097 args = new Object[NUM_WIFI_SUPPL_STATES];
2098 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2099 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2100 }
2101 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2102 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2103 args[i] = getWifiSupplStateCount(i, which);
2104 }
2105 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
2106
2107 // Dump wifi signal strength stats
2108 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
2109 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2110 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
2111 }
2112 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
2113 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2114 args[i] = getWifiSignalStrengthCount(i, which);
2115 }
2116 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
2117
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002118 // Dump bluetooth state stats
2119 args = new Object[NUM_BLUETOOTH_STATES];
2120 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002121 args[i] = getBluetoothStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002122 }
2123 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_TIME_DATA, args);
2124 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
2125 args[i] = getBluetoothStateCount(i, which);
2126 }
2127 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_COUNT_DATA, args);
2128
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002129 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002130 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07002131 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002134 if (which == STATS_SINCE_UNPLUGGED) {
2135 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2136 getDischargeStartLevel()-getDischargeCurrentLevel(),
2137 getDischargeStartLevel()-getDischargeCurrentLevel(),
2138 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
2139 } else {
2140 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2141 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002142 getDischargeAmountScreenOnSinceCharge(),
2143 getDischargeAmountScreenOffSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002144 }
2145
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002146 if (reqUid < 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002147 Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002148 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002149 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002150 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002151 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002152 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002153 sb.toString());
2154 }
Evan Millarc64edde2009-04-18 12:26:32 -07002155 }
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002156 Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002157 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002158 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
2159 // Not doing the regular wake lock formatting to remain compatible
2160 // with the old checkin format.
2161 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
2162 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002163 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002164 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002165 }
2166 }
Evan Millarc64edde2009-04-18 12:26:32 -07002167 }
2168
Dianne Hackbornd953c532014-08-16 18:17:38 -07002169 BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002170 helper.create(this);
2171 helper.refreshStats(which, UserHandle.USER_ALL);
2172 List<BatterySipper> sippers = helper.getUsageList();
2173 if (sippers != null && sippers.size() > 0) {
2174 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
2175 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08002176 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002177 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
2178 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
2179 for (int i=0; i<sippers.size(); i++) {
2180 BatterySipper bs = sippers.get(i);
2181 int uid = 0;
2182 String label;
2183 switch (bs.drainType) {
2184 case IDLE:
2185 label="idle";
2186 break;
2187 case CELL:
2188 label="cell";
2189 break;
2190 case PHONE:
2191 label="phone";
2192 break;
2193 case WIFI:
2194 label="wifi";
2195 break;
2196 case BLUETOOTH:
2197 label="blue";
2198 break;
2199 case SCREEN:
2200 label="scrn";
2201 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002202 case FLASHLIGHT:
2203 label="flashlight";
2204 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002205 case APP:
2206 uid = bs.uidObj.getUid();
2207 label = "uid";
2208 break;
2209 case USER:
2210 uid = UserHandle.getUid(bs.userId, 0);
2211 label = "user";
2212 break;
2213 case UNACCOUNTED:
2214 label = "unacc";
2215 break;
2216 case OVERCOUNTED:
2217 label = "over";
2218 break;
2219 default:
2220 label = "???";
2221 }
2222 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
2223 BatteryStatsHelper.makemAh(bs.value));
2224 }
2225 }
2226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002227 for (int iu = 0; iu < NU; iu++) {
2228 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002229 if (reqUid >= 0 && uid != reqUid) {
2230 continue;
2231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 Uid u = uidStats.valueAt(iu);
2233 // Dump Network stats per uid, if any
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002234 long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2235 long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2236 long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2237 long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2238 long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2239 long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002240 long mobileActiveTime = u.getMobileRadioActiveTime(which);
2241 int mobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002242 long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2243 long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002244 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
2245 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
2246 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002247
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002248 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
2249 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002250 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002251 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
2252 wifiBytesRx, wifiBytesTx,
2253 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002254 wifiPacketsRx, wifiPacketsTx,
2255 mobileActiveTime, mobileActiveCount);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002256 }
2257
Nick Pelly6ccaa542012-06-15 15:22:47 -07002258 if (fullWifiLockOnTime != 0 || wifiScanTime != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07002259 || uidWifiRunningTime != 0) {
Nick Pelly6ccaa542012-06-15 15:22:47 -07002260 dumpLine(pw, uid, category, WIFI_DATA,
2261 fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07002262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263
Dianne Hackborn617f8772009-03-31 15:04:46 -07002264 if (u.hasUserActivity()) {
2265 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
2266 boolean hasData = false;
2267 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
2268 int val = u.getUserActivityCount(i, which);
2269 args[i] = val;
2270 if (val != 0) hasData = true;
2271 }
2272 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07002273 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002274 }
2275 }
2276
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002277 Map<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278 if (wakelocks.size() > 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002279 for (Map.Entry<String, ? extends Uid.Wakelock> ent : wakelocks.entrySet()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 Uid.Wakelock wl = ent.getValue();
2281 String linePrefix = "";
2282 sb.setLength(0);
Evan Millarc64edde2009-04-18 12:26:32 -07002283 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002284 rawRealtime, "f", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07002285 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002286 rawRealtime, "p", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07002287 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002288 rawRealtime, "w", which, linePrefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002289
2290 // Only log if we had at lease one wakelock...
2291 if (sb.length() > 0) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002292 String name = ent.getKey();
2293 if (name.indexOf(',') >= 0) {
2294 name = name.replace(',', '_');
2295 }
2296 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 }
2298 }
2299 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07002300
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002301 Map<String, ? extends Timer> syncs = u.getSyncStats();
2302 if (syncs.size() > 0) {
2303 for (Map.Entry<String, ? extends Timer> ent : syncs.entrySet()) {
2304 Timer timer = ent.getValue();
2305 // Convert from microseconds to milliseconds with rounding
2306 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2307 int count = timer.getCountLocked(which);
2308 if (totalTime != 0) {
2309 dumpLine(pw, uid, category, SYNC_DATA, ent.getKey(), totalTime, count);
2310 }
2311 }
2312 }
2313
2314 Map<String, ? extends Timer> jobs = u.getJobStats();
2315 if (jobs.size() > 0) {
2316 for (Map.Entry<String, ? extends Timer> ent : jobs.entrySet()) {
2317 Timer timer = ent.getValue();
2318 // Convert from microseconds to milliseconds with rounding
2319 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2320 int count = timer.getCountLocked(which);
2321 if (totalTime != 0) {
2322 dumpLine(pw, uid, category, JOB_DATA, ent.getKey(), totalTime, count);
2323 }
2324 }
2325 }
2326
Dianne Hackborn61659e52014-07-09 16:13:01 -07002327 SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
2328 int NSE = sensors.size();
2329 for (int ise=0; ise<NSE; ise++) {
2330 Uid.Sensor se = sensors.valueAt(ise);
2331 int sensorNumber = sensors.keyAt(ise);
2332 Timer timer = se.getSensorTime();
2333 if (timer != null) {
2334 // Convert from microseconds to milliseconds with rounding
2335 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2336 int count = timer.getCountLocked(which);
2337 if (totalTime != 0) {
2338 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
2339 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002340 }
2341 }
2342
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002343 Timer vibTimer = u.getVibratorOnTimer();
2344 if (vibTimer != null) {
2345 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002346 long totalTime = (vibTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002347 int count = vibTimer.getCountLocked(which);
2348 if (totalTime != 0) {
2349 dumpLine(pw, uid, category, VIBRATOR_DATA, totalTime, count);
2350 }
2351 }
2352
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002353 Timer fgTimer = u.getForegroundActivityTimer();
2354 if (fgTimer != null) {
2355 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002356 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002357 int count = fgTimer.getCountLocked(which);
2358 if (totalTime != 0) {
2359 dumpLine(pw, uid, category, FOREGROUND_DATA, totalTime, count);
2360 }
2361 }
2362
Dianne Hackborn61659e52014-07-09 16:13:01 -07002363 Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
2364 long totalStateTime = 0;
2365 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
2366 totalStateTime += u.getProcessStateTime(ips, rawRealtime, which);
2367 stateTimes[ips] = (totalStateTime + 500) / 1000;
2368 }
2369 if (totalStateTime > 0) {
2370 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
2371 }
2372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002373 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
2374 if (processStats.size() > 0) {
2375 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
2376 : processStats.entrySet()) {
2377 Uid.Proc ps = ent.getValue();
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002378
2379 final long userMillis = ps.getUserTime(which) * 10;
2380 final long systemMillis = ps.getSystemTime(which) * 10;
2381 final long foregroundMillis = ps.getForegroundTime(which) * 10;
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002382 final int starts = ps.getStarts(which);
2383 final int numCrashes = ps.getNumCrashes(which);
2384 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002385
2386 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002387 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002388 dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis,
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002389 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002390 }
2391 }
2392 }
2393
2394 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
2395 if (packageStats.size() > 0) {
2396 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
2397 : packageStats.entrySet()) {
2398
2399 Uid.Pkg ps = ent.getValue();
2400 int wakeups = ps.getWakeups(which);
2401 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
2402 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
2403 : serviceStats.entrySet()) {
2404 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
2405 long startTime = ss.getStartTime(batteryUptime, which);
2406 int starts = ss.getStarts(which);
2407 int launches = ss.getLaunches(which);
2408 if (startTime != 0 || starts != 0 || launches != 0) {
2409 dumpLine(pw, uid, category, APK_DATA,
2410 wakeups, // wakeup alarms
2411 ent.getKey(), // Apk
2412 sent.getKey(), // service
2413 startTime / 1000, // time spent started, in ms
2414 starts,
2415 launches);
2416 }
2417 }
2418 }
2419 }
2420 }
2421 }
2422
Dianne Hackborn81038902012-11-26 17:04:09 -08002423 static final class TimerEntry {
2424 final String mName;
2425 final int mId;
2426 final BatteryStats.Timer mTimer;
2427 final long mTime;
2428 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
2429 mName = name;
2430 mId = id;
2431 mTimer = timer;
2432 mTime = time;
2433 }
2434 }
2435
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002436 private void printmAh(PrintWriter printer, double power) {
2437 printer.print(BatteryStatsHelper.makemAh(power));
2438 }
2439
Dianne Hackbornd953c532014-08-16 18:17:38 -07002440 /**
2441 * Temporary for settings.
2442 */
2443 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
2444 int reqUid) {
2445 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2446 }
2447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002449 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07002450 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2452 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2453 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002454
2455 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2456 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
2457 final long totalRealtime = computeRealtime(rawRealtime, which);
2458 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002459 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2460 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2461 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002462 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
2463 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07002466
2467 SparseArray<? extends Uid> uidStats = getUidStats();
2468 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002470 sb.setLength(0);
2471 sb.append(prefix);
2472 sb.append(" Time on battery: ");
2473 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
2474 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
2475 sb.append(") realtime, ");
2476 formatTimeMs(sb, whichBatteryUptime / 1000);
2477 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
2478 sb.append(") uptime");
2479 pw.println(sb.toString());
2480 sb.setLength(0);
2481 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002482 sb.append(" Time on battery screen off: ");
2483 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
2484 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
2485 sb.append(") realtime, ");
2486 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
2487 sb.append("(");
2488 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
2489 sb.append(") uptime");
2490 pw.println(sb.toString());
2491 sb.setLength(0);
2492 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002493 sb.append(" Total run time: ");
2494 formatTimeMs(sb, totalRealtime / 1000);
2495 sb.append("realtime, ");
2496 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002497 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07002498 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002499 if (batteryTimeRemaining >= 0) {
2500 sb.setLength(0);
2501 sb.append(prefix);
2502 sb.append(" Battery time remaining: ");
2503 formatTimeMs(sb, batteryTimeRemaining / 1000);
2504 pw.println(sb.toString());
2505 }
2506 if (chargeTimeRemaining >= 0) {
2507 sb.setLength(0);
2508 sb.append(prefix);
2509 sb.append(" Charge time remaining: ");
2510 formatTimeMs(sb, chargeTimeRemaining / 1000);
2511 pw.println(sb.toString());
2512 }
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002513 pw.print(" Start clock time: ");
2514 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
2515
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002516 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002517 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002518 final long lowPowerModeEnabledTime = getLowPowerModeEnabledTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002519 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
2520 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
2521 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2522 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002523 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002524 sb.append(prefix);
2525 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
2526 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002527 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002528 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
2529 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07002530 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002531 pw.println(sb.toString());
2532 sb.setLength(0);
2533 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002534 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002535 boolean didOne = false;
2536 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002537 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002538 if (time == 0) {
2539 continue;
2540 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002541 sb.append("\n ");
2542 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002543 didOne = true;
2544 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
2545 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002546 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002547 sb.append("(");
2548 sb.append(formatRatioLocked(time, screenOnTime));
2549 sb.append(")");
2550 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002551 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002552 pw.println(sb.toString());
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002553 if (lowPowerModeEnabledTime != 0) {
2554 sb.setLength(0);
2555 sb.append(prefix);
2556 sb.append(" Low power mode enabled: ");
2557 formatTimeMs(sb, lowPowerModeEnabledTime / 1000);
2558 sb.append("(");
2559 sb.append(formatRatioLocked(lowPowerModeEnabledTime, whichBatteryRealtime));
2560 sb.append(")");
2561 pw.println(sb.toString());
2562 }
2563 if (phoneOnTime != 0) {
2564 sb.setLength(0);
2565 sb.append(prefix);
2566 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
2567 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
2568 sb.append(") "); sb.append(getPhoneOnCount(which));
2569 }
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002570 int connChanges = getNumConnectivityChange(which);
2571 if (connChanges != 0) {
2572 pw.print(prefix);
2573 pw.print(" Connectivity changes: "); pw.println(connChanges);
2574 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002575
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002576 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002577 long fullWakeLockTimeTotalMicros = 0;
2578 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08002579
Dianne Hackborn81038902012-11-26 17:04:09 -08002580 final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>();
2581
Evan Millar22ac0432009-03-31 11:33:18 -07002582 for (int iu = 0; iu < NU; iu++) {
2583 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002584
Evan Millar22ac0432009-03-31 11:33:18 -07002585 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
2586 if (wakelocks.size() > 0) {
2587 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
2588 : wakelocks.entrySet()) {
2589 Uid.Wakelock wl = ent.getValue();
2590
2591 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2592 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07002593 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002594 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002595 }
2596
2597 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2598 if (partialWakeTimer != null) {
Dianne Hackborn81038902012-11-26 17:04:09 -08002599 long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002600 rawRealtime, which);
Dianne Hackborn81038902012-11-26 17:04:09 -08002601 if (totalTimeMicros > 0) {
2602 if (reqUid < 0) {
2603 // Only show the ordered list of all wake
2604 // locks if the caller is not asking for data
2605 // about a specific uid.
2606 timers.add(new TimerEntry(ent.getKey(), u.getUid(),
2607 partialWakeTimer, totalTimeMicros));
2608 }
2609 partialWakeLockTimeTotalMicros += totalTimeMicros;
2610 }
Evan Millar22ac0432009-03-31 11:33:18 -07002611 }
2612 }
2613 }
2614 }
2615
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002616 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2617 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2618 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2619 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2620 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2621 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2622 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2623 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
2624
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002625 if (fullWakeLockTimeTotalMicros != 0) {
2626 sb.setLength(0);
2627 sb.append(prefix);
2628 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
2629 (fullWakeLockTimeTotalMicros + 500) / 1000);
2630 pw.println(sb.toString());
2631 }
2632
2633 if (partialWakeLockTimeTotalMicros != 0) {
2634 sb.setLength(0);
2635 sb.append(prefix);
2636 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
2637 (partialWakeLockTimeTotalMicros + 500) / 1000);
2638 pw.println(sb.toString());
2639 }
2640
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002641 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002642 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
2643 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
2644 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
2645 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002646 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002647 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07002648 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002649 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08002650 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002651 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002652 if (time == 0) {
2653 continue;
2654 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002655 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002656 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002657 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08002658 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002659 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002660 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002661 sb.append("(");
2662 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002663 sb.append(") ");
2664 sb.append(getPhoneSignalStrengthCount(i, which));
2665 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002666 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002667 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002668 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07002669
2670 sb.setLength(0);
2671 sb.append(prefix);
2672 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002673 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002674 pw.println(sb.toString());
2675
Dianne Hackborn627bba72009-03-24 22:32:56 -07002676 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002677 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002678 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002679 didOne = false;
2680 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002681 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002682 if (time == 0) {
2683 continue;
2684 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002685 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002686 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002687 didOne = true;
2688 sb.append(DATA_CONNECTION_NAMES[i]);
2689 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002690 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002691 sb.append("(");
2692 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002693 sb.append(") ");
2694 sb.append(getPhoneDataConnectionCount(i, which));
2695 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002696 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002697 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002698 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07002699
2700 sb.setLength(0);
2701 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002702 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002703 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002704 formatTimeMs(sb, mobileActiveTime / 1000);
2705 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
2706 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
2707 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07002708 pw.println(sb.toString());
2709
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002710 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
2711 if (mobileActiveUnknownTime != 0) {
2712 sb.setLength(0);
2713 sb.append(prefix);
2714 sb.append(" Mobile radio active unknown time: ");
2715 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
2716 sb.append("(");
2717 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
2718 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
2719 sb.append("x");
2720 pw.println(sb.toString());
2721 }
2722
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002723 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
2724 if (mobileActiveAdjustedTime != 0) {
2725 sb.setLength(0);
2726 sb.append(prefix);
2727 sb.append(" Mobile radio active adjusted time: ");
2728 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
2729 sb.append("(");
2730 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
2731 sb.append(")");
2732 pw.println(sb.toString());
2733 }
2734
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002735 pw.print(prefix);
2736 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
2737 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
2738 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
2739 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002740 sb.setLength(0);
2741 sb.append(prefix);
2742 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
2743 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
2744 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
2745 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002746 sb.append(")");
2747 pw.println(sb.toString());
2748
2749 sb.setLength(0);
2750 sb.append(prefix);
2751 sb.append(" Wifi states:");
2752 didOne = false;
2753 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002754 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002755 if (time == 0) {
2756 continue;
2757 }
2758 sb.append("\n ");
2759 didOne = true;
2760 sb.append(WIFI_STATE_NAMES[i]);
2761 sb.append(" ");
2762 formatTimeMs(sb, time/1000);
2763 sb.append("(");
2764 sb.append(formatRatioLocked(time, whichBatteryRealtime));
2765 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07002766 sb.append(getWifiStateCount(i, which));
2767 sb.append("x");
2768 }
2769 if (!didOne) sb.append(" (no activity)");
2770 pw.println(sb.toString());
2771
2772 sb.setLength(0);
2773 sb.append(prefix);
2774 sb.append(" Wifi supplicant states:");
2775 didOne = false;
2776 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2777 final long time = getWifiSupplStateTime(i, rawRealtime, which);
2778 if (time == 0) {
2779 continue;
2780 }
2781 sb.append("\n ");
2782 didOne = true;
2783 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
2784 sb.append(" ");
2785 formatTimeMs(sb, time/1000);
2786 sb.append("(");
2787 sb.append(formatRatioLocked(time, whichBatteryRealtime));
2788 sb.append(") ");
2789 sb.append(getWifiSupplStateCount(i, which));
2790 sb.append("x");
2791 }
2792 if (!didOne) sb.append(" (no activity)");
2793 pw.println(sb.toString());
2794
2795 sb.setLength(0);
2796 sb.append(prefix);
2797 sb.append(" Wifi signal levels:");
2798 didOne = false;
2799 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2800 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
2801 if (time == 0) {
2802 continue;
2803 }
2804 sb.append("\n ");
2805 sb.append(prefix);
2806 didOne = true;
2807 sb.append("level(");
2808 sb.append(i);
2809 sb.append(") ");
2810 formatTimeMs(sb, time/1000);
2811 sb.append("(");
2812 sb.append(formatRatioLocked(time, whichBatteryRealtime));
2813 sb.append(") ");
2814 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002815 sb.append("x");
2816 }
2817 if (!didOne) sb.append(" (no activity)");
2818 pw.println(sb.toString());
2819
2820 sb.setLength(0);
2821 sb.append(prefix);
2822 sb.append(" Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002823 sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime));
2824 sb.append(")");
2825 pw.println(sb.toString());
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002826
2827 sb.setLength(0);
2828 sb.append(prefix);
2829 sb.append(" Bluetooth states:");
2830 didOne = false;
2831 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002832 final long time = getBluetoothStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002833 if (time == 0) {
2834 continue;
2835 }
2836 sb.append("\n ");
2837 didOne = true;
2838 sb.append(BLUETOOTH_STATE_NAMES[i]);
2839 sb.append(" ");
2840 formatTimeMs(sb, time/1000);
2841 sb.append("(");
2842 sb.append(formatRatioLocked(time, whichBatteryRealtime));
2843 sb.append(") ");
2844 sb.append(getPhoneDataConnectionCount(i, which));
2845 sb.append("x");
2846 }
2847 if (!didOne) sb.append(" (no activity)");
2848 pw.println(sb.toString());
2849
2850 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07002851
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002852 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07002853 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002854 pw.print(prefix); pw.println(" Device is currently unplugged");
2855 pw.print(prefix); pw.print(" Discharge cycle start level: ");
2856 pw.println(getDischargeStartLevel());
2857 pw.print(prefix); pw.print(" Discharge cycle current level: ");
2858 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07002859 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002860 pw.print(prefix); pw.println(" Device is currently plugged into power");
2861 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
2862 pw.println(getDischargeStartLevel());
2863 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
2864 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002865 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002866 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
2867 pw.println(getDischargeAmountScreenOn());
2868 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
2869 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07002870 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002871 } else {
2872 pw.print(prefix); pw.println(" Device battery use since last full charge");
2873 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
2874 pw.println(getLowDischargeAmountSinceCharge());
2875 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
2876 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002877 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
2878 pw.println(getDischargeAmountScreenOnSinceCharge());
2879 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
2880 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08002881 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07002882 }
Dianne Hackborn81038902012-11-26 17:04:09 -08002883
Dianne Hackbornd953c532014-08-16 18:17:38 -07002884 BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002885 helper.create(this);
2886 helper.refreshStats(which, UserHandle.USER_ALL);
2887 List<BatterySipper> sippers = helper.getUsageList();
2888 if (sippers != null && sippers.size() > 0) {
2889 pw.print(prefix); pw.println(" Estimated power use (mAh):");
2890 pw.print(prefix); pw.print(" Capacity: ");
2891 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08002892 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07002893 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
2894 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
2895 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
2896 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002897 pw.println();
2898 for (int i=0; i<sippers.size(); i++) {
2899 BatterySipper bs = sippers.get(i);
2900 switch (bs.drainType) {
2901 case IDLE:
2902 pw.print(prefix); pw.print(" Idle: "); printmAh(pw, bs.value);
2903 pw.println();
2904 break;
2905 case CELL:
2906 pw.print(prefix); pw.print(" Cell standby: "); printmAh(pw, bs.value);
2907 pw.println();
2908 break;
2909 case PHONE:
2910 pw.print(prefix); pw.print(" Phone calls: "); printmAh(pw, bs.value);
2911 pw.println();
2912 break;
2913 case WIFI:
2914 pw.print(prefix); pw.print(" Wifi: "); printmAh(pw, bs.value);
2915 pw.println();
2916 break;
2917 case BLUETOOTH:
2918 pw.print(prefix); pw.print(" Bluetooth: "); printmAh(pw, bs.value);
2919 pw.println();
2920 break;
2921 case SCREEN:
2922 pw.print(prefix); pw.print(" Screen: "); printmAh(pw, bs.value);
2923 pw.println();
2924 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002925 case FLASHLIGHT:
2926 pw.print(prefix); pw.print(" Flashlight: "); printmAh(pw, bs.value);
2927 pw.println();
2928 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002929 case APP:
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002930 pw.print(prefix); pw.print(" Uid ");
2931 UserHandle.formatUid(pw, bs.uidObj.getUid());
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002932 pw.print(": "); printmAh(pw, bs.value); pw.println();
2933 break;
2934 case USER:
2935 pw.print(prefix); pw.print(" User "); pw.print(bs.userId);
2936 pw.print(": "); printmAh(pw, bs.value); pw.println();
2937 break;
2938 case UNACCOUNTED:
2939 pw.print(prefix); pw.print(" Unaccounted: "); printmAh(pw, bs.value);
2940 pw.println();
2941 break;
2942 case OVERCOUNTED:
2943 pw.print(prefix); pw.print(" Over-counted: "); printmAh(pw, bs.value);
2944 pw.println();
2945 break;
2946 }
2947 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08002948 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002949 }
2950
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002951 sippers = helper.getMobilemsppList();
2952 if (sippers != null && sippers.size() > 0) {
2953 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002954 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002955 for (int i=0; i<sippers.size(); i++) {
2956 BatterySipper bs = sippers.get(i);
2957 sb.setLength(0);
2958 sb.append(prefix); sb.append(" Uid ");
2959 UserHandle.formatUid(sb, bs.uidObj.getUid());
2960 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
2961 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
2962 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002963 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002964 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002965 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002966 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002967 sb.setLength(0);
2968 sb.append(prefix);
2969 sb.append(" TOTAL TIME: ");
2970 formatTimeMs(sb, totalTime);
2971 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
2972 sb.append(")");
2973 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002974 pw.println();
2975 }
2976
Dianne Hackbornc51cf032014-03-02 19:08:15 -08002977 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
2978 @Override
2979 public int compare(TimerEntry lhs, TimerEntry rhs) {
2980 long lhsTime = lhs.mTime;
2981 long rhsTime = rhs.mTime;
2982 if (lhsTime < rhsTime) {
2983 return 1;
2984 }
2985 if (lhsTime > rhsTime) {
2986 return -1;
2987 }
2988 return 0;
2989 }
2990 };
2991
2992 if (reqUid < 0) {
2993 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
2994 if (kernelWakelocks.size() > 0) {
2995 final ArrayList<TimerEntry> ktimers = new ArrayList<TimerEntry>();
2996 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
2997 BatteryStats.Timer timer = ent.getValue();
2998 long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
2999 if (totalTimeMillis > 0) {
3000 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
3001 }
3002 }
3003 if (ktimers.size() > 0) {
3004 Collections.sort(ktimers, timerComparator);
3005 pw.print(prefix); pw.println(" All kernel wake locks:");
3006 for (int i=0; i<ktimers.size(); i++) {
3007 TimerEntry timer = ktimers.get(i);
3008 String linePrefix = ": ";
3009 sb.setLength(0);
3010 sb.append(prefix);
3011 sb.append(" Kernel Wake lock ");
3012 sb.append(timer.mName);
3013 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
3014 which, linePrefix);
3015 if (!linePrefix.equals(": ")) {
3016 sb.append(" realtime");
3017 // Only print out wake locks that were held
3018 pw.println(sb.toString());
3019 }
3020 }
3021 pw.println();
3022 }
3023 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003024
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003025 if (timers.size() > 0) {
3026 Collections.sort(timers, timerComparator);
3027 pw.print(prefix); pw.println(" All partial wake locks:");
3028 for (int i=0; i<timers.size(); i++) {
3029 TimerEntry timer = timers.get(i);
3030 sb.setLength(0);
3031 sb.append(" Wake lock ");
3032 UserHandle.formatUid(sb, timer.mId);
3033 sb.append(" ");
3034 sb.append(timer.mName);
3035 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3036 sb.append(" realtime");
3037 pw.println(sb.toString());
3038 }
3039 timers.clear();
3040 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08003041 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003042
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003043 Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003044 if (wakeupReasons.size() > 0) {
3045 pw.print(prefix); pw.println(" All wakeup reasons:");
3046 final ArrayList<TimerEntry> reasons = new ArrayList<TimerEntry>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003047 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3048 Timer timer = ent.getValue();
3049 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
3050 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003051 }
3052 Collections.sort(reasons, timerComparator);
3053 for (int i=0; i<reasons.size(); i++) {
3054 TimerEntry timer = reasons.get(i);
3055 String linePrefix = ": ";
3056 sb.setLength(0);
3057 sb.append(prefix);
3058 sb.append(" Wakeup reason ");
3059 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003060 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3061 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003062 pw.println(sb.toString());
3063 }
3064 pw.println();
3065 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003066 }
Evan Millar22ac0432009-03-31 11:33:18 -07003067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 for (int iu=0; iu<NU; iu++) {
3069 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08003070 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003071 continue;
3072 }
3073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003074 Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07003075
3076 pw.print(prefix);
3077 pw.print(" ");
3078 UserHandle.formatUid(pw, uid);
3079 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003081
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003082 long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3083 long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3084 long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3085 long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3086 long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3087 long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003088 long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
3089 int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003090 long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3091 long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003092 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3093 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
3094 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003095
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003096 if (mobileRxBytes > 0 || mobileTxBytes > 0
3097 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003098 pw.print(prefix); pw.print(" Mobile network: ");
3099 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003100 pw.print(formatBytesLocked(mobileTxBytes));
3101 pw.print(" sent (packets "); pw.print(mobileRxPackets);
3102 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003103 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003104 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
3105 sb.setLength(0);
3106 sb.append(prefix); sb.append(" Mobile radio active: ");
3107 formatTimeMs(sb, uidMobileActiveTime / 1000);
3108 sb.append("(");
3109 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
3110 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
3111 long packets = mobileRxPackets + mobileTxPackets;
3112 if (packets == 0) {
3113 packets = 1;
3114 }
3115 sb.append(" @ ");
3116 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
3117 sb.append(" mspp");
3118 pw.println(sb.toString());
3119 }
3120
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003121 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003122 pw.print(prefix); pw.print(" Wi-Fi network: ");
3123 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003124 pw.print(formatBytesLocked(wifiTxBytes));
3125 pw.print(" sent (packets "); pw.print(wifiRxPackets);
3126 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003127 }
3128
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003129 if (fullWifiLockOnTime != 0 || wifiScanTime != 0
3130 || uidWifiRunningTime != 0) {
3131 sb.setLength(0);
3132 sb.append(prefix); sb.append(" Wifi Running: ");
3133 formatTimeMs(sb, uidWifiRunningTime / 1000);
3134 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
3135 whichBatteryRealtime)); sb.append(")\n");
3136 sb.append(prefix); sb.append(" Full Wifi Lock: ");
3137 formatTimeMs(sb, fullWifiLockOnTime / 1000);
3138 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
3139 whichBatteryRealtime)); sb.append(")\n");
3140 sb.append(prefix); sb.append(" Wifi Scan: ");
3141 formatTimeMs(sb, wifiScanTime / 1000);
3142 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
3143 whichBatteryRealtime)); sb.append(")");
3144 pw.println(sb.toString());
3145 }
3146
Dianne Hackborn617f8772009-03-31 15:04:46 -07003147 if (u.hasUserActivity()) {
3148 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07003149 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003150 int val = u.getUserActivityCount(i, which);
3151 if (val != 0) {
3152 if (!hasData) {
3153 sb.setLength(0);
3154 sb.append(" User activity: ");
3155 hasData = true;
3156 } else {
3157 sb.append(", ");
3158 }
3159 sb.append(val);
3160 sb.append(" ");
3161 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
3162 }
3163 }
3164 if (hasData) {
3165 pw.println(sb.toString());
3166 }
3167 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003168
3169 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
3170 if (wakelocks.size() > 0) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003171 long totalFull = 0, totalPartial = 0, totalWindow = 0;
3172 int count = 0;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003173 for (Map.Entry<String, ? extends Uid.Wakelock> ent : wakelocks.entrySet()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 Uid.Wakelock wl = ent.getValue();
3175 String linePrefix = ": ";
3176 sb.setLength(0);
3177 sb.append(prefix);
3178 sb.append(" Wake lock ");
3179 sb.append(ent.getKey());
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003180 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003181 "full", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003182 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 "partial", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003184 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 "window", which, linePrefix);
Dianne Hackbornacc4a122014-08-18 16:33:44 -07003186 if (true || !linePrefix.equals(": ")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05003188 // Only print out wake locks that were held
3189 pw.println(sb.toString());
3190 uidActivity = true;
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003191 count++;
3192 }
3193 totalFull += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003194 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003195 totalPartial += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003196 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003197 totalWindow += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003198 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003199 }
3200 if (count > 1) {
3201 if (totalFull != 0 || totalPartial != 0 || totalWindow != 0) {
3202 sb.setLength(0);
3203 sb.append(prefix);
3204 sb.append(" TOTAL wake: ");
3205 boolean needComma = false;
3206 if (totalFull != 0) {
3207 needComma = true;
3208 formatTimeMs(sb, totalFull);
3209 sb.append("full");
3210 }
3211 if (totalPartial != 0) {
3212 if (needComma) {
3213 sb.append(", ");
3214 }
3215 needComma = true;
3216 formatTimeMs(sb, totalPartial);
3217 sb.append("partial");
3218 }
3219 if (totalWindow != 0) {
3220 if (needComma) {
3221 sb.append(", ");
3222 }
3223 needComma = true;
3224 formatTimeMs(sb, totalWindow);
3225 sb.append("window");
3226 }
3227 sb.append(" realtime");
3228 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 }
3231 }
3232
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003233 Map<String, ? extends Timer> syncs = u.getSyncStats();
3234 if (syncs.size() > 0) {
3235 for (Map.Entry<String, ? extends Timer> ent : syncs.entrySet()) {
3236 Timer timer = ent.getValue();
3237 // Convert from microseconds to milliseconds with rounding
3238 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3239 int count = timer.getCountLocked(which);
3240 sb.setLength(0);
3241 sb.append(prefix);
3242 sb.append(" Sync ");
3243 sb.append(ent.getKey());
3244 sb.append(": ");
3245 if (totalTime != 0) {
3246 formatTimeMs(sb, totalTime);
3247 sb.append("realtime (");
3248 sb.append(count);
3249 sb.append(" times)");
3250 } else {
3251 sb.append("(not used)");
3252 }
3253 pw.println(sb.toString());
3254 uidActivity = true;
3255 }
3256 }
3257
3258 Map<String, ? extends Timer> jobs = u.getJobStats();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003259 if (jobs.size() > 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003260 for (Map.Entry<String, ? extends Timer> ent : jobs.entrySet()) {
3261 Timer timer = ent.getValue();
3262 // Convert from microseconds to milliseconds with rounding
3263 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3264 int count = timer.getCountLocked(which);
3265 sb.setLength(0);
3266 sb.append(prefix);
3267 sb.append(" Job ");
3268 sb.append(ent.getKey());
3269 sb.append(": ");
3270 if (totalTime != 0) {
3271 formatTimeMs(sb, totalTime);
3272 sb.append("realtime (");
3273 sb.append(count);
3274 sb.append(" times)");
3275 } else {
3276 sb.append("(not used)");
3277 }
3278 pw.println(sb.toString());
3279 uidActivity = true;
3280 }
3281 }
3282
Dianne Hackborn61659e52014-07-09 16:13:01 -07003283 SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3284 int NSE = sensors.size();
3285 for (int ise=0; ise<NSE; ise++) {
3286 Uid.Sensor se = sensors.valueAt(ise);
3287 int sensorNumber = sensors.keyAt(ise);
3288 sb.setLength(0);
3289 sb.append(prefix);
3290 sb.append(" Sensor ");
3291 int handle = se.getHandle();
3292 if (handle == Uid.Sensor.GPS) {
3293 sb.append("GPS");
3294 } else {
3295 sb.append(handle);
3296 }
3297 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298
Dianne Hackborn61659e52014-07-09 16:13:01 -07003299 Timer timer = se.getSensorTime();
3300 if (timer != null) {
3301 // Convert from microseconds to milliseconds with rounding
3302 long totalTime = (timer.getTotalTimeLocked(
3303 rawRealtime, which) + 500) / 1000;
3304 int count = timer.getCountLocked(which);
3305 //timer.logState();
3306 if (totalTime != 0) {
3307 formatTimeMs(sb, totalTime);
3308 sb.append("realtime (");
3309 sb.append(count);
3310 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 } else {
3312 sb.append("(not used)");
3313 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003314 } else {
3315 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003317
3318 pw.println(sb.toString());
3319 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 }
3321
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003322 Timer vibTimer = u.getVibratorOnTimer();
3323 if (vibTimer != null) {
3324 // Convert from microseconds to milliseconds with rounding
3325 long totalTime = (vibTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003326 rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003327 int count = vibTimer.getCountLocked(which);
3328 //timer.logState();
3329 if (totalTime != 0) {
3330 sb.setLength(0);
3331 sb.append(prefix);
3332 sb.append(" Vibrator: ");
3333 formatTimeMs(sb, totalTime);
3334 sb.append("realtime (");
3335 sb.append(count);
3336 sb.append(" times)");
3337 pw.println(sb.toString());
3338 uidActivity = true;
3339 }
3340 }
3341
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003342 Timer fgTimer = u.getForegroundActivityTimer();
3343 if (fgTimer != null) {
3344 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003345 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003346 int count = fgTimer.getCountLocked(which);
3347 if (totalTime != 0) {
3348 sb.setLength(0);
3349 sb.append(prefix);
3350 sb.append(" Foreground activities: ");
3351 formatTimeMs(sb, totalTime);
3352 sb.append("realtime (");
3353 sb.append(count);
3354 sb.append(" times)");
3355 pw.println(sb.toString());
3356 uidActivity = true;
3357 }
3358 }
3359
Dianne Hackborn61659e52014-07-09 16:13:01 -07003360 long totalStateTime = 0;
3361 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
3362 long time = u.getProcessStateTime(ips, rawRealtime, which);
3363 if (time > 0) {
3364 totalStateTime += time;
3365 sb.setLength(0);
3366 sb.append(prefix);
3367 sb.append(" ");
3368 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
3369 sb.append(" for: ");
3370 formatTimeMs(sb, (totalStateTime + 500) / 1000);
3371 pw.println(sb.toString());
3372 uidActivity = true;
3373 }
3374 }
3375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
3377 if (processStats.size() > 0) {
3378 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
3379 : processStats.entrySet()) {
3380 Uid.Proc ps = ent.getValue();
3381 long userTime;
3382 long systemTime;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003383 long foregroundTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 int starts;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003385 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003386
3387 userTime = ps.getUserTime(which);
3388 systemTime = ps.getSystemTime(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003389 foregroundTime = ps.getForegroundTime(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 starts = ps.getStarts(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003391 final int numCrashes = ps.getNumCrashes(which);
3392 final int numAnrs = ps.getNumAnrs(which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003393 numExcessive = which == STATS_SINCE_CHARGED
Dianne Hackborn287952c2010-09-22 22:34:31 -07003394 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003395
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003396 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003397 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003398 sb.setLength(0);
3399 sb.append(prefix); sb.append(" Proc ");
3400 sb.append(ent.getKey()); sb.append(":\n");
3401 sb.append(prefix); sb.append(" CPU: ");
3402 formatTime(sb, userTime); sb.append("usr + ");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003403 formatTime(sb, systemTime); sb.append("krn ; ");
3404 formatTime(sb, foregroundTime); sb.append("fg");
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003405 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
Dianne Hackbornb8071d792010-09-09 16:45:15 -07003406 sb.append("\n"); sb.append(prefix); sb.append(" ");
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003407 boolean hasOne = false;
3408 if (starts != 0) {
3409 hasOne = true;
3410 sb.append(starts); sb.append(" starts");
3411 }
3412 if (numCrashes != 0) {
3413 if (hasOne) {
3414 sb.append(", ");
3415 }
3416 hasOne = true;
3417 sb.append(numCrashes); sb.append(" crashes");
3418 }
3419 if (numAnrs != 0) {
3420 if (hasOne) {
3421 sb.append(", ");
3422 }
3423 sb.append(numAnrs); sb.append(" anrs");
3424 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -07003425 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003426 pw.println(sb.toString());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003427 for (int e=0; e<numExcessive; e++) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07003428 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003429 if (ew != null) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07003430 pw.print(prefix); pw.print(" * Killed for ");
3431 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
3432 pw.print("wake lock");
3433 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
3434 pw.print("cpu");
3435 } else {
3436 pw.print("unknown");
3437 }
3438 pw.print(" use: ");
Dianne Hackborn1ebccf52010-08-15 13:04:34 -07003439 TimeUtils.formatDuration(ew.usedTime, pw);
3440 pw.print(" over ");
3441 TimeUtils.formatDuration(ew.overTime, pw);
Robert Greenwalta029ea12013-09-25 16:38:12 -07003442 if (ew.overTime != 0) {
3443 pw.print(" (");
3444 pw.print((ew.usedTime*100)/ew.overTime);
3445 pw.println("%)");
3446 }
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003447 }
3448 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003449 uidActivity = true;
3450 }
3451 }
3452 }
3453
3454 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
3455 if (packageStats.size() > 0) {
3456 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
3457 : packageStats.entrySet()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003458 pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003459 boolean apkActivity = false;
3460 Uid.Pkg ps = ent.getValue();
3461 int wakeups = ps.getWakeups(which);
3462 if (wakeups != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003463 pw.print(prefix); pw.print(" ");
3464 pw.print(wakeups); pw.println(" wakeup alarms");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003465 apkActivity = true;
3466 }
3467 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3468 if (serviceStats.size() > 0) {
3469 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
3470 : serviceStats.entrySet()) {
3471 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
3472 long startTime = ss.getStartTime(batteryUptime, which);
3473 int starts = ss.getStarts(which);
3474 int launches = ss.getLaunches(which);
3475 if (startTime != 0 || starts != 0 || launches != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003476 sb.setLength(0);
3477 sb.append(prefix); sb.append(" Service ");
3478 sb.append(sent.getKey()); sb.append(":\n");
3479 sb.append(prefix); sb.append(" Created for: ");
3480 formatTimeMs(sb, startTime / 1000);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003481 sb.append("uptime\n");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003482 sb.append(prefix); sb.append(" Starts: ");
3483 sb.append(starts);
3484 sb.append(", launches: "); sb.append(launches);
3485 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 apkActivity = true;
3487 }
3488 }
3489 }
3490 if (!apkActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003491 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 }
3493 uidActivity = true;
3494 }
3495 }
3496 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003497 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003498 }
3499 }
3500 }
3501
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003502 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003503 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003504 int diff = oldval ^ newval;
3505 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003506 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003507 for (int i=0; i<descriptions.length; i++) {
3508 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003509 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003510 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003511 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003512 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003513 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003514 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
3515 didWake = true;
3516 pw.print("=");
3517 if (longNames) {
3518 UserHandle.formatUid(pw, wakelockTag.uid);
3519 pw.print(":\"");
3520 pw.print(wakelockTag.string);
3521 pw.print("\"");
3522 } else {
3523 pw.print(wakelockTag.poolIdx);
3524 }
3525 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003526 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003527 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003528 pw.print("=");
3529 int val = (newval&bd.mask)>>bd.shift;
3530 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003531 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003532 } else {
3533 pw.print(val);
3534 }
3535 }
3536 }
3537 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003538 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07003539 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003540 if (longNames) {
3541 UserHandle.formatUid(pw, wakelockTag.uid);
3542 pw.print(":\"");
3543 pw.print(wakelockTag.string);
3544 pw.print("\"");
3545 } else {
3546 pw.print(wakelockTag.poolIdx);
3547 }
3548 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003549 }
3550
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003551 public void prepareForDumpLocked() {
3552 }
3553
3554 public static class HistoryPrinter {
3555 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003556 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003557 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003558 int oldStatus = -1;
3559 int oldHealth = -1;
3560 int oldPlug = -1;
3561 int oldTemp = -1;
3562 int oldVolt = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003563 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003564
Dianne Hackborn3251b902014-06-20 14:40:53 -07003565 void reset() {
3566 oldState = oldState2 = 0;
3567 oldLevel = -1;
3568 oldStatus = -1;
3569 oldHealth = -1;
3570 oldPlug = -1;
3571 oldTemp = -1;
3572 oldVolt = -1;
3573 }
3574
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003575 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003576 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003577 if (!checkin) {
3578 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003579 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003580 pw.print(" (");
3581 pw.print(rec.numReadInts);
3582 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003583 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003584 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
3585 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003586 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003587 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003588 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003589 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003590 }
3591 lastTime = rec.time;
3592 }
3593 if (rec.cmd == HistoryItem.CMD_START) {
3594 if (checkin) {
3595 pw.print(":");
3596 }
3597 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003598 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07003599 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
3600 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08003601 if (checkin) {
3602 pw.print(":");
3603 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07003604 if (rec.cmd == HistoryItem.CMD_RESET) {
3605 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003606 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07003607 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08003608 pw.print("TIME:");
3609 if (checkin) {
3610 pw.println(rec.currentTime);
3611 } else {
3612 pw.print(" ");
3613 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
3614 rec.currentTime).toString());
3615 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08003616 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
3617 if (checkin) {
3618 pw.print(":");
3619 }
3620 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003621 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
3622 if (checkin) {
3623 pw.print(":");
3624 }
3625 pw.println("*OVERFLOW*");
3626 } else {
3627 if (!checkin) {
3628 if (rec.batteryLevel < 10) pw.print("00");
3629 else if (rec.batteryLevel < 100) pw.print("0");
3630 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003631 if (verbose) {
3632 pw.print(" ");
3633 if (rec.states < 0) ;
3634 else if (rec.states < 0x10) pw.print("0000000");
3635 else if (rec.states < 0x100) pw.print("000000");
3636 else if (rec.states < 0x1000) pw.print("00000");
3637 else if (rec.states < 0x10000) pw.print("0000");
3638 else if (rec.states < 0x100000) pw.print("000");
3639 else if (rec.states < 0x1000000) pw.print("00");
3640 else if (rec.states < 0x10000000) pw.print("0");
3641 pw.print(Integer.toHexString(rec.states));
3642 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003643 } else {
3644 if (oldLevel != rec.batteryLevel) {
3645 oldLevel = rec.batteryLevel;
3646 pw.print(",Bl="); pw.print(rec.batteryLevel);
3647 }
3648 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003649 if (oldStatus != rec.batteryStatus) {
3650 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003651 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003652 switch (oldStatus) {
3653 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003654 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003655 break;
3656 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003657 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003658 break;
3659 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003660 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003661 break;
3662 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003663 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003664 break;
3665 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003666 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003667 break;
3668 default:
3669 pw.print(oldStatus);
3670 break;
3671 }
3672 }
3673 if (oldHealth != rec.batteryHealth) {
3674 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003675 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003676 switch (oldHealth) {
3677 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003678 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003679 break;
3680 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003681 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003682 break;
3683 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003684 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003685 break;
3686 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003687 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003688 break;
3689 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003690 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003691 break;
3692 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003693 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003694 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08003695 case BatteryManager.BATTERY_HEALTH_COLD:
3696 pw.print(checkin ? "c" : "cold");
3697 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003698 default:
3699 pw.print(oldHealth);
3700 break;
3701 }
3702 }
3703 if (oldPlug != rec.batteryPlugType) {
3704 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003705 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003706 switch (oldPlug) {
3707 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003708 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003709 break;
3710 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003711 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003712 break;
3713 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003714 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003715 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07003716 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003717 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07003718 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003719 default:
3720 pw.print(oldPlug);
3721 break;
3722 }
3723 }
3724 if (oldTemp != rec.batteryTemperature) {
3725 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003726 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003727 pw.print(oldTemp);
3728 }
3729 if (oldVolt != rec.batteryVoltage) {
3730 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003731 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003732 pw.print(oldVolt);
3733 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003734 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003735 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003736 printBitDescriptions(pw, oldState2, rec.states2, null,
3737 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003738 if (rec.wakeReasonTag != null) {
3739 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07003740 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003741 pw.print(rec.wakeReasonTag.poolIdx);
3742 } else {
3743 pw.print(" wake_reason=");
3744 pw.print(rec.wakeReasonTag.uid);
3745 pw.print(":\"");
3746 pw.print(rec.wakeReasonTag.string);
3747 pw.print("\"");
3748 }
3749 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08003750 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08003751 pw.print(checkin ? "," : " ");
3752 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
3753 pw.print("+");
3754 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
3755 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08003756 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08003757 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
3758 : HISTORY_EVENT_NAMES;
3759 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
3760 | HistoryItem.EVENT_FLAG_FINISH);
3761 if (idx >= 0 && idx < eventNames.length) {
3762 pw.print(eventNames[idx]);
3763 } else {
3764 pw.print(checkin ? "Ev" : "event");
3765 pw.print(idx);
3766 }
3767 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08003768 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003769 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08003770 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003771 UserHandle.formatUid(pw, rec.eventTag.uid);
3772 pw.print(":\"");
3773 pw.print(rec.eventTag.string);
3774 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08003775 }
3776 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003777 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08003778 if (rec.stepDetails != null) {
3779 if (!checkin) {
3780 pw.print(" Details: cpu=");
3781 pw.print(rec.stepDetails.userTime);
3782 pw.print("u+");
3783 pw.print(rec.stepDetails.systemTime);
3784 pw.print("s");
3785 if (rec.stepDetails.appCpuUid1 >= 0) {
3786 pw.print(" (");
3787 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
3788 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
3789 if (rec.stepDetails.appCpuUid2 >= 0) {
3790 pw.print(", ");
3791 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
3792 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
3793 }
3794 if (rec.stepDetails.appCpuUid3 >= 0) {
3795 pw.print(", ");
3796 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
3797 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
3798 }
3799 pw.print(')');
3800 }
3801 pw.println();
3802 pw.print(" /proc/stat=");
3803 pw.print(rec.stepDetails.statUserTime);
3804 pw.print(" usr, ");
3805 pw.print(rec.stepDetails.statSystemTime);
3806 pw.print(" sys, ");
3807 pw.print(rec.stepDetails.statIOWaitTime);
3808 pw.print(" io, ");
3809 pw.print(rec.stepDetails.statIrqTime);
3810 pw.print(" irq, ");
3811 pw.print(rec.stepDetails.statSoftIrqTime);
3812 pw.print(" sirq, ");
3813 pw.print(rec.stepDetails.statIdlTime);
3814 pw.print(" idle");
3815 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
3816 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
3817 + rec.stepDetails.statSoftIrqTime;
3818 int total = totalRun + rec.stepDetails.statIdlTime;
3819 if (total > 0) {
3820 pw.print(" (");
3821 float perc = ((float)totalRun) / ((float)total) * 100;
3822 pw.print(String.format("%.1f%%", perc));
3823 pw.print(" of ");
3824 StringBuilder sb = new StringBuilder(64);
3825 formatTimeMsNoSpace(sb, total*10);
3826 pw.print(sb);
3827 pw.print(")");
3828 }
3829 pw.println();
3830 } else {
3831 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
3832 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
3833 pw.print(rec.stepDetails.userTime);
3834 pw.print(":");
3835 pw.print(rec.stepDetails.systemTime);
3836 if (rec.stepDetails.appCpuUid1 >= 0) {
3837 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
3838 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
3839 if (rec.stepDetails.appCpuUid2 >= 0) {
3840 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
3841 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
3842 }
3843 if (rec.stepDetails.appCpuUid3 >= 0) {
3844 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
3845 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
3846 }
3847 }
3848 pw.println();
3849 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
3850 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
3851 pw.print(rec.stepDetails.statUserTime);
3852 pw.print(',');
3853 pw.print(rec.stepDetails.statSystemTime);
3854 pw.print(',');
3855 pw.print(rec.stepDetails.statIOWaitTime);
3856 pw.print(',');
3857 pw.print(rec.stepDetails.statIrqTime);
3858 pw.print(',');
3859 pw.print(rec.stepDetails.statSoftIrqTime);
3860 pw.print(',');
3861 pw.print(rec.stepDetails.statIdlTime);
3862 pw.println();
3863 }
3864 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08003865 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003866 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003867 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003868 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08003869
3870 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
3871 UserHandle.formatUid(pw, uid);
3872 pw.print("=");
3873 pw.print(utime);
3874 pw.print("u+");
3875 pw.print(stime);
3876 pw.print("s");
3877 }
3878
3879 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
3880 pw.print('/');
3881 pw.print(uid);
3882 pw.print(":");
3883 pw.print(utime);
3884 pw.print(":");
3885 pw.print(stime);
3886 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003887 }
3888
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003889 private void printSizeValue(PrintWriter pw, long size) {
3890 float result = size;
3891 String suffix = "";
3892 if (result >= 10*1024) {
3893 suffix = "KB";
3894 result = result / 1024;
3895 }
3896 if (result >= 10*1024) {
3897 suffix = "MB";
3898 result = result / 1024;
3899 }
3900 if (result >= 10*1024) {
3901 suffix = "GB";
3902 result = result / 1024;
3903 }
3904 if (result >= 10*1024) {
3905 suffix = "TB";
3906 result = result / 1024;
3907 }
3908 if (result >= 10*1024) {
3909 suffix = "PB";
3910 result = result / 1024;
3911 }
3912 pw.print((int)result);
3913 pw.print(suffix);
3914 }
3915
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08003916 private static boolean dumpTimeEstimate(PrintWriter pw, String label, long[] steps,
3917 int count, long modesOfInterest, long modeValues) {
3918 if (count <= 0) {
3919 return false;
3920 }
3921 long total = 0;
3922 int numOfInterest = 0;
3923 for (int i=0; i<count; i++) {
3924 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
3925 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
3926 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
3927 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
3928 // If the modes of interest didn't change during this step period...
3929 if ((modMode&modesOfInterest) == 0) {
3930 // And the mode values during this period match those we are measuring...
3931 if ((initMode&modesOfInterest) == modeValues) {
3932 // Then this can be used to estimate the total time!
3933 numOfInterest++;
3934 total += steps[i] & STEP_LEVEL_TIME_MASK;
3935 }
3936 }
3937 }
3938 if (numOfInterest <= 0) {
3939 return false;
3940 }
3941
3942 // The estimated time is the average time we spend in each level, multipled
3943 // by 100 -- the total number of battery levels
3944 long estimatedTime = (total / numOfInterest) * 100;
3945
3946 pw.print(label);
3947 StringBuilder sb = new StringBuilder(64);
3948 formatTimeMs(sb, estimatedTime);
3949 pw.print(sb);
3950 pw.println();
3951
3952 return true;
3953 }
3954
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07003955 private static boolean dumpDurationSteps(PrintWriter pw, String header, long[] steps,
3956 int count, boolean checkin) {
3957 if (count <= 0) {
3958 return false;
3959 }
3960 if (!checkin) {
3961 pw.println(header);
3962 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07003963 String[] lineArgs = new String[4];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07003964 for (int i=0; i<count; i++) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07003965 long duration = steps[i] & STEP_LEVEL_TIME_MASK;
3966 int level = (int)((steps[i] & STEP_LEVEL_LEVEL_MASK)
3967 >> STEP_LEVEL_LEVEL_SHIFT);
3968 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
3969 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
3970 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
3971 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07003972 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07003973 lineArgs[0] = Long.toString(duration);
3974 lineArgs[1] = Integer.toString(level);
3975 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
3976 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
3977 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
3978 case Display.STATE_ON: lineArgs[2] = "s+"; break;
3979 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
3980 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
3981 default: lineArgs[1] = "?"; break;
3982 }
3983 } else {
3984 lineArgs[2] = "";
3985 }
3986 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
3987 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
3988 } else {
3989 lineArgs[3] = "";
3990 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07003991 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
3992 } else {
3993 pw.print(" #"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07003994 TimeUtils.formatDuration(duration, pw);
3995 pw.print(" to "); pw.print(level);
3996 boolean haveModes = false;
3997 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
3998 pw.print(" (");
3999 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4000 case Display.STATE_OFF: pw.print("screen-off"); break;
4001 case Display.STATE_ON: pw.print("screen-on"); break;
4002 case Display.STATE_DOZE: pw.print("screen-doze"); break;
4003 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
4004 default: lineArgs[1] = "screen-?"; break;
4005 }
4006 haveModes = true;
4007 }
4008 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4009 pw.print(haveModes ? ", " : " (");
4010 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
4011 ? "power-save-on" : "power-save-off");
4012 haveModes = true;
4013 }
4014 if (haveModes) {
4015 pw.print(")");
4016 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004017 pw.println();
4018 }
4019 }
4020 return true;
4021 }
4022
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004023 public static final int DUMP_UNPLUGGED_ONLY = 1<<0;
4024 public static final int DUMP_CHARGED_ONLY = 1<<1;
4025 public static final int DUMP_HISTORY_ONLY = 1<<2;
4026 public static final int DUMP_INCLUDE_HISTORY = 1<<3;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004027 public static final int DUMP_VERBOSE = 1<<4;
Dianne Hackbornd953c532014-08-16 18:17:38 -07004028 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<5;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004029
Dianne Hackborn37de0982014-05-09 09:32:18 -07004030 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
4031 final HistoryPrinter hprinter = new HistoryPrinter();
4032 final HistoryItem rec = new HistoryItem();
4033 long lastTime = -1;
4034 long baseTime = -1;
4035 boolean printed = false;
4036 HistoryEventTracker tracker = null;
4037 while (getNextHistoryLocked(rec)) {
4038 lastTime = rec.time;
4039 if (baseTime < 0) {
4040 baseTime = lastTime;
4041 }
4042 if (rec.time >= histStart) {
4043 if (histStart >= 0 && !printed) {
4044 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07004045 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004046 || rec.cmd == HistoryItem.CMD_START
4047 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004048 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004049 hprinter.printNextItem(pw, rec, baseTime, checkin,
4050 (flags&DUMP_VERBOSE) != 0);
4051 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004052 } else if (rec.currentTime != 0) {
4053 printed = true;
4054 byte cmd = rec.cmd;
4055 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004056 hprinter.printNextItem(pw, rec, baseTime, checkin,
4057 (flags&DUMP_VERBOSE) != 0);
4058 rec.cmd = cmd;
4059 }
4060 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004061 if (rec.cmd != HistoryItem.CMD_UPDATE) {
4062 hprinter.printNextItem(pw, rec, baseTime, checkin,
4063 (flags&DUMP_VERBOSE) != 0);
4064 rec.cmd = HistoryItem.CMD_UPDATE;
4065 }
4066 int oldEventCode = rec.eventCode;
4067 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004068 rec.eventTag = new HistoryTag();
4069 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
4070 HashMap<String, SparseIntArray> active
4071 = tracker.getStateForEvent(i);
4072 if (active == null) {
4073 continue;
4074 }
4075 for (HashMap.Entry<String, SparseIntArray> ent
4076 : active.entrySet()) {
4077 SparseIntArray uids = ent.getValue();
4078 for (int j=0; j<uids.size(); j++) {
4079 rec.eventCode = i;
4080 rec.eventTag.string = ent.getKey();
4081 rec.eventTag.uid = uids.keyAt(j);
4082 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07004083 hprinter.printNextItem(pw, rec, baseTime, checkin,
4084 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004085 rec.wakeReasonTag = null;
4086 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004087 }
4088 }
4089 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004090 rec.eventCode = oldEventCode;
4091 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004092 tracker = null;
4093 }
4094 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004095 hprinter.printNextItem(pw, rec, baseTime, checkin,
4096 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07004097 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
4098 // This is an attempt to aggregate the previous state and generate
4099 // fake events to reflect that state at the point where we start
4100 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07004101 if (tracker == null) {
4102 tracker = new HistoryEventTracker();
4103 }
4104 tracker.updateState(rec.eventCode, rec.eventTag.string,
4105 rec.eventTag.uid, rec.eventTag.poolIdx);
4106 }
4107 }
4108 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07004109 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004110 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
4111 }
4112 }
4113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 /**
4115 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
4116 *
4117 * @param pw a Printer to receive the dump output.
4118 */
4119 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004120 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004121 prepareForDumpLocked();
4122
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004123 final boolean filtering =
4124 (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004125
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004126 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004127 final long historyTotalSize = getHistoryTotalSize();
4128 final long historyUsedSize = getHistoryUsedSize();
4129 if (startIteratingHistoryLocked()) {
4130 try {
4131 pw.print("Battery History (");
4132 pw.print((100*historyUsedSize)/historyTotalSize);
4133 pw.print("% used, ");
4134 printSizeValue(pw, historyUsedSize);
4135 pw.print(" used of ");
4136 printSizeValue(pw, historyTotalSize);
4137 pw.print(", ");
4138 pw.print(getHistoryStringPoolSize());
4139 pw.print(" strings using ");
4140 printSizeValue(pw, getHistoryStringPoolBytes());
4141 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07004142 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004143 pw.println();
4144 } finally {
4145 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004146 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004147 }
4148
4149 if (startIteratingOldHistoryLocked()) {
4150 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004151 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004152 pw.println("Old battery History:");
4153 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004154 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004155 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004156 if (baseTime < 0) {
4157 baseTime = rec.time;
4158 }
4159 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004160 }
4161 pw.println();
4162 } finally {
4163 finishIteratingOldHistoryLocked();
4164 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07004165 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004166 }
4167
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004168 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08004169 return;
4170 }
4171
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004172 if (!filtering) {
4173 SparseArray<? extends Uid> uidStats = getUidStats();
4174 final int NU = uidStats.size();
4175 boolean didPid = false;
4176 long nowRealtime = SystemClock.elapsedRealtime();
4177 for (int i=0; i<NU; i++) {
4178 Uid uid = uidStats.valueAt(i);
4179 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
4180 if (pids != null) {
4181 for (int j=0; j<pids.size(); j++) {
4182 Uid.Pid pid = pids.valueAt(j);
4183 if (!didPid) {
4184 pw.println("Per-PID Stats:");
4185 didPid = true;
4186 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004187 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
4188 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004189 pw.print(" PID "); pw.print(pids.keyAt(j));
4190 pw.print(" wake time: ");
4191 TimeUtils.formatDuration(time, pw);
4192 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004193 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004194 }
4195 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004196 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004197 pw.println();
4198 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004199 }
4200
4201 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004202 if (dumpDurationSteps(pw, "Discharge step durations:", getDischargeStepDurationsArray(),
4203 getNumDischargeStepDurations(), false)) {
4204 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
4205 if (timeRemaining >= 0) {
4206 pw.print(" Estimated discharge time remaining: ");
4207 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4208 pw.println();
4209 }
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004210 dumpTimeEstimate(pw, " Estimated screen off time: ",
4211 getDischargeStepDurationsArray(), getNumDischargeStepDurations(),
4212 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
4213 (Display.STATE_OFF-1));
4214 dumpTimeEstimate(pw, " Estimated screen off power save time: ",
4215 getDischargeStepDurationsArray(), getNumDischargeStepDurations(),
4216 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
4217 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE);
4218 dumpTimeEstimate(pw, " Estimated screen on time: ",
4219 getDischargeStepDurationsArray(), getNumDischargeStepDurations(),
4220 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
4221 (Display.STATE_ON-1));
4222 dumpTimeEstimate(pw, " Estimated screen on power save time: ",
4223 getDischargeStepDurationsArray(), getNumDischargeStepDurations(),
4224 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
4225 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE);
4226 dumpTimeEstimate(pw, " Estimated screen doze time: ",
4227 getDischargeStepDurationsArray(), getNumDischargeStepDurations(),
4228 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
4229 (Display.STATE_DOZE-1));
4230 dumpTimeEstimate(pw, " Estimated screen doze power save time: ",
4231 getDischargeStepDurationsArray(), getNumDischargeStepDurations(),
4232 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
4233 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE);
4234 dumpTimeEstimate(pw, " Estimated screen doze suspend time: ",
4235 getDischargeStepDurationsArray(), getNumDischargeStepDurations(),
4236 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
4237 (Display.STATE_DOZE_SUSPEND-1));
4238 dumpTimeEstimate(pw, " Estimated screen doze suspend power save time: ",
4239 getDischargeStepDurationsArray(), getNumDischargeStepDurations(),
4240 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
4241 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004242 pw.println();
4243 }
4244 if (dumpDurationSteps(pw, "Charge step durations:", getChargeStepDurationsArray(),
4245 getNumChargeStepDurations(), false)) {
4246 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
4247 if (timeRemaining >= 0) {
4248 pw.print(" Estimated charge time remaining: ");
4249 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4250 pw.println();
4251 }
4252 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004253 }
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004254 pw.println("Statistics since last charge:");
4255 pw.println(" System starts: " + getStartCount()
4256 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07004257 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
4258 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004259 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004260 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004261 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
4262 pw.println("Statistics since last unplugged:");
Dianne Hackbornd953c532014-08-16 18:17:38 -07004263 dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid,
4264 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004266 }
4267
4268 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004269 public void dumpCheckinLocked(Context context, PrintWriter pw,
4270 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004271 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004272
4273 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0ee10f62015-01-14 16:16:13 -08004274 "12", getParcelVersion(), getStartPlatformVersion(), getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004275
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004276 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
4277
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004278 final boolean filtering =
4279 (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0;
4280
4281 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07004282 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004283 try {
4284 for (int i=0; i<getHistoryStringPoolSize(); i++) {
4285 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4286 pw.print(HISTORY_STRING_POOL); pw.print(',');
4287 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004288 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004289 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004290 pw.print(",\"");
4291 String str = getHistoryTagPoolString(i);
4292 str = str.replace("\\", "\\\\");
4293 str = str.replace("\"", "\\\"");
4294 pw.print(str);
4295 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004296 pw.println();
4297 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004298 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004299 } finally {
4300 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08004301 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004302 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004303 }
4304
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004305 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08004306 return;
4307 }
4308
Dianne Hackborne4a59512010-12-07 11:08:07 -08004309 if (apps != null) {
4310 SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
4311 for (int i=0; i<apps.size(); i++) {
4312 ApplicationInfo ai = apps.get(i);
4313 ArrayList<String> pkgs = uids.get(ai.uid);
4314 if (pkgs == null) {
4315 pkgs = new ArrayList<String>();
4316 uids.put(ai.uid, pkgs);
4317 }
4318 pkgs.add(ai.packageName);
4319 }
4320 SparseArray<? extends Uid> uidStats = getUidStats();
4321 final int NU = uidStats.size();
4322 String[] lineArgs = new String[2];
4323 for (int i=0; i<NU; i++) {
4324 int uid = uidStats.keyAt(i);
4325 ArrayList<String> pkgs = uids.get(uid);
4326 if (pkgs != null) {
4327 for (int j=0; j<pkgs.size(); j++) {
4328 lineArgs[0] = Integer.toString(uid);
4329 lineArgs[1] = pkgs.get(j);
4330 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
4331 (Object[])lineArgs);
4332 }
4333 }
4334 }
4335 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004336 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004337 dumpDurationSteps(pw, DISCHARGE_STEP_DATA, getDischargeStepDurationsArray(),
4338 getNumDischargeStepDurations(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004339 String[] lineArgs = new String[1];
4340 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
4341 if (timeRemaining >= 0) {
4342 lineArgs[0] = Long.toString(timeRemaining);
4343 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
4344 (Object[])lineArgs);
4345 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004346 dumpDurationSteps(pw, CHARGE_STEP_DATA, getChargeStepDurationsArray(),
4347 getNumChargeStepDurations(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004348 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
4349 if (timeRemaining >= 0) {
4350 lineArgs[0] = Long.toString(timeRemaining);
4351 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
4352 (Object[])lineArgs);
4353 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07004354 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
4355 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004356 }
4357 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
Dianne Hackbornd953c532014-08-16 18:17:38 -07004358 dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1,
4359 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 }
4361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004362}