blob: d96a0e9550681a976839dc0532473b44c405b6fd [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;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -080033import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070035import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070036import android.util.TimeUtils;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -070037import android.view.Display;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080038import com.android.internal.os.BatterySipper;
39import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
41/**
42 * A class providing access to battery usage statistics, including information on
43 * wakelocks, processes, packages, and services. All times are represented in microseconds
44 * except where indicated otherwise.
45 * @hide
46 */
47public abstract class BatteryStats implements Parcelable {
48
49 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070050
51 /** @hide */
52 public static final String SERVICE_NAME = "batterystats";
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 /**
55 * A constant indicating a partial wake lock timer.
56 */
57 public static final int WAKE_TYPE_PARTIAL = 0;
58
59 /**
60 * A constant indicating a full wake lock timer.
61 */
62 public static final int WAKE_TYPE_FULL = 1;
63
64 /**
65 * A constant indicating a window wake lock timer.
66 */
67 public static final int WAKE_TYPE_WINDOW = 2;
68
69 /**
70 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 */
72 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070073
74 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070075 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070076 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070077 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070078
79 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070080 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070081 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070082 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070083
84 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070085 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070086 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070087 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
Dianne Hackborn62793e42015-03-09 11:15:41 -070089 /**
90 * A constant indicating a wifi multicast timer
91 */
92 public static final int WIFI_MULTICAST_ENABLED = 7;
Robert Greenwalt5347bd42009-05-13 15:10:16 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070095 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070096 */
97 public static final int VIDEO_TURNED_ON = 8;
98
99 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800100 * A constant indicating a vibrator on timer
101 */
102 public static final int VIBRATOR_ON = 9;
103
104 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700105 * A constant indicating a foreground activity timer
106 */
107 public static final int FOREGROUND_ACTIVITY = 10;
108
109 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700110 * A constant indicating a wifi batched scan is active
111 */
112 public static final int WIFI_BATCHED_SCAN = 11;
113
114 /**
Dianne Hackborn61659e52014-07-09 16:13:01 -0700115 * A constant indicating a process state timer
116 */
117 public static final int PROCESS_STATE = 12;
118
119 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700120 * A constant indicating a sync timer
121 */
122 public static final int SYNC = 13;
123
124 /**
125 * A constant indicating a job timer
126 */
127 public static final int JOB = 14;
128
129 /**
Kweku Adamsd5379872014-11-24 17:34:05 -0800130 * A constant indicating an audio turn on timer
131 */
132 public static final int AUDIO_TURNED_ON = 15;
133
134 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 * Include all of the data in the stats, including previously saved data.
136 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700137 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138
139 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 * Include only the current run in the stats.
141 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700142 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143
144 /**
145 * Include only the run since the last time the device was unplugged in the stats.
146 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700147 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700148
149 // NOTE: Update this list if you add/change any stats above.
150 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700151 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700152 private static final String[] STAT_NAMES = { "l", "c", "u" };
153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 /**
155 * Bump the version on this if the checkin format changes.
156 */
Ashish Sharma213bb2f2014-07-07 17:14:52 -0700157 private static final int BATTERY_STATS_CHECKIN_VERSION = 9;
Evan Millar22ac0432009-03-31 11:33:18 -0700158
159 private static final long BYTES_PER_KB = 1024;
160 private static final long BYTES_PER_MB = 1048576; // 1024^2
161 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162
Dianne Hackborncd0e3352014-08-07 17:08:09 -0700163 private static final String VERSION_DATA = "vers";
Dianne Hackborne4a59512010-12-07 11:08:07 -0800164 private static final String UID_DATA = "uid";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700166 private static final String PROCESS_DATA = "pr";
167 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800168 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700169 private static final String FOREGROUND_DATA = "fg";
Dianne Hackborn61659e52014-07-09 16:13:01 -0700170 private static final String STATE_TIME_DATA = "st";
Evan Millare84de8d2009-04-02 22:16:12 -0700171 private static final String WAKELOCK_DATA = "wl";
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700172 private static final String SYNC_DATA = "sy";
173 private static final String JOB_DATA = "jb";
Evan Millarc64edde2009-04-18 12:26:32 -0700174 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700175 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700176 private static final String NETWORK_DATA = "nt";
177 private static final String USER_ACTIVITY_DATA = "ua";
178 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800179 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700180 private static final String BATTERY_LEVEL_DATA = "lv";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700181 private static final String WIFI_DATA = "wfl";
Evan Millare84de8d2009-04-02 22:16:12 -0700182 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800183 private static final String GLOBAL_NETWORK_DATA = "gn";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800184 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700185 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700186 private static final String SCREEN_BRIGHTNESS_DATA = "br";
187 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700188 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700189 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
190 private static final String DATA_CONNECTION_TIME_DATA = "dct";
191 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800192 private static final String WIFI_STATE_TIME_DATA = "wst";
193 private static final String WIFI_STATE_COUNT_DATA = "wsc";
Dianne Hackborn3251b902014-06-20 14:40:53 -0700194 private static final String WIFI_SUPPL_STATE_TIME_DATA = "wsst";
195 private static final String WIFI_SUPPL_STATE_COUNT_DATA = "wssc";
196 private static final String WIFI_SIGNAL_STRENGTH_TIME_DATA = "wsgt";
197 private static final String WIFI_SIGNAL_STRENGTH_COUNT_DATA = "wsgc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800198 private static final String BLUETOOTH_STATE_TIME_DATA = "bst";
199 private static final String BLUETOOTH_STATE_COUNT_DATA = "bsc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800200 private static final String POWER_USE_SUMMARY_DATA = "pws";
201 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700202 private static final String DISCHARGE_STEP_DATA = "dsd";
203 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700204 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
205 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700207 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 private final Formatter mFormatter = new Formatter(mFormatBuilder);
209
210 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700211 * State for keeping track of counting information.
212 */
213 public static abstract class Counter {
214
215 /**
216 * Returns the count associated with this Counter for the
217 * selected type of statistics.
218 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700219 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700220 */
Evan Millarc64edde2009-04-18 12:26:32 -0700221 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700222
223 /**
224 * Temporary for debugging.
225 */
226 public abstract void logState(Printer pw, String prefix);
227 }
228
229 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700230 * State for keeping track of long counting information.
231 */
232 public static abstract class LongCounter {
233
234 /**
235 * Returns the count associated with this Counter for the
236 * selected type of statistics.
237 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700238 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700239 */
240 public abstract long getCountLocked(int which);
241
242 /**
243 * Temporary for debugging.
244 */
245 public abstract void logState(Printer pw, String prefix);
246 }
247
248 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 * State for keeping track of timing information.
250 */
251 public static abstract class Timer {
252
253 /**
254 * Returns the count associated with this Timer for the
255 * selected type of statistics.
256 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700257 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 */
Evan Millarc64edde2009-04-18 12:26:32 -0700259 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260
261 /**
262 * Returns the total time in microseconds associated with this Timer for the
263 * selected type of statistics.
264 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800265 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700266 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 * @return a time in microseconds
268 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800269 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700270
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 /**
272 * Temporary for debugging.
273 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700274 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 }
276
277 /**
278 * The statistics associated with a particular uid.
279 */
280 public static abstract class Uid {
281
282 /**
283 * Returns a mapping containing wakelock statistics.
284 *
285 * @return a Map from Strings to Uid.Wakelock objects.
286 */
287 public abstract Map<String, ? extends Wakelock> getWakelockStats();
288
289 /**
Dianne Hackbornfdb19562014-07-11 16:03:36 -0700290 * Returns a mapping containing sync statistics.
291 *
292 * @return a Map from Strings to Timer objects.
293 */
294 public abstract Map<String, ? extends Timer> getSyncStats();
295
296 /**
297 * Returns a mapping containing scheduled job statistics.
298 *
299 * @return a Map from Strings to Timer objects.
300 */
301 public abstract Map<String, ? extends Timer> getJobStats();
302
303 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 * The statistics associated with a particular wake lock.
305 */
306 public static abstract class Wakelock {
307 public abstract Timer getWakeTime(int type);
308 }
309
310 /**
311 * Returns a mapping containing sensor statistics.
312 *
313 * @return a Map from Integer sensor ids to Uid.Sensor objects.
314 */
Dianne Hackborn61659e52014-07-09 16:13:01 -0700315 public abstract SparseArray<? extends Sensor> getSensorStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316
317 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700318 * Returns a mapping containing active process data.
319 */
320 public abstract SparseArray<? extends Pid> getPidStats();
321
322 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 * Returns a mapping containing process statistics.
324 *
325 * @return a Map from Strings to Uid.Proc objects.
326 */
327 public abstract Map<String, ? extends Proc> getProcessStats();
328
329 /**
330 * Returns a mapping containing package statistics.
331 *
332 * @return a Map from Strings to Uid.Pkg objects.
333 */
334 public abstract Map<String, ? extends Pkg> getPackageStats();
335
336 /**
337 * {@hide}
338 */
339 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700340
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800341 public abstract void noteWifiRunningLocked(long elapsedRealtime);
342 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
343 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
344 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
345 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
346 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
347 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
348 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
349 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
350 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800351 public abstract void noteActivityResumedLocked(long elapsedRealtime);
352 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800353 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
354 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
355 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700356 public abstract int getWifiScanCount(int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800357 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
Dianne Hackborn62793e42015-03-09 11:15:41 -0700358 public abstract int getWifiBatchedScanCount(int csphBin, int which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800359 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
360 public abstract long getAudioTurnedOnTime(long elapsedRealtimeUs, int which);
361 public abstract long getVideoTurnedOnTime(long elapsedRealtimeUs, int which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700362 public abstract Timer getForegroundActivityTimer();
Dianne Hackborn61659e52014-07-09 16:13:01 -0700363
364 // Time this uid has any processes in foreground state.
365 public static final int PROCESS_STATE_FOREGROUND = 0;
366 // Time this uid has any process in active state (not cached).
367 public static final int PROCESS_STATE_ACTIVE = 1;
368 // Time this uid has any processes running at all.
369 public static final int PROCESS_STATE_RUNNING = 2;
370 // Total number of process states we track.
371 public static final int NUM_PROCESS_STATE = 3;
372
373 static final String[] PROCESS_STATE_NAMES = {
374 "Foreground", "Active", "Running"
375 };
376
377 public abstract long getProcessStateTime(int state, long elapsedRealtimeUs, int which);
378
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800379 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380
Robert Greenwalta029ea12013-09-25 16:38:12 -0700381 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
382
Dianne Hackborn617f8772009-03-31 15:04:46 -0700383 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700384 * Note that these must match the constants in android.os.PowerManager.
385 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
386 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700387 */
388 static final String[] USER_ACTIVITY_TYPES = {
Jeff Browndf693de2012-07-27 12:03:38 -0700389 "other", "button", "touch"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700390 };
391
Jeff Browndf693de2012-07-27 12:03:38 -0700392 public static final int NUM_USER_ACTIVITY_TYPES = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700393
Dianne Hackborn617f8772009-03-31 15:04:46 -0700394 public abstract void noteUserActivityLocked(int type);
395 public abstract boolean hasUserActivity();
396 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700397
398 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800399 public abstract long getNetworkActivityBytes(int type, int which);
400 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800401 public abstract long getMobileRadioActiveTime(int which);
402 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800405 /*
406 * FIXME: it's not correct to use this magic value because it
407 * could clash with a sensor handle (which are defined by
408 * the sensor HAL, and therefore out of our control
409 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 // Magic sensor number for the GPS.
411 public static final int GPS = -10000;
412
413 public abstract int getHandle();
414
415 public abstract Timer getSensorTime();
416 }
417
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700418 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800419 public int mWakeNesting;
420 public long mWakeSumMs;
421 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700422 }
423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 /**
425 * The statistics associated with a particular process.
426 */
427 public static abstract class Proc {
428
Dianne Hackborn287952c2010-09-22 22:34:31 -0700429 public static class ExcessivePower {
430 public static final int TYPE_WAKE = 1;
431 public static final int TYPE_CPU = 2;
432
433 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700434 public long overTime;
435 public long usedTime;
436 }
437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800439 * Returns true if this process is still active in the battery stats.
440 */
441 public abstract boolean isActive();
442
443 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700444 * Returns the total time (in milliseconds) spent executing in user code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700446 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 */
448 public abstract long getUserTime(int which);
449
450 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700451 * Returns the total time (in milliseconds) spent executing in system code.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700453 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 */
455 public abstract long getSystemTime(int which);
456
457 /**
458 * Returns the number of times the process has been started.
459 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700460 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 */
462 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700463
464 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -0800465 * Returns the number of times the process has crashed.
466 *
467 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
468 */
469 public abstract int getNumCrashes(int which);
470
471 /**
472 * Returns the number of times the process has ANRed.
473 *
474 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
475 */
476 public abstract int getNumAnrs(int which);
477
478 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700479 * Returns the cpu time (milliseconds) spent while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700480 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700481 * @return foreground cpu time in microseconds
482 */
483 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700484
485 /**
Adam Lesinski33dac552015-03-09 15:24:48 -0700486 * Returns the approximate cpu time (in milliseconds) spent at a certain CPU speed.
Amith Yamasanie43530a2009-08-21 13:11:37 -0700487 * @param speedStep the index of the CPU speed. This is not the actual speed of the
488 * CPU.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700489 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanie43530a2009-08-21 13:11:37 -0700490 * @see BatteryStats#getCpuSpeedSteps()
491 */
492 public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700493
Dianne Hackborn287952c2010-09-22 22:34:31 -0700494 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700495
Dianne Hackborn287952c2010-09-22 22:34:31 -0700496 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 }
498
499 /**
500 * The statistics associated with a particular package.
501 */
502 public static abstract class Pkg {
503
504 /**
505 * Returns the number of times this package has done something that could wake up the
506 * device from sleep.
507 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700508 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 */
510 public abstract int getWakeups(int which);
511
512 /**
513 * Returns a mapping containing service statistics.
514 */
515 public abstract Map<String, ? extends Serv> getServiceStats();
516
517 /**
518 * The statistics associated with a particular service.
519 */
520 public abstract class Serv {
521
522 /**
523 * Returns the amount of time spent started.
524 *
525 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700526 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 * @return
528 */
529 public abstract long getStartTime(long batteryUptime, int which);
530
531 /**
532 * Returns the total number of times startService() has been called.
533 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700534 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 */
536 public abstract int getStarts(int which);
537
538 /**
539 * Returns the total number times the service has been launched.
540 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700541 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 */
543 public abstract int getLaunches(int which);
544 }
545 }
546 }
547
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800548 public static final class LevelStepTracker {
549 public long mLastStepTime = -1;
550 public int mNumStepDurations;
551 public final long[] mStepDurations;
552
553 public LevelStepTracker(int maxLevelSteps) {
554 mStepDurations = new long[maxLevelSteps];
555 }
556
557 public LevelStepTracker(int numSteps, long[] steps) {
558 mNumStepDurations = numSteps;
559 mStepDurations = new long[numSteps];
560 System.arraycopy(steps, 0, mStepDurations, 0, numSteps);
561 }
562
563 public long getDurationAt(int index) {
564 return mStepDurations[index] & STEP_LEVEL_TIME_MASK;
565 }
566
567 public int getLevelAt(int index) {
568 return (int)((mStepDurations[index] & STEP_LEVEL_LEVEL_MASK)
569 >> STEP_LEVEL_LEVEL_SHIFT);
570 }
571
572 public int getInitModeAt(int index) {
573 return (int)((mStepDurations[index] & STEP_LEVEL_INITIAL_MODE_MASK)
574 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
575 }
576
577 public int getModModeAt(int index) {
578 return (int)((mStepDurations[index] & STEP_LEVEL_MODIFIED_MODE_MASK)
579 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
580 }
581
582 private void appendHex(long val, int topOffset, StringBuilder out) {
583 boolean hasData = false;
584 while (topOffset >= 0) {
585 int digit = (int)( (val>>topOffset) & 0xf );
586 topOffset -= 4;
587 if (!hasData && digit == 0) {
588 continue;
589 }
590 hasData = true;
591 if (digit >= 0 && digit <= 9) {
592 out.append((char)('0' + digit));
593 } else {
594 out.append((char)('a' + digit - 10));
595 }
596 }
597 }
598
599 public void encodeEntryAt(int index, StringBuilder out) {
600 long item = mStepDurations[index];
601 long duration = item & STEP_LEVEL_TIME_MASK;
602 int level = (int)((item & STEP_LEVEL_LEVEL_MASK)
603 >> STEP_LEVEL_LEVEL_SHIFT);
604 int initMode = (int)((item & STEP_LEVEL_INITIAL_MODE_MASK)
605 >> STEP_LEVEL_INITIAL_MODE_SHIFT);
606 int modMode = (int)((item & STEP_LEVEL_MODIFIED_MODE_MASK)
607 >> STEP_LEVEL_MODIFIED_MODE_SHIFT);
608 switch ((initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
609 case Display.STATE_OFF: out.append('f'); break;
610 case Display.STATE_ON: out.append('o'); break;
611 case Display.STATE_DOZE: out.append('d'); break;
612 case Display.STATE_DOZE_SUSPEND: out.append('z'); break;
613 }
614 if ((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
615 out.append('p');
616 }
617 switch ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
618 case Display.STATE_OFF: out.append('F'); break;
619 case Display.STATE_ON: out.append('O'); break;
620 case Display.STATE_DOZE: out.append('D'); break;
621 case Display.STATE_DOZE_SUSPEND: out.append('Z'); break;
622 }
623 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) != 0) {
624 out.append('P');
625 }
626 out.append('-');
627 appendHex(level, 4, out);
628 out.append('-');
629 appendHex(duration, STEP_LEVEL_LEVEL_SHIFT-4, out);
630 }
631
632 public void decodeEntryAt(int index, String value) {
633 final int N = value.length();
634 int i = 0;
635 char c;
636 long out = 0;
637 while (i < N && (c=value.charAt(i)) != '-') {
638 i++;
639 switch (c) {
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800640 case 'f': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800641 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800642 case 'o': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800643 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800644 case 'd': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_INITIAL_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800645 break;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800646 case 'z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
647 << STEP_LEVEL_INITIAL_MODE_SHIFT);
648 break;
649 case 'p': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
650 << STEP_LEVEL_INITIAL_MODE_SHIFT);
651 break;
652 case 'F': out |= (((long)Display.STATE_OFF-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
653 break;
654 case 'O': out |= (((long)Display.STATE_ON-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
655 break;
656 case 'D': out |= (((long)Display.STATE_DOZE-1)<<STEP_LEVEL_MODIFIED_MODE_SHIFT);
657 break;
658 case 'Z': out |= (((long)Display.STATE_DOZE_SUSPEND-1)
659 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
660 break;
661 case 'P': out |= (((long)STEP_LEVEL_MODE_POWER_SAVE)
662 << STEP_LEVEL_MODIFIED_MODE_SHIFT);
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800663 break;
664 }
665 }
666 i++;
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800667 long level = 0;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800668 while (i < N && (c=value.charAt(i)) != '-') {
669 i++;
670 level <<= 4;
671 if (c >= '0' && c <= '9') {
672 level += c - '0';
673 } else if (c >= 'a' && c <= 'f') {
674 level += c - 'a' + 10;
675 } else if (c >= 'A' && c <= 'F') {
676 level += c - 'A' + 10;
677 }
678 }
Dianne Hackborn8cfb58b2015-03-04 13:28:36 -0800679 i++;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -0800680 out |= (level << STEP_LEVEL_LEVEL_SHIFT) & STEP_LEVEL_LEVEL_MASK;
681 long duration = 0;
682 while (i < N && (c=value.charAt(i)) != '-') {
683 i++;
684 duration <<= 4;
685 if (c >= '0' && c <= '9') {
686 duration += c - '0';
687 } else if (c >= 'a' && c <= 'f') {
688 duration += c - 'a' + 10;
689 } else if (c >= 'A' && c <= 'F') {
690 duration += c - 'A' + 10;
691 }
692 }
693 mStepDurations[index] = out | (duration & STEP_LEVEL_TIME_MASK);
694 }
695
696 public void init() {
697 mLastStepTime = -1;
698 mNumStepDurations = 0;
699 }
700
701 public void clearTime() {
702 mLastStepTime = -1;
703 }
704
705 public long computeTimePerLevel() {
706 final long[] steps = mStepDurations;
707 final int numSteps = mNumStepDurations;
708
709 // For now we'll do a simple average across all steps.
710 if (numSteps <= 0) {
711 return -1;
712 }
713 long total = 0;
714 for (int i=0; i<numSteps; i++) {
715 total += steps[i] & STEP_LEVEL_TIME_MASK;
716 }
717 return total / numSteps;
718 /*
719 long[] buckets = new long[numSteps];
720 int numBuckets = 0;
721 int numToAverage = 4;
722 int i = 0;
723 while (i < numSteps) {
724 long totalTime = 0;
725 int num = 0;
726 for (int j=0; j<numToAverage && (i+j)<numSteps; j++) {
727 totalTime += steps[i+j] & STEP_LEVEL_TIME_MASK;
728 num++;
729 }
730 buckets[numBuckets] = totalTime / num;
731 numBuckets++;
732 numToAverage *= 2;
733 i += num;
734 }
735 if (numBuckets < 1) {
736 return -1;
737 }
738 long averageTime = buckets[numBuckets-1];
739 for (i=numBuckets-2; i>=0; i--) {
740 averageTime = (averageTime + buckets[i]) / 2;
741 }
742 return averageTime;
743 */
744 }
745
746 public long computeTimeEstimate(long modesOfInterest, long modeValues,
747 int[] outNumOfInterest) {
748 final long[] steps = mStepDurations;
749 final int count = mNumStepDurations;
750 if (count <= 0) {
751 return -1;
752 }
753 long total = 0;
754 int numOfInterest = 0;
755 for (int i=0; i<count; i++) {
756 long initMode = (steps[i] & STEP_LEVEL_INITIAL_MODE_MASK)
757 >> STEP_LEVEL_INITIAL_MODE_SHIFT;
758 long modMode = (steps[i] & STEP_LEVEL_MODIFIED_MODE_MASK)
759 >> STEP_LEVEL_MODIFIED_MODE_SHIFT;
760 // If the modes of interest didn't change during this step period...
761 if ((modMode&modesOfInterest) == 0) {
762 // And the mode values during this period match those we are measuring...
763 if ((initMode&modesOfInterest) == modeValues) {
764 // Then this can be used to estimate the total time!
765 numOfInterest++;
766 total += steps[i] & STEP_LEVEL_TIME_MASK;
767 }
768 }
769 }
770 if (numOfInterest <= 0) {
771 return -1;
772 }
773
774 if (outNumOfInterest != null) {
775 outNumOfInterest[0] = numOfInterest;
776 }
777
778 // The estimated time is the average time we spend in each level, multipled
779 // by 100 -- the total number of battery levels
780 return (total / numOfInterest) * 100;
781 }
782
783 public void addLevelSteps(int numStepLevels, long modeBits, long elapsedRealtime) {
784 int stepCount = mNumStepDurations;
785 final long lastStepTime = mLastStepTime;
786 if (lastStepTime >= 0 && numStepLevels > 0) {
787 final long[] steps = mStepDurations;
788 long duration = elapsedRealtime - lastStepTime;
789 for (int i=0; i<numStepLevels; i++) {
790 System.arraycopy(steps, 0, steps, 1, steps.length-1);
791 long thisDuration = duration / (numStepLevels-i);
792 duration -= thisDuration;
793 if (thisDuration > STEP_LEVEL_TIME_MASK) {
794 thisDuration = STEP_LEVEL_TIME_MASK;
795 }
796 steps[0] = thisDuration | modeBits;
797 }
798 stepCount += numStepLevels;
799 if (stepCount > steps.length) {
800 stepCount = steps.length;
801 }
802 }
803 mNumStepDurations = stepCount;
804 mLastStepTime = elapsedRealtime;
805 }
806
807 public void readFromParcel(Parcel in) {
808 final int N = in.readInt();
809 mNumStepDurations = N;
810 for (int i=0; i<N; i++) {
811 mStepDurations[i] = in.readLong();
812 }
813 }
814
815 public void writeToParcel(Parcel out) {
816 final int N = mNumStepDurations;
817 out.writeInt(N);
818 for (int i=0; i<N; i++) {
819 out.writeLong(mStepDurations[i]);
820 }
821 }
822 }
823
824 public static final class DailyItem {
825 public long mStartTime;
826 public long mEndTime;
827 public LevelStepTracker mDischargeSteps;
828 public LevelStepTracker mChargeSteps;
829 }
830
831 public abstract DailyItem getDailyItemLocked(int daysAgo);
832
833 public abstract long getCurrentDailyStartTime();
834
835 public abstract long getNextMinDailyDeadline();
836
837 public abstract long getNextMaxDailyDeadline();
838
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800839 public final static class HistoryTag {
840 public String string;
841 public int uid;
842
843 public int poolIdx;
844
845 public void setTo(HistoryTag o) {
846 string = o.string;
847 uid = o.uid;
848 poolIdx = o.poolIdx;
849 }
850
851 public void setTo(String _string, int _uid) {
852 string = _string;
853 uid = _uid;
854 poolIdx = -1;
855 }
856
857 public void writeToParcel(Parcel dest, int flags) {
858 dest.writeString(string);
859 dest.writeInt(uid);
860 }
861
862 public void readFromParcel(Parcel src) {
863 string = src.readString();
864 uid = src.readInt();
865 poolIdx = -1;
866 }
867
868 @Override
869 public boolean equals(Object o) {
870 if (this == o) return true;
871 if (o == null || getClass() != o.getClass()) return false;
872
873 HistoryTag that = (HistoryTag) o;
874
875 if (uid != that.uid) return false;
876 if (!string.equals(that.string)) return false;
877
878 return true;
879 }
880
881 @Override
882 public int hashCode() {
883 int result = string.hashCode();
884 result = 31 * result + uid;
885 return result;
886 }
887 }
888
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -0800889 /**
890 * Optional detailed information that can go into a history step. This is typically
891 * generated each time the battery level changes.
892 */
893 public final static class HistoryStepDetails {
894 // Time (in 1/100 second) spent in user space and the kernel since the last step.
895 public int userTime;
896 public int systemTime;
897
898 // Top three apps using CPU in the last step, with times in 1/100 second.
899 public int appCpuUid1;
900 public int appCpuUTime1;
901 public int appCpuSTime1;
902 public int appCpuUid2;
903 public int appCpuUTime2;
904 public int appCpuSTime2;
905 public int appCpuUid3;
906 public int appCpuUTime3;
907 public int appCpuSTime3;
908
909 // Information from /proc/stat
910 public int statUserTime;
911 public int statSystemTime;
912 public int statIOWaitTime;
913 public int statIrqTime;
914 public int statSoftIrqTime;
915 public int statIdlTime;
916
917 public HistoryStepDetails() {
918 clear();
919 }
920
921 public void clear() {
922 userTime = systemTime = 0;
923 appCpuUid1 = appCpuUid2 = appCpuUid3 = -1;
924 appCpuUTime1 = appCpuSTime1 = appCpuUTime2 = appCpuSTime2
925 = appCpuUTime3 = appCpuSTime3 = 0;
926 }
927
928 public void writeToParcel(Parcel out) {
929 out.writeInt(userTime);
930 out.writeInt(systemTime);
931 out.writeInt(appCpuUid1);
932 out.writeInt(appCpuUTime1);
933 out.writeInt(appCpuSTime1);
934 out.writeInt(appCpuUid2);
935 out.writeInt(appCpuUTime2);
936 out.writeInt(appCpuSTime2);
937 out.writeInt(appCpuUid3);
938 out.writeInt(appCpuUTime3);
939 out.writeInt(appCpuSTime3);
940 out.writeInt(statUserTime);
941 out.writeInt(statSystemTime);
942 out.writeInt(statIOWaitTime);
943 out.writeInt(statIrqTime);
944 out.writeInt(statSoftIrqTime);
945 out.writeInt(statIdlTime);
946 }
947
948 public void readFromParcel(Parcel in) {
949 userTime = in.readInt();
950 systemTime = in.readInt();
951 appCpuUid1 = in.readInt();
952 appCpuUTime1 = in.readInt();
953 appCpuSTime1 = in.readInt();
954 appCpuUid2 = in.readInt();
955 appCpuUTime2 = in.readInt();
956 appCpuSTime2 = in.readInt();
957 appCpuUid3 = in.readInt();
958 appCpuUTime3 = in.readInt();
959 appCpuSTime3 = in.readInt();
960 statUserTime = in.readInt();
961 statSystemTime = in.readInt();
962 statIOWaitTime = in.readInt();
963 statIrqTime = in.readInt();
964 statSoftIrqTime = in.readInt();
965 statIdlTime = in.readInt();
966 }
967 }
968
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700969 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700970 public HistoryItem next;
Dianne Hackborn9a755432014-05-15 17:05:22 -0700971
972 // The time of this event in milliseconds, as per SystemClock.elapsedRealtime().
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700973 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800974
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800975 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800976 public static final byte CMD_NULL = -1;
977 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800978 public static final byte CMD_CURRENT_TIME = 5;
979 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -0700980 public static final byte CMD_RESET = 7;
Dianne Hackborn29cd7f12015-01-08 10:37:05 -0800981 public static final byte CMD_SHUTDOWN = 8;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800982
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700983 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700984
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800985 /**
986 * Return whether the command code is a delta data update.
987 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800988 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800989 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800990 }
991
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700992 public byte batteryLevel;
993 public byte batteryStatus;
994 public byte batteryHealth;
995 public byte batteryPlugType;
996
Sungmin Choic7e9e8b2013-01-16 12:57:36 +0900997 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700998 public char batteryVoltage;
999
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001000 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001001 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001002 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001003 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn3251b902014-06-20 14:40:53 -07001004 public static final int STATE_PHONE_SIGNAL_STRENGTH_SHIFT = 3;
1005 public static final int STATE_PHONE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_PHONE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001006 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001007 public static final int STATE_PHONE_STATE_SHIFT = 6;
1008 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001009 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001010 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001011 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001012
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001013 // These states always appear directly in the first int token
1014 // of a delta change; they should be ones that change relatively
1015 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001016 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
1017 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001018 public static final int STATE_GPS_ON_FLAG = 1<<29;
1019 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001020 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001021 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001022 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001023 // These are on the lower bits used for the command; if they change
1024 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001025 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001026 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001027 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001028 public static final int STATE_SCREEN_ON_FLAG = 1<<20;
1029 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19;
1030 public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001031 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -07001032
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001033 public static final int MOST_INTERESTING_STATES =
1034 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
Dianne Hackborn3251b902014-06-20 14:40:53 -07001035 | STATE_PHONE_IN_CALL_FLAG | STATE_BLUETOOTH_ON_FLAG;
Dianne Hackbornf47d8f22010-10-08 10:46:55 -07001036
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001037 public int states;
1038
Dianne Hackborn3251b902014-06-20 14:40:53 -07001039 // Constants from WIFI_SUPPL_STATE_*
1040 public static final int STATE2_WIFI_SUPPL_STATE_SHIFT = 0;
1041 public static final int STATE2_WIFI_SUPPL_STATE_MASK = 0xf;
1042 // Values for NUM_WIFI_SIGNAL_STRENGTH_BINS
1043 public static final int STATE2_WIFI_SIGNAL_STRENGTH_SHIFT = 4;
1044 public static final int STATE2_WIFI_SIGNAL_STRENGTH_MASK =
1045 0x7 << STATE2_WIFI_SIGNAL_STRENGTH_SHIFT;
1046
1047 public static final int STATE2_LOW_POWER_FLAG = 1<<31;
1048 public static final int STATE2_VIDEO_ON_FLAG = 1<<30;
1049 public static final int STATE2_WIFI_RUNNING_FLAG = 1<<29;
1050 public static final int STATE2_WIFI_ON_FLAG = 1<<28;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001051 public static final int STATE2_FLASHLIGHT_FLAG = 1<<27;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001052
1053 public static final int MOST_INTERESTING_STATES2 =
1054 STATE2_LOW_POWER_FLAG | STATE2_WIFI_ON_FLAG;
1055
Dianne Hackborn40c87252014-03-19 16:55:40 -07001056 public int states2;
1057
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001058 // The wake lock that was acquired at this point.
1059 public HistoryTag wakelockTag;
1060
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001061 // Kernel wakeup reason at this point.
1062 public HistoryTag wakeReasonTag;
1063
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08001064 // Non-null when there is more detailed information at this step.
1065 public HistoryStepDetails stepDetails;
1066
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001067 public static final int EVENT_FLAG_START = 0x8000;
1068 public static final int EVENT_FLAG_FINISH = 0x4000;
1069
1070 // No event in this item.
1071 public static final int EVENT_NONE = 0x0000;
1072 // Event is about a process that is running.
1073 public static final int EVENT_PROC = 0x0001;
1074 // Event is about an application package that is in the foreground.
1075 public static final int EVENT_FOREGROUND = 0x0002;
1076 // Event is about an application package that is at the top of the screen.
1077 public static final int EVENT_TOP = 0x0003;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001078 // Event is about active sync operations.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001079 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001080 // Events for all additional wake locks aquired/release within a wake block.
1081 // These are not generated by default.
1082 public static final int EVENT_WAKE_LOCK = 0x0005;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001083 // Event is about an application executing a scheduled job.
1084 public static final int EVENT_JOB = 0x0006;
1085 // Events for users running.
1086 public static final int EVENT_USER_RUNNING = 0x0007;
1087 // Events for foreground user.
1088 public static final int EVENT_USER_FOREGROUND = 0x0008;
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001089 // Events for connectivity changed.
1090 public static final int EVENT_CONNECTIVITY_CHANGED = 0x0009;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001091 // Number of event types.
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001092 public static final int EVENT_COUNT = 0x000a;
Dianne Hackborn37de0982014-05-09 09:32:18 -07001093 // Mask to extract out only the type part of the event.
1094 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001095
1096 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
1097 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
1098 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
1099 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
1100 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
1101 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001102 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
1103 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001104 public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
1105 public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07001106 public static final int EVENT_JOB_START = EVENT_JOB | EVENT_FLAG_START;
1107 public static final int EVENT_JOB_FINISH = EVENT_JOB | EVENT_FLAG_FINISH;
1108 public static final int EVENT_USER_RUNNING_START = EVENT_USER_RUNNING | EVENT_FLAG_START;
1109 public static final int EVENT_USER_RUNNING_FINISH = EVENT_USER_RUNNING | EVENT_FLAG_FINISH;
1110 public static final int EVENT_USER_FOREGROUND_START =
1111 EVENT_USER_FOREGROUND | EVENT_FLAG_START;
1112 public static final int EVENT_USER_FOREGROUND_FINISH =
1113 EVENT_USER_FOREGROUND | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001114
1115 // For CMD_EVENT.
1116 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001117 public HistoryTag eventTag;
1118
Dianne Hackborn9a755432014-05-15 17:05:22 -07001119 // Only set for CMD_CURRENT_TIME or CMD_RESET, as per System.currentTimeMillis().
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001120 public long currentTime;
1121
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001122 // Meta-data when reading.
1123 public int numReadInts;
1124
1125 // Pre-allocated objects.
1126 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001127 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001128 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001129
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001130 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001131 }
1132
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001133 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001134 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001135 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001136 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001137 }
1138
1139 public int describeContents() {
1140 return 0;
1141 }
1142
1143 public void writeToParcel(Parcel dest, int flags) {
1144 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001145 int bat = (((int)cmd)&0xff)
1146 | ((((int)batteryLevel)<<8)&0xff00)
1147 | ((((int)batteryStatus)<<16)&0xf0000)
1148 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001149 | ((((int)batteryPlugType)<<24)&0xf000000)
1150 | (wakelockTag != null ? 0x10000000 : 0)
1151 | (wakeReasonTag != null ? 0x20000000 : 0)
1152 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001153 dest.writeInt(bat);
1154 bat = (((int)batteryTemperature)&0xffff)
1155 | ((((int)batteryVoltage)<<16)&0xffff0000);
1156 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001157 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001158 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001159 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001160 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001161 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001162 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001163 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001164 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001165 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001166 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001167 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001168 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001169 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001170 dest.writeLong(currentTime);
1171 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001172 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001173
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001174 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001175 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001176 int bat = src.readInt();
1177 cmd = (byte)(bat&0xff);
1178 batteryLevel = (byte)((bat>>8)&0xff);
1179 batteryStatus = (byte)((bat>>16)&0xf);
1180 batteryHealth = (byte)((bat>>20)&0xf);
1181 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001182 int bat2 = src.readInt();
1183 batteryTemperature = (short)(bat2&0xffff);
1184 batteryVoltage = (char)((bat2>>16)&0xffff);
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001185 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001186 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001187 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001188 wakelockTag = localWakelockTag;
1189 wakelockTag.readFromParcel(src);
1190 } else {
1191 wakelockTag = null;
1192 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001193 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001194 wakeReasonTag = localWakeReasonTag;
1195 wakeReasonTag.readFromParcel(src);
1196 } else {
1197 wakeReasonTag = null;
1198 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001199 if ((bat&0x40000000) != 0) {
1200 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001201 eventTag = localEventTag;
1202 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001203 } else {
1204 eventCode = EVENT_NONE;
1205 eventTag = null;
1206 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001207 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001208 currentTime = src.readLong();
1209 } else {
1210 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001211 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001212 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001213 }
1214
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001215 public void clear() {
1216 time = 0;
1217 cmd = CMD_NULL;
1218 batteryLevel = 0;
1219 batteryStatus = 0;
1220 batteryHealth = 0;
1221 batteryPlugType = 0;
1222 batteryTemperature = 0;
1223 batteryVoltage = 0;
1224 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001225 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001226 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001227 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001228 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001229 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -07001230 }
1231
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001232 public void setTo(HistoryItem o) {
1233 time = o.time;
1234 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001235 setToCommon(o);
1236 }
1237
1238 public void setTo(long time, byte cmd, HistoryItem o) {
1239 this.time = time;
1240 this.cmd = cmd;
1241 setToCommon(o);
1242 }
1243
1244 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001245 batteryLevel = o.batteryLevel;
1246 batteryStatus = o.batteryStatus;
1247 batteryHealth = o.batteryHealth;
1248 batteryPlugType = o.batteryPlugType;
1249 batteryTemperature = o.batteryTemperature;
1250 batteryVoltage = o.batteryVoltage;
1251 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001252 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001253 if (o.wakelockTag != null) {
1254 wakelockTag = localWakelockTag;
1255 wakelockTag.setTo(o.wakelockTag);
1256 } else {
1257 wakelockTag = null;
1258 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001259 if (o.wakeReasonTag != null) {
1260 wakeReasonTag = localWakeReasonTag;
1261 wakeReasonTag.setTo(o.wakeReasonTag);
1262 } else {
1263 wakeReasonTag = null;
1264 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001265 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001266 if (o.eventTag != null) {
1267 eventTag = localEventTag;
1268 eventTag.setTo(o.eventTag);
1269 } else {
1270 eventTag = null;
1271 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001272 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001273 }
1274
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001275 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001276 return batteryLevel == o.batteryLevel
1277 && batteryStatus == o.batteryStatus
1278 && batteryHealth == o.batteryHealth
1279 && batteryPlugType == o.batteryPlugType
1280 && batteryTemperature == o.batteryTemperature
1281 && batteryVoltage == o.batteryVoltage
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001282 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001283 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -08001284 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001285 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001286
1287 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001288 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001289 return false;
1290 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001291 if (wakelockTag != o.wakelockTag) {
1292 if (wakelockTag == null || o.wakelockTag == null) {
1293 return false;
1294 }
1295 if (!wakelockTag.equals(o.wakelockTag)) {
1296 return false;
1297 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001298 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08001299 if (wakeReasonTag != o.wakeReasonTag) {
1300 if (wakeReasonTag == null || o.wakeReasonTag == null) {
1301 return false;
1302 }
1303 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
1304 return false;
1305 }
1306 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001307 if (eventTag != o.eventTag) {
1308 if (eventTag == null || o.eventTag == null) {
1309 return false;
1310 }
1311 if (!eventTag.equals(o.eventTag)) {
1312 return false;
1313 }
1314 }
1315 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001316 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001317 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001318
1319 public final static class HistoryEventTracker {
1320 private final HashMap<String, SparseIntArray>[] mActiveEvents
1321 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
1322
1323 public boolean updateState(int code, String name, int uid, int poolIdx) {
1324 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
1325 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1326 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1327 if (active == null) {
1328 active = new HashMap<String, SparseIntArray>();
1329 mActiveEvents[idx] = active;
1330 }
1331 SparseIntArray uids = active.get(name);
1332 if (uids == null) {
1333 uids = new SparseIntArray();
1334 active.put(name, uids);
1335 }
1336 if (uids.indexOfKey(uid) >= 0) {
1337 // Already set, nothing to do!
1338 return false;
1339 }
1340 uids.put(uid, poolIdx);
1341 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
1342 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1343 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
1344 if (active == null) {
1345 // not currently active, nothing to do.
1346 return false;
1347 }
1348 SparseIntArray uids = active.get(name);
1349 if (uids == null) {
1350 // not currently active, nothing to do.
1351 return false;
1352 }
1353 idx = uids.indexOfKey(uid);
1354 if (idx < 0) {
1355 // not currently active, nothing to do.
1356 return false;
1357 }
1358 uids.removeAt(idx);
1359 if (uids.size() <= 0) {
1360 active.remove(name);
1361 }
1362 }
1363 return true;
1364 }
1365
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001366 public void removeEvents(int code) {
1367 int idx = code&HistoryItem.EVENT_TYPE_MASK;
1368 mActiveEvents[idx] = null;
1369 }
1370
Dianne Hackborn37de0982014-05-09 09:32:18 -07001371 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
1372 return mActiveEvents[code];
1373 }
1374 }
1375
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001376 public static final class BitDescription {
1377 public final int mask;
1378 public final int shift;
1379 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001380 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001381 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001382 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001383
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001384 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001385 this.mask = mask;
1386 this.shift = -1;
1387 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001388 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001389 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001390 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001391 }
1392
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001393 public BitDescription(int mask, int shift, String name, String shortName,
1394 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001395 this.mask = mask;
1396 this.shift = shift;
1397 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001398 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001399 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001400 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001401 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001402 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07001403
Dianne Hackbornfc064132014-06-02 12:42:12 -07001404 /**
1405 * Don't allow any more batching in to the current history event. This
1406 * is called when printing partial histories, so to ensure that the next
1407 * history event will go in to a new batch after what was printed in the
1408 * last partial history.
1409 */
1410 public abstract void commitCurrentHistoryBatchLocked();
1411
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001412 public abstract int getHistoryTotalSize();
1413
1414 public abstract int getHistoryUsedSize();
1415
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001416 public abstract boolean startIteratingHistoryLocked();
1417
Dianne Hackborn099bc622014-01-22 13:39:16 -08001418 public abstract int getHistoryStringPoolSize();
1419
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08001420 public abstract int getHistoryStringPoolBytes();
1421
1422 public abstract String getHistoryTagPoolString(int index);
1423
1424 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -08001425
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001426 public abstract boolean getNextHistoryLocked(HistoryItem out);
1427
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07001428 public abstract void finishIteratingHistoryLocked();
1429
1430 public abstract boolean startIteratingOldHistoryLocked();
1431
1432 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
1433
1434 public abstract void finishIteratingOldHistoryLocked();
1435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001437 * Return the base time offset for the battery history.
1438 */
1439 public abstract long getHistoryBaseTime();
1440
1441 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 * Returns the number of times the device has been started.
1443 */
1444 public abstract int getStartCount();
1445
1446 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001447 * 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 -08001448 * running on battery.
1449 *
1450 * {@hide}
1451 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001452 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001454 /**
1455 * Returns the number of times the screen was turned on.
1456 *
1457 * {@hide}
1458 */
1459 public abstract int getScreenOnCount(int which);
1460
Jeff Browne95c3cd2014-05-02 16:59:26 -07001461 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
1462
Dianne Hackborn617f8772009-03-31 15:04:46 -07001463 public static final int SCREEN_BRIGHTNESS_DARK = 0;
1464 public static final int SCREEN_BRIGHTNESS_DIM = 1;
1465 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
1466 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
1467 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
1468
1469 static final String[] SCREEN_BRIGHTNESS_NAMES = {
1470 "dark", "dim", "medium", "light", "bright"
1471 };
1472
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001473 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
1474 "0", "1", "2", "3", "4"
1475 };
1476
Dianne Hackborn617f8772009-03-31 15:04:46 -07001477 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
Dianne Hackborn3251b902014-06-20 14:40:53 -07001478
Dianne Hackborn617f8772009-03-31 15:04:46 -07001479 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001480 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -07001481 * the given brightness
1482 *
1483 * {@hide}
1484 */
1485 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001486 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001487
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 /**
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001489 * Returns the time in microseconds that low power mode has been enabled while the device was
1490 * running on battery.
1491 *
1492 * {@hide}
1493 */
1494 public abstract long getLowPowerModeEnabledTime(long elapsedRealtimeUs, int which);
1495
1496 /**
1497 * Returns the number of times that low power mode was enabled.
1498 *
1499 * {@hide}
1500 */
1501 public abstract int getLowPowerModeEnabledCount(int which);
1502
1503 /**
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001504 * Returns the number of times that connectivity state changed.
1505 *
1506 * {@hide}
1507 */
1508 public abstract int getNumConnectivityChange(int which);
1509
1510 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001511 * 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 -08001512 * running on battery.
1513 *
1514 * {@hide}
1515 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001516 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001517
1518 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001519 * Returns the number of times a phone call was activated.
1520 *
1521 * {@hide}
1522 */
1523 public abstract int getPhoneOnCount(int which);
1524
1525 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001526 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001527 * the given signal strength.
1528 *
1529 * {@hide}
1530 */
1531 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001532 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001533
Dianne Hackborn617f8772009-03-31 15:04:46 -07001534 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001535 * Returns the time in microseconds that the phone has been trying to
1536 * acquire a signal.
1537 *
1538 * {@hide}
1539 */
1540 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001541 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001542
1543 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001544 * Returns the number of times the phone has entered the given signal strength.
1545 *
1546 * {@hide}
1547 */
1548 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1549
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001550 /**
1551 * Returns the time in microseconds that the mobile network has been active
1552 * (in a high power state).
1553 *
1554 * {@hide}
1555 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001556 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001557
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001558 /**
1559 * Returns the number of times that the mobile network has transitioned to the
1560 * active state.
1561 *
1562 * {@hide}
1563 */
1564 public abstract int getMobileRadioActiveCount(int which);
1565
1566 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001567 * Returns the time in microseconds that is the difference between the mobile radio
1568 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1569 * from the radio.
1570 *
1571 * {@hide}
1572 */
1573 public abstract long getMobileRadioActiveAdjustedTime(int which);
1574
1575 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001576 * Returns the time in microseconds that the mobile network has been active
1577 * (in a high power state) but not being able to blame on an app.
1578 *
1579 * {@hide}
1580 */
1581 public abstract long getMobileRadioActiveUnknownTime(int which);
1582
1583 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001584 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001585 *
1586 * {@hide}
1587 */
1588 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001589
Dianne Hackborn627bba72009-03-24 22:32:56 -07001590 public static final int DATA_CONNECTION_NONE = 0;
1591 public static final int DATA_CONNECTION_GPRS = 1;
1592 public static final int DATA_CONNECTION_EDGE = 2;
1593 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001594 public static final int DATA_CONNECTION_CDMA = 4;
1595 public static final int DATA_CONNECTION_EVDO_0 = 5;
1596 public static final int DATA_CONNECTION_EVDO_A = 6;
1597 public static final int DATA_CONNECTION_1xRTT = 7;
1598 public static final int DATA_CONNECTION_HSDPA = 8;
1599 public static final int DATA_CONNECTION_HSUPA = 9;
1600 public static final int DATA_CONNECTION_HSPA = 10;
1601 public static final int DATA_CONNECTION_IDEN = 11;
1602 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001603 public static final int DATA_CONNECTION_LTE = 13;
1604 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001605 public static final int DATA_CONNECTION_HSPAP = 15;
1606 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001607
Dianne Hackborn627bba72009-03-24 22:32:56 -07001608 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001609 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001610 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001611 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001612 };
1613
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001614 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001615
1616 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001617 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001618 * the given data connection.
1619 *
1620 * {@hide}
1621 */
1622 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001623 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001626 * Returns the number of times the phone has entered the given data
1627 * connection type.
1628 *
1629 * {@hide}
1630 */
1631 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001632
Dianne Hackborn3251b902014-06-20 14:40:53 -07001633 public static final int WIFI_SUPPL_STATE_INVALID = 0;
1634 public static final int WIFI_SUPPL_STATE_DISCONNECTED = 1;
1635 public static final int WIFI_SUPPL_STATE_INTERFACE_DISABLED = 2;
1636 public static final int WIFI_SUPPL_STATE_INACTIVE = 3;
1637 public static final int WIFI_SUPPL_STATE_SCANNING = 4;
1638 public static final int WIFI_SUPPL_STATE_AUTHENTICATING = 5;
1639 public static final int WIFI_SUPPL_STATE_ASSOCIATING = 6;
1640 public static final int WIFI_SUPPL_STATE_ASSOCIATED = 7;
1641 public static final int WIFI_SUPPL_STATE_FOUR_WAY_HANDSHAKE = 8;
1642 public static final int WIFI_SUPPL_STATE_GROUP_HANDSHAKE = 9;
1643 public static final int WIFI_SUPPL_STATE_COMPLETED = 10;
1644 public static final int WIFI_SUPPL_STATE_DORMANT = 11;
1645 public static final int WIFI_SUPPL_STATE_UNINITIALIZED = 12;
1646
1647 public static final int NUM_WIFI_SUPPL_STATES = WIFI_SUPPL_STATE_UNINITIALIZED+1;
1648
1649 static final String[] WIFI_SUPPL_STATE_NAMES = {
1650 "invalid", "disconn", "disabled", "inactive", "scanning",
1651 "authenticating", "associating", "associated", "4-way-handshake",
1652 "group-handshake", "completed", "dormant", "uninit"
1653 };
1654
1655 static final String[] WIFI_SUPPL_STATE_SHORT_NAMES = {
1656 "inv", "dsc", "dis", "inact", "scan",
1657 "auth", "ascing", "asced", "4-way",
1658 "group", "compl", "dorm", "uninit"
1659 };
1660
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001661 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1662 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001663 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001664 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1665 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001666 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001667 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1668 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1669 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001670 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001671 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001672 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001673 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1674 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
1675 new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001676 new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
1677 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1678 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1679 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1680 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1681 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1682 new String[] {"in", "out", "emergency", "off"},
1683 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001684 new BitDescription(HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_MASK,
1685 HistoryItem.STATE_PHONE_SIGNAL_STRENGTH_SHIFT, "phone_signal_strength", "Pss",
1686 SignalStrength.SIGNAL_STRENGTH_NAMES,
1687 new String[] { "0", "1", "2", "3", "4" }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001688 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1689 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1690 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001691 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001692
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001693 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1694 = new BitDescription[] {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07001695 new BitDescription(HistoryItem.STATE2_LOW_POWER_FLAG, "low_power", "lp"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001696 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
1697 new BitDescription(HistoryItem.STATE2_WIFI_RUNNING_FLAG, "wifi_running", "Wr"),
1698 new BitDescription(HistoryItem.STATE2_WIFI_ON_FLAG, "wifi", "W"),
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001699 new BitDescription(HistoryItem.STATE2_FLASHLIGHT_FLAG, "flashlight", "fl"),
Dianne Hackborn3251b902014-06-20 14:40:53 -07001700 new BitDescription(HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK,
1701 HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_SHIFT, "wifi_signal_strength", "Wss",
1702 new String[] { "0", "1", "2", "3", "4" },
1703 new String[] { "0", "1", "2", "3", "4" }),
1704 new BitDescription(HistoryItem.STATE2_WIFI_SUPPL_STATE_MASK,
1705 HistoryItem.STATE2_WIFI_SUPPL_STATE_SHIFT, "wifi_suppl", "Wsp",
1706 WIFI_SUPPL_STATE_NAMES, WIFI_SUPPL_STATE_SHORT_NAMES),
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001707 };
1708
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001709 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001710 "null", "proc", "fg", "top", "sync", "wake_lock_in", "job", "user", "userfg", "conn"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001711 };
1712
1713 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborn1e01d162014-12-04 17:46:42 -08001714 "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001715 };
1716
Dianne Hackborn617f8772009-03-31 15:04:46 -07001717 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001718 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001719 * running on battery.
1720 *
1721 * {@hide}
1722 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001723 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001724
1725 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001726 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001727 * been in the running state while the device was running on battery.
1728 *
1729 * {@hide}
1730 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001731 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001732
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001733 public static final int WIFI_STATE_OFF = 0;
1734 public static final int WIFI_STATE_OFF_SCANNING = 1;
1735 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
1736 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
1737 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
1738 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
1739 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
1740 public static final int WIFI_STATE_SOFT_AP = 7;
1741
1742 static final String[] WIFI_STATE_NAMES = {
1743 "off", "scanning", "no_net", "disconn",
1744 "sta", "p2p", "sta_p2p", "soft_ap"
1745 };
1746
1747 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
1748
1749 /**
1750 * Returns the time in microseconds that WiFi has been running in the given state.
1751 *
1752 * {@hide}
1753 */
1754 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001755 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001756
1757 /**
1758 * Returns the number of times that WiFi has entered the given state.
1759 *
1760 * {@hide}
1761 */
1762 public abstract int getWifiStateCount(int wifiState, int which);
1763
The Android Open Source Project10592532009-03-18 17:39:46 -07001764 /**
Dianne Hackborn3251b902014-06-20 14:40:53 -07001765 * Returns the time in microseconds that the wifi supplicant has been
1766 * in a given state.
1767 *
1768 * {@hide}
1769 */
1770 public abstract long getWifiSupplStateTime(int state, long elapsedRealtimeUs, int which);
1771
1772 /**
1773 * Returns the number of times that the wifi supplicant has transitioned
1774 * to a given state.
1775 *
1776 * {@hide}
1777 */
1778 public abstract int getWifiSupplStateCount(int state, int which);
1779
1780 public static final int NUM_WIFI_SIGNAL_STRENGTH_BINS = 5;
1781
1782 /**
1783 * Returns the time in microseconds that WIFI has been running with
1784 * the given signal strength.
1785 *
1786 * {@hide}
1787 */
1788 public abstract long getWifiSignalStrengthTime(int strengthBin,
1789 long elapsedRealtimeUs, int which);
1790
1791 /**
1792 * Returns the number of times WIFI has entered the given signal strength.
1793 *
1794 * {@hide}
1795 */
1796 public abstract int getWifiSignalStrengthCount(int strengthBin, int which);
1797
1798 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001799 * Returns the time in microseconds that bluetooth has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001800 * running on battery.
1801 *
1802 * {@hide}
1803 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001804 public abstract long getBluetoothOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001805
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001806 public abstract int getBluetoothPingCount();
1807
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001808 public static final int BLUETOOTH_STATE_INACTIVE = 0;
1809 public static final int BLUETOOTH_STATE_LOW = 1;
1810 public static final int BLUETOOTH_STATE_MEDIUM = 2;
1811 public static final int BLUETOOTH_STATE_HIGH = 3;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001812
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001813 static final String[] BLUETOOTH_STATE_NAMES = {
1814 "inactive", "low", "med", "high"
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001815 };
1816
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001817 public static final int NUM_BLUETOOTH_STATES = BLUETOOTH_STATE_HIGH +1;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001818
1819 /**
1820 * Returns the time in microseconds that Bluetooth has been running in the
1821 * given active state.
1822 *
1823 * {@hide}
1824 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001825 public abstract long getBluetoothStateTime(int bluetoothState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001826 long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001827
1828 /**
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001829 * Returns the number of times that Bluetooth has entered the given active state.
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001830 *
1831 * {@hide}
1832 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001833 public abstract int getBluetoothStateCount(int bluetoothState, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001834
Dianne Hackbornabc7c492014-06-30 16:57:46 -07001835 /**
1836 * Returns the time in microseconds that the flashlight has been on while the device was
1837 * running on battery.
1838 *
1839 * {@hide}
1840 */
1841 public abstract long getFlashlightOnTime(long elapsedRealtimeUs, int which);
1842
1843 /**
1844 * Returns the number of times that the flashlight has been turned on while the device was
1845 * running on battery.
1846 *
1847 * {@hide}
1848 */
1849 public abstract long getFlashlightOnCount(int which);
1850
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001851 public static final int NETWORK_MOBILE_RX_DATA = 0;
1852 public static final int NETWORK_MOBILE_TX_DATA = 1;
1853 public static final int NETWORK_WIFI_RX_DATA = 2;
1854 public static final int NETWORK_WIFI_TX_DATA = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001855
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001856 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001857
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001858 public abstract long getNetworkActivityBytes(int type, int which);
1859 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001860
Adam Lesinski33dac552015-03-09 15:24:48 -07001861 public static final int CONTROLLER_IDLE_TIME = 0;
1862 public static final int CONTROLLER_RX_TIME = 1;
1863 public static final int CONTROLLER_TX_TIME = 2;
1864 public static final int CONTROLLER_ENERGY = 3;
1865 public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_ENERGY + 1;
1866
1867 public abstract long getBluetoothControllerActivity(int type, int which);
1868 public abstract long getWifiControllerActivity(int type, int which);
1869
The Android Open Source Project10592532009-03-18 17:39:46 -07001870 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08001871 * Return the wall clock time when battery stats data collection started.
1872 */
1873 public abstract long getStartClockTime();
1874
1875 /**
Dianne Hackborncd0e3352014-08-07 17:08:09 -07001876 * Return platform version tag that we were running in when the battery stats started.
1877 */
1878 public abstract String getStartPlatformVersion();
1879
1880 /**
1881 * Return platform version tag that we were running in when the battery stats ended.
1882 */
1883 public abstract String getEndPlatformVersion();
1884
1885 /**
1886 * Return the internal version code of the parcelled format.
1887 */
1888 public abstract int getParcelVersion();
1889
1890 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001891 * Return whether we are currently running on battery.
1892 */
1893 public abstract boolean getIsOnBattery();
1894
1895 /**
1896 * Returns a SparseArray containing the statistics for each uid.
1897 */
1898 public abstract SparseArray<? extends Uid> getUidStats();
1899
1900 /**
1901 * Returns the current battery uptime in microseconds.
1902 *
1903 * @param curTime the amount of elapsed realtime in microseconds.
1904 */
1905 public abstract long getBatteryUptime(long curTime);
1906
1907 /**
1908 * Returns the current battery realtime in microseconds.
1909 *
1910 * @param curTime the amount of elapsed realtime in microseconds.
1911 */
1912 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001913
1914 /**
Evan Millar633a1742009-04-02 16:36:33 -07001915 * Returns the battery percentage level at the last time the device was unplugged from power, or
1916 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07001917 */
Evan Millar633a1742009-04-02 16:36:33 -07001918 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07001919
1920 /**
Evan Millar633a1742009-04-02 16:36:33 -07001921 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
1922 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07001923 */
Evan Millar633a1742009-04-02 16:36:33 -07001924 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001925
1926 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001927 * Get the amount the battery has discharged since the stats were
1928 * last reset after charging, as a lower-end approximation.
1929 */
1930 public abstract int getLowDischargeAmountSinceCharge();
1931
1932 /**
1933 * Get the amount the battery has discharged since the stats were
1934 * last reset after charging, as an upper-end approximation.
1935 */
1936 public abstract int getHighDischargeAmountSinceCharge();
1937
1938 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07001939 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
1940 */
1941 public abstract int getDischargeAmount(int which);
1942
1943 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08001944 * Get the amount the battery has discharged while the screen was on,
1945 * since the last time power was unplugged.
1946 */
1947 public abstract int getDischargeAmountScreenOn();
1948
1949 /**
1950 * Get the amount the battery has discharged while the screen was on,
1951 * since the last time the device was charged.
1952 */
1953 public abstract int getDischargeAmountScreenOnSinceCharge();
1954
1955 /**
1956 * Get the amount the battery has discharged while the screen was off,
1957 * since the last time power was unplugged.
1958 */
1959 public abstract int getDischargeAmountScreenOff();
1960
1961 /**
1962 * Get the amount the battery has discharged while the screen was off,
1963 * since the last time the device was charged.
1964 */
1965 public abstract int getDischargeAmountScreenOffSinceCharge();
1966
1967 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 * Returns the total, last, or current battery uptime in microseconds.
1969 *
1970 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001971 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001972 */
1973 public abstract long computeBatteryUptime(long curTime, int which);
1974
1975 /**
1976 * Returns the total, last, or current battery realtime in microseconds.
1977 *
1978 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001979 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 */
1981 public abstract long computeBatteryRealtime(long curTime, int which);
1982
1983 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001984 * Returns the total, last, or current battery screen off uptime in microseconds.
1985 *
1986 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001987 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001988 */
1989 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
1990
1991 /**
1992 * Returns the total, last, or current battery screen off realtime in microseconds.
1993 *
1994 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001995 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001996 */
1997 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
1998
1999 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 * Returns the total, last, or current uptime in microseconds.
2001 *
2002 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002003 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 */
2005 public abstract long computeUptime(long curTime, int which);
2006
2007 /**
2008 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002009 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002010 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002011 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 */
2013 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002014
2015 /**
2016 * Compute an approximation for how much run time (in microseconds) is remaining on
2017 * the battery. Returns -1 if no time can be computed: either there is not
2018 * enough current data to make a decision, or the battery is currently
2019 * charging.
2020 *
2021 * @param curTime The current elepsed realtime in microseconds.
2022 */
2023 public abstract long computeBatteryTimeRemaining(long curTime);
2024
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002025 // The part of a step duration that is the actual time.
2026 public static final long STEP_LEVEL_TIME_MASK = 0x000000ffffffffffL;
2027
2028 // Bits in a step duration that are the new battery level we are at.
2029 public static final long STEP_LEVEL_LEVEL_MASK = 0x0000ff0000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002030 public static final int STEP_LEVEL_LEVEL_SHIFT = 40;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002031
2032 // Bits in a step duration that are the initial mode we were in at that step.
2033 public static final long STEP_LEVEL_INITIAL_MODE_MASK = 0x00ff000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002034 public static final int STEP_LEVEL_INITIAL_MODE_SHIFT = 48;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002035
2036 // Bits in a step duration that indicate which modes changed during that step.
2037 public static final long STEP_LEVEL_MODIFIED_MODE_MASK = 0xff00000000000000L;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002038 public static final int STEP_LEVEL_MODIFIED_MODE_SHIFT = 56;
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07002039
2040 // Step duration mode: the screen is on, off, dozed, etc; value is Display.STATE_* - 1.
2041 public static final int STEP_LEVEL_MODE_SCREEN_STATE = 0x03;
2042
2043 // Step duration mode: power save is on.
2044 public static final int STEP_LEVEL_MODE_POWER_SAVE = 0x04;
2045
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002046 public static final int[] STEP_LEVEL_MODES_OF_INTEREST = new int[] {
2047 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2048 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2049 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2050 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2051 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2052 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2053 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2054 STEP_LEVEL_MODE_SCREEN_STATE|STEP_LEVEL_MODE_POWER_SAVE,
2055 };
2056 public static final int[] STEP_LEVEL_MODE_VALUES = new int[] {
2057 (Display.STATE_OFF-1),
2058 (Display.STATE_OFF-1)|STEP_LEVEL_MODE_POWER_SAVE,
2059 (Display.STATE_ON-1),
2060 (Display.STATE_ON-1)|STEP_LEVEL_MODE_POWER_SAVE,
2061 (Display.STATE_DOZE-1),
2062 (Display.STATE_DOZE-1)|STEP_LEVEL_MODE_POWER_SAVE,
2063 (Display.STATE_DOZE_SUSPEND-1),
2064 (Display.STATE_DOZE_SUSPEND-1)|STEP_LEVEL_MODE_POWER_SAVE,
2065 };
2066 public static final String[] STEP_LEVEL_MODE_LABELS = new String[] {
2067 "screen off",
2068 "screen off power save",
2069 "screen on",
2070 "screen on power save",
2071 "screen doze",
2072 "screen doze power save",
2073 "screen doze-suspend",
2074 "screen doze-suspend power save",
2075 };
2076 public static final String[] STEP_LEVEL_MODE_TAGS = new String[] {
2077 "off",
2078 "off-save",
2079 "on",
2080 "on-save",
2081 "doze",
2082 "doze-save",
2083 "susp",
2084 "susp-save",
2085 };
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002086
2087 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002088 * Return the array of discharge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002089 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002090 public abstract LevelStepTracker getDischargeLevelStepTracker();
2091
2092 /**
2093 * Return the array of daily discharge step durations.
2094 */
2095 public abstract LevelStepTracker getDailyDischargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002096
2097 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002098 * Compute an approximation for how much time (in microseconds) remains until the battery
2099 * is fully charged. Returns -1 if no time can be computed: either there is not
2100 * enough current data to make a decision, or the battery is currently
2101 * discharging.
2102 *
2103 * @param curTime The current elepsed realtime in microseconds.
2104 */
2105 public abstract long computeChargeTimeRemaining(long curTime);
2106
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002107 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002108 * Return the array of charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002109 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002110 public abstract LevelStepTracker getChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002111
2112 /**
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002113 * Return the array of daily charge step durations.
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002114 */
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08002115 public abstract LevelStepTracker getDailyChargeLevelStepTracker();
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07002116
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002117 public abstract Map<String, ? extends Timer> getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002118
Evan Millarc64edde2009-04-18 12:26:32 -07002119 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120
Amith Yamasanie43530a2009-08-21 13:11:37 -07002121 /** Returns the number of different speeds that the CPU can run at */
2122 public abstract int getCpuSpeedSteps();
2123
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002124 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
2125
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002126 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002127 long days = seconds / (60 * 60 * 24);
2128 if (days != 0) {
2129 out.append(days);
2130 out.append("d ");
2131 }
2132 long used = days * 60 * 60 * 24;
2133
2134 long hours = (seconds - used) / (60 * 60);
2135 if (hours != 0 || used != 0) {
2136 out.append(hours);
2137 out.append("h ");
2138 }
2139 used += hours * 60 * 60;
2140
2141 long mins = (seconds-used) / 60;
2142 if (mins != 0 || used != 0) {
2143 out.append(mins);
2144 out.append("m ");
2145 }
2146 used += mins * 60;
2147
2148 if (seconds != 0 || used != 0) {
2149 out.append(seconds-used);
2150 out.append("s ");
2151 }
2152 }
2153
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002154 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002155 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002156 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 sb.append(time - (sec * 1000));
2158 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159 }
2160
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002161 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002162 long sec = time / 1000;
2163 formatTimeRaw(sb, sec);
2164 sb.append(time - (sec * 1000));
2165 sb.append("ms");
2166 }
2167
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002168 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002170 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 }
2172 float perc = ((float)num) / ((float)den) * 100;
2173 mFormatBuilder.setLength(0);
2174 mFormatter.format("%.1f%%", perc);
2175 return mFormatBuilder.toString();
2176 }
2177
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002178 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07002179 mFormatBuilder.setLength(0);
2180
2181 if (bytes < BYTES_PER_KB) {
2182 return bytes + "B";
2183 } else if (bytes < BYTES_PER_MB) {
2184 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
2185 return mFormatBuilder.toString();
2186 } else if (bytes < BYTES_PER_GB){
2187 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
2188 return mFormatBuilder.toString();
2189 } else {
2190 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
2191 return mFormatBuilder.toString();
2192 }
2193 }
2194
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002195 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002196 if (timer != null) {
2197 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002198 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002199 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
2200 return totalTimeMillis;
2201 }
2202 return 0;
2203 }
2204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 /**
2206 *
2207 * @param sb a StringBuilder object.
2208 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002209 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002211 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002212 * @param linePrefix a String to be prepended to each line of output.
2213 * @return the line prefix
2214 */
2215 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002216 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217
2218 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002219 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002220
Evan Millarc64edde2009-04-18 12:26:32 -07002221 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 if (totalTimeMillis != 0) {
2223 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002224 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08002225 if (name != null) {
2226 sb.append(name);
2227 sb.append(' ');
2228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002229 sb.append('(');
2230 sb.append(count);
2231 sb.append(" times)");
2232 return ", ";
2233 }
2234 }
2235 return linePrefix;
2236 }
2237
2238 /**
2239 * Checkin version of wakelock printer. Prints simple comma-separated list.
2240 *
2241 * @param sb a StringBuilder object.
2242 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002243 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002245 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 * @param linePrefix a String to be prepended to each line of output.
2247 * @return the line prefix
2248 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002249 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
2250 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 long totalTimeMicros = 0;
2252 int count = 0;
2253 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002254 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07002255 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 }
2257 sb.append(linePrefix);
2258 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
2259 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07002260 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002261 sb.append(count);
2262 return ",";
2263 }
2264
2265 /**
2266 * Dump a comma-separated line of values for terse checkin mode.
2267 *
2268 * @param pw the PageWriter to dump log to
2269 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
2270 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
2271 * @param args type-dependent data arguments
2272 */
2273 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
2274 Object... args ) {
2275 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
2276 pw.print(uid); pw.print(',');
2277 pw.print(category); pw.print(',');
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002278 pw.print(type);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279
2280 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002281 pw.print(',');
2282 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002283 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002284 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07002286
2287 /**
2288 * Temporary for settings.
2289 */
2290 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
2291 dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2292 }
2293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002294 /**
2295 * Checkin server version of dump to produce more compact, computer-readable log.
2296 *
2297 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 */
Dianne Hackbornd953c532014-08-16 18:17:38 -07002299 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
2300 boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002301 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2302 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2303 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2305 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002306 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2307 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2308 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309 final long totalRealtime = computeRealtime(rawRealtime, which);
2310 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002311 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002312 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002313 final long lowPowerModeEnabledTime = getLowPowerModeEnabledTime(rawRealtime, which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002314 final int connChanges = getNumConnectivityChange(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002315 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
2316 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2317 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
2318 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 StringBuilder sb = new StringBuilder(128);
2321
Evan Millar22ac0432009-03-31 11:33:18 -07002322 SparseArray<? extends Uid> uidStats = getUidStats();
2323 final int NU = uidStats.size();
2324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 // Dump "battery" stat
2328 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002329 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07002330 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002331 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002332 getStartClockTime(),
2333 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002334
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002335 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002336 long fullWakeLockTimeTotal = 0;
2337 long partialWakeLockTimeTotal = 0;
2338
2339 for (int iu = 0; iu < NU; iu++) {
2340 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002341
Evan Millar22ac0432009-03-31 11:33:18 -07002342 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
2343 if (wakelocks.size() > 0) {
2344 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
2345 : wakelocks.entrySet()) {
2346 Uid.Wakelock wl = ent.getValue();
2347
2348 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2349 if (fullWakeTimer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002350 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
2351 which);
Evan Millar22ac0432009-03-31 11:33:18 -07002352 }
2353
2354 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2355 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07002356 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002357 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002358 }
2359 }
2360 }
2361 }
2362
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002363 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2364 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2365 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2366 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2367 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2368 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2369 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2370 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
2371
2372 // Dump network stats
2373 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
2374 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
2375 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets);
2376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 // Dump misc stats
2378 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07002379 screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000,
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002380 wifiRunningTime / 1000, bluetoothOnTime / 1000,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002381 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Ashish Sharma213bb2f2014-07-07 17:14:52 -07002382 fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000,
2383 0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which) / 1000,
2384 getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000,
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002385 lowPowerModeEnabledTime / 1000, connChanges);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002386
2387 // Dump screen brightness stats
2388 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
2389 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002390 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07002391 }
2392 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07002393
Dianne Hackborn627bba72009-03-24 22:32:56 -07002394 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08002395 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
2396 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002397 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002398 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002399 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002400 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002401 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08002402 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002403 args[i] = getPhoneSignalStrengthCount(i, which);
2404 }
2405 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002406
Dianne Hackborn627bba72009-03-24 22:32:56 -07002407 // Dump network type stats
2408 args = new Object[NUM_DATA_CONNECTION_TYPES];
2409 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002410 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07002411 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07002412 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
2413 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
2414 args[i] = getPhoneDataConnectionCount(i, which);
2415 }
2416 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002417
2418 // Dump wifi state stats
2419 args = new Object[NUM_WIFI_STATES];
2420 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002421 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002422 }
2423 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
2424 for (int i=0; i<NUM_WIFI_STATES; i++) {
2425 args[i] = getWifiStateCount(i, which);
2426 }
2427 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
2428
Dianne Hackborn3251b902014-06-20 14:40:53 -07002429 // Dump wifi suppl state stats
2430 args = new Object[NUM_WIFI_SUPPL_STATES];
2431 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2432 args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
2433 }
2434 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_TIME_DATA, args);
2435 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
2436 args[i] = getWifiSupplStateCount(i, which);
2437 }
2438 dumpLine(pw, 0 /* uid */, category, WIFI_SUPPL_STATE_COUNT_DATA, args);
2439
2440 // Dump wifi signal strength stats
2441 args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
2442 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2443 args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
2444 }
2445 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
2446 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
2447 args[i] = getWifiSignalStrengthCount(i, which);
2448 }
2449 dumpLine(pw, 0 /* uid */, category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
2450
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002451 // Dump bluetooth state stats
2452 args = new Object[NUM_BLUETOOTH_STATES];
2453 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002454 args[i] = getBluetoothStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002455 }
2456 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_TIME_DATA, args);
2457 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
2458 args[i] = getBluetoothStateCount(i, which);
2459 }
2460 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_COUNT_DATA, args);
2461
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002462 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002463 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07002464 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002465 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002467 if (which == STATS_SINCE_UNPLUGGED) {
2468 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2469 getDischargeStartLevel()-getDischargeCurrentLevel(),
2470 getDischargeStartLevel()-getDischargeCurrentLevel(),
2471 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
2472 } else {
2473 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
2474 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
Dianne Hackborncd0e3352014-08-07 17:08:09 -07002475 getDischargeAmountScreenOnSinceCharge(),
2476 getDischargeAmountScreenOffSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002477 }
2478
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002479 if (reqUid < 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002480 Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002481 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002482 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002483 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002484 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002485 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002486 sb.toString());
2487 }
Evan Millarc64edde2009-04-18 12:26:32 -07002488 }
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002489 Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002490 if (wakeupReasons.size() > 0) {
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002491 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
2492 // Not doing the regular wake lock formatting to remain compatible
2493 // with the old checkin format.
2494 long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
2495 int count = ent.getValue().getCountLocked(which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002496 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07002497 "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002498 }
2499 }
Evan Millarc64edde2009-04-18 12:26:32 -07002500 }
2501
Dianne Hackbornd953c532014-08-16 18:17:38 -07002502 BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002503 helper.create(this);
2504 helper.refreshStats(which, UserHandle.USER_ALL);
2505 List<BatterySipper> sippers = helper.getUsageList();
2506 if (sippers != null && sippers.size() > 0) {
2507 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
2508 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08002509 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002510 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
2511 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
2512 for (int i=0; i<sippers.size(); i++) {
2513 BatterySipper bs = sippers.get(i);
2514 int uid = 0;
2515 String label;
2516 switch (bs.drainType) {
2517 case IDLE:
2518 label="idle";
2519 break;
2520 case CELL:
2521 label="cell";
2522 break;
2523 case PHONE:
2524 label="phone";
2525 break;
2526 case WIFI:
2527 label="wifi";
2528 break;
2529 case BLUETOOTH:
2530 label="blue";
2531 break;
2532 case SCREEN:
2533 label="scrn";
2534 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07002535 case FLASHLIGHT:
2536 label="flashlight";
2537 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002538 case APP:
2539 uid = bs.uidObj.getUid();
2540 label = "uid";
2541 break;
2542 case USER:
2543 uid = UserHandle.getUid(bs.userId, 0);
2544 label = "user";
2545 break;
2546 case UNACCOUNTED:
2547 label = "unacc";
2548 break;
2549 case OVERCOUNTED:
2550 label = "over";
2551 break;
2552 default:
2553 label = "???";
2554 }
2555 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
2556 BatteryStatsHelper.makemAh(bs.value));
2557 }
2558 }
2559
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 for (int iu = 0; iu < NU; iu++) {
2561 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002562 if (reqUid >= 0 && uid != reqUid) {
2563 continue;
2564 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002565 Uid u = uidStats.valueAt(iu);
2566 // Dump Network stats per uid, if any
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002567 long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2568 long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2569 long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2570 long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2571 long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2572 long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002573 long mobileActiveTime = u.getMobileRadioActiveTime(which);
2574 int mobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002575 long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2576 long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002577 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
2578 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07002579 int wifiScanCount = u.getWifiScanCount(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002580 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002581
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002582 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
2583 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002584 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002585 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
2586 wifiBytesRx, wifiBytesTx,
2587 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002588 wifiPacketsRx, wifiPacketsTx,
2589 mobileActiveTime, mobileActiveCount);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002590 }
2591
Dianne Hackborn62793e42015-03-09 11:15:41 -07002592 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07002593 || uidWifiRunningTime != 0) {
Nick Pelly6ccaa542012-06-15 15:22:47 -07002594 dumpLine(pw, uid, category, WIFI_DATA,
Dianne Hackborn62793e42015-03-09 11:15:41 -07002595 fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime, wifiScanCount);
The Android Open Source Project10592532009-03-18 17:39:46 -07002596 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002597
Dianne Hackborn617f8772009-03-31 15:04:46 -07002598 if (u.hasUserActivity()) {
2599 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
2600 boolean hasData = false;
2601 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
2602 int val = u.getUserActivityCount(i, which);
2603 args[i] = val;
2604 if (val != 0) hasData = true;
2605 }
2606 if (hasData) {
Ashish Sharmacba12152014-07-07 17:14:52 -07002607 dumpLine(pw, uid /* uid */, category, USER_ACTIVITY_DATA, args);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002608 }
2609 }
2610
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002611 Map<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 if (wakelocks.size() > 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002613 for (Map.Entry<String, ? extends Uid.Wakelock> ent : wakelocks.entrySet()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 Uid.Wakelock wl = ent.getValue();
2615 String linePrefix = "";
2616 sb.setLength(0);
Evan Millarc64edde2009-04-18 12:26:32 -07002617 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002618 rawRealtime, "f", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07002619 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002620 rawRealtime, "p", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07002621 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002622 rawRealtime, "w", which, linePrefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623
2624 // Only log if we had at lease one wakelock...
2625 if (sb.length() > 0) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07002626 String name = ent.getKey();
2627 if (name.indexOf(',') >= 0) {
2628 name = name.replace(',', '_');
2629 }
2630 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002631 }
2632 }
2633 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07002634
Dianne Hackbornfdb19562014-07-11 16:03:36 -07002635 Map<String, ? extends Timer> syncs = u.getSyncStats();
2636 if (syncs.size() > 0) {
2637 for (Map.Entry<String, ? extends Timer> ent : syncs.entrySet()) {
2638 Timer timer = ent.getValue();
2639 // Convert from microseconds to milliseconds with rounding
2640 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2641 int count = timer.getCountLocked(which);
2642 if (totalTime != 0) {
2643 dumpLine(pw, uid, category, SYNC_DATA, ent.getKey(), totalTime, count);
2644 }
2645 }
2646 }
2647
2648 Map<String, ? extends Timer> jobs = u.getJobStats();
2649 if (jobs.size() > 0) {
2650 for (Map.Entry<String, ? extends Timer> ent : jobs.entrySet()) {
2651 Timer timer = ent.getValue();
2652 // Convert from microseconds to milliseconds with rounding
2653 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2654 int count = timer.getCountLocked(which);
2655 if (totalTime != 0) {
2656 dumpLine(pw, uid, category, JOB_DATA, ent.getKey(), totalTime, count);
2657 }
2658 }
2659 }
2660
Dianne Hackborn61659e52014-07-09 16:13:01 -07002661 SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
2662 int NSE = sensors.size();
2663 for (int ise=0; ise<NSE; ise++) {
2664 Uid.Sensor se = sensors.valueAt(ise);
2665 int sensorNumber = sensors.keyAt(ise);
2666 Timer timer = se.getSensorTime();
2667 if (timer != null) {
2668 // Convert from microseconds to milliseconds with rounding
2669 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
2670 int count = timer.getCountLocked(which);
2671 if (totalTime != 0) {
2672 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
2673 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002674 }
2675 }
2676
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002677 Timer vibTimer = u.getVibratorOnTimer();
2678 if (vibTimer != null) {
2679 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002680 long totalTime = (vibTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002681 int count = vibTimer.getCountLocked(which);
2682 if (totalTime != 0) {
2683 dumpLine(pw, uid, category, VIBRATOR_DATA, totalTime, count);
2684 }
2685 }
2686
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002687 Timer fgTimer = u.getForegroundActivityTimer();
2688 if (fgTimer != null) {
2689 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002690 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002691 int count = fgTimer.getCountLocked(which);
2692 if (totalTime != 0) {
2693 dumpLine(pw, uid, category, FOREGROUND_DATA, totalTime, count);
2694 }
2695 }
2696
Dianne Hackborn61659e52014-07-09 16:13:01 -07002697 Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
2698 long totalStateTime = 0;
2699 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
2700 totalStateTime += u.getProcessStateTime(ips, rawRealtime, which);
2701 stateTimes[ips] = (totalStateTime + 500) / 1000;
2702 }
2703 if (totalStateTime > 0) {
2704 dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
2705 }
2706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
2708 if (processStats.size() > 0) {
2709 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
2710 : processStats.entrySet()) {
2711 Uid.Proc ps = ent.getValue();
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002712
Dianne Hackborn62793e42015-03-09 11:15:41 -07002713 final long userMillis = ps.getUserTime(which);
2714 final long systemMillis = ps.getSystemTime(which);
2715 final long foregroundMillis = ps.getForegroundTime(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002716 final int starts = ps.getStarts(which);
2717 final int numCrashes = ps.getNumCrashes(which);
2718 final int numAnrs = ps.getNumAnrs(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002719
2720 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002721 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002722 dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis,
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002723 systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002724 }
2725 }
2726 }
2727
2728 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
2729 if (packageStats.size() > 0) {
2730 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
2731 : packageStats.entrySet()) {
2732
2733 Uid.Pkg ps = ent.getValue();
2734 int wakeups = ps.getWakeups(which);
2735 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
2736 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
2737 : serviceStats.entrySet()) {
2738 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
2739 long startTime = ss.getStartTime(batteryUptime, which);
2740 int starts = ss.getStarts(which);
2741 int launches = ss.getLaunches(which);
2742 if (startTime != 0 || starts != 0 || launches != 0) {
2743 dumpLine(pw, uid, category, APK_DATA,
2744 wakeups, // wakeup alarms
2745 ent.getKey(), // Apk
2746 sent.getKey(), // service
2747 startTime / 1000, // time spent started, in ms
2748 starts,
2749 launches);
2750 }
2751 }
2752 }
2753 }
2754 }
2755 }
2756
Dianne Hackborn81038902012-11-26 17:04:09 -08002757 static final class TimerEntry {
2758 final String mName;
2759 final int mId;
2760 final BatteryStats.Timer mTimer;
2761 final long mTime;
2762 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
2763 mName = name;
2764 mId = id;
2765 mTimer = timer;
2766 mTime = time;
2767 }
2768 }
2769
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002770 private void printmAh(PrintWriter printer, double power) {
2771 printer.print(BatteryStatsHelper.makemAh(power));
2772 }
2773
Dianne Hackbornd953c532014-08-16 18:17:38 -07002774 /**
2775 * Temporary for settings.
2776 */
2777 public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which,
2778 int reqUid) {
2779 dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context));
2780 }
2781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002782 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002783 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
Dianne Hackbornd953c532014-08-16 18:17:38 -07002784 int reqUid, boolean wifiOnly) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2786 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2787 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788
2789 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2790 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
2791 final long totalRealtime = computeRealtime(rawRealtime, which);
2792 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002793 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2794 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2795 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002796 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
2797 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002799 StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07002800
2801 SparseArray<? extends Uid> uidStats = getUidStats();
2802 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002804 sb.setLength(0);
2805 sb.append(prefix);
2806 sb.append(" Time on battery: ");
2807 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
2808 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
2809 sb.append(") realtime, ");
2810 formatTimeMs(sb, whichBatteryUptime / 1000);
2811 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
2812 sb.append(") uptime");
2813 pw.println(sb.toString());
2814 sb.setLength(0);
2815 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002816 sb.append(" Time on battery screen off: ");
2817 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
2818 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
2819 sb.append(") realtime, ");
2820 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
2821 sb.append("(");
2822 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
2823 sb.append(") uptime");
2824 pw.println(sb.toString());
2825 sb.setLength(0);
2826 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002827 sb.append(" Total run time: ");
2828 formatTimeMs(sb, totalRealtime / 1000);
2829 sb.append("realtime, ");
2830 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002831 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07002832 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002833 if (batteryTimeRemaining >= 0) {
2834 sb.setLength(0);
2835 sb.append(prefix);
2836 sb.append(" Battery time remaining: ");
2837 formatTimeMs(sb, batteryTimeRemaining / 1000);
2838 pw.println(sb.toString());
2839 }
2840 if (chargeTimeRemaining >= 0) {
2841 sb.setLength(0);
2842 sb.append(prefix);
2843 sb.append(" Charge time remaining: ");
2844 formatTimeMs(sb, chargeTimeRemaining / 1000);
2845 pw.println(sb.toString());
2846 }
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002847 pw.print(" Start clock time: ");
2848 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
2849
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002850 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002851 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002852 final long lowPowerModeEnabledTime = getLowPowerModeEnabledTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002853 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
2854 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
2855 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2856 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002857 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002858 sb.append(prefix);
2859 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
2860 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002861 sb.append(") "); sb.append(getScreenOnCount(which));
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002862 sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
2863 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
Jeff Browne95c3cd2014-05-02 16:59:26 -07002864 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002865 pw.println(sb.toString());
2866 sb.setLength(0);
2867 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002868 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002869 boolean didOne = false;
2870 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002871 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002872 if (time == 0) {
2873 continue;
2874 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002875 sb.append("\n ");
2876 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002877 didOne = true;
2878 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
2879 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002880 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002881 sb.append("(");
2882 sb.append(formatRatioLocked(time, screenOnTime));
2883 sb.append(")");
2884 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002885 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002886 pw.println(sb.toString());
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002887 if (lowPowerModeEnabledTime != 0) {
2888 sb.setLength(0);
2889 sb.append(prefix);
2890 sb.append(" Low power mode enabled: ");
2891 formatTimeMs(sb, lowPowerModeEnabledTime / 1000);
2892 sb.append("(");
2893 sb.append(formatRatioLocked(lowPowerModeEnabledTime, whichBatteryRealtime));
2894 sb.append(")");
2895 pw.println(sb.toString());
2896 }
2897 if (phoneOnTime != 0) {
2898 sb.setLength(0);
2899 sb.append(prefix);
2900 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
2901 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
2902 sb.append(") "); sb.append(getPhoneOnCount(which));
2903 }
Dianne Hackborn1e01d162014-12-04 17:46:42 -08002904 int connChanges = getNumConnectivityChange(which);
2905 if (connChanges != 0) {
2906 pw.print(prefix);
2907 pw.print(" Connectivity changes: "); pw.println(connChanges);
2908 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07002909
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002910 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002911 long fullWakeLockTimeTotalMicros = 0;
2912 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08002913
Dianne Hackborn81038902012-11-26 17:04:09 -08002914 final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>();
2915
Evan Millar22ac0432009-03-31 11:33:18 -07002916 for (int iu = 0; iu < NU; iu++) {
2917 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002918
Evan Millar22ac0432009-03-31 11:33:18 -07002919 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
2920 if (wakelocks.size() > 0) {
2921 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
2922 : wakelocks.entrySet()) {
2923 Uid.Wakelock wl = ent.getValue();
2924
2925 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2926 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07002927 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002928 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002929 }
2930
2931 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2932 if (partialWakeTimer != null) {
Dianne Hackborn81038902012-11-26 17:04:09 -08002933 long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002934 rawRealtime, which);
Dianne Hackborn81038902012-11-26 17:04:09 -08002935 if (totalTimeMicros > 0) {
2936 if (reqUid < 0) {
2937 // Only show the ordered list of all wake
2938 // locks if the caller is not asking for data
2939 // about a specific uid.
2940 timers.add(new TimerEntry(ent.getKey(), u.getUid(),
2941 partialWakeTimer, totalTimeMicros));
2942 }
2943 partialWakeLockTimeTotalMicros += totalTimeMicros;
2944 }
Evan Millar22ac0432009-03-31 11:33:18 -07002945 }
2946 }
2947 }
2948 }
2949
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002950 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2951 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2952 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2953 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2954 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2955 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2956 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2957 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
2958
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002959 if (fullWakeLockTimeTotalMicros != 0) {
2960 sb.setLength(0);
2961 sb.append(prefix);
2962 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
2963 (fullWakeLockTimeTotalMicros + 500) / 1000);
2964 pw.println(sb.toString());
2965 }
2966
2967 if (partialWakeLockTimeTotalMicros != 0) {
2968 sb.setLength(0);
2969 sb.append(prefix);
2970 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
2971 (partialWakeLockTimeTotalMicros + 500) / 1000);
2972 pw.println(sb.toString());
2973 }
2974
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002975 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002976 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
2977 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
2978 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
2979 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002980 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002981 sb.append(prefix);
Dianne Hackborn3251b902014-06-20 14:40:53 -07002982 sb.append(" Phone signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002983 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08002984 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002985 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002986 if (time == 0) {
2987 continue;
2988 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002989 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002990 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002991 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08002992 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002993 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002994 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002995 sb.append("(");
2996 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002997 sb.append(") ");
2998 sb.append(getPhoneSignalStrengthCount(i, which));
2999 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003000 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003001 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003002 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07003003
3004 sb.setLength(0);
3005 sb.append(prefix);
3006 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003007 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07003008 pw.println(sb.toString());
3009
Dianne Hackborn627bba72009-03-24 22:32:56 -07003010 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003011 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003012 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003013 didOne = false;
3014 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003015 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003016 if (time == 0) {
3017 continue;
3018 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003019 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003020 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003021 didOne = true;
3022 sb.append(DATA_CONNECTION_NAMES[i]);
3023 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003024 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07003025 sb.append("(");
3026 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07003027 sb.append(") ");
3028 sb.append(getPhoneDataConnectionCount(i, which));
3029 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003030 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003031 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07003032 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003033
3034 sb.setLength(0);
3035 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08003036 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003037 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003038 formatTimeMs(sb, mobileActiveTime / 1000);
3039 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
3040 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
3041 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07003042 pw.println(sb.toString());
3043
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003044 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
3045 if (mobileActiveUnknownTime != 0) {
3046 sb.setLength(0);
3047 sb.append(prefix);
3048 sb.append(" Mobile radio active unknown time: ");
3049 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
3050 sb.append("(");
3051 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
3052 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
3053 sb.append("x");
3054 pw.println(sb.toString());
3055 }
3056
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003057 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
3058 if (mobileActiveAdjustedTime != 0) {
3059 sb.setLength(0);
3060 sb.append(prefix);
3061 sb.append(" Mobile radio active adjusted time: ");
3062 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
3063 sb.append("(");
3064 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
3065 sb.append(")");
3066 pw.println(sb.toString());
3067 }
3068
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003069 pw.print(prefix);
3070 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
3071 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
3072 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
3073 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003074 sb.setLength(0);
3075 sb.append(prefix);
3076 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
3077 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
3078 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
3079 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003080 sb.append(")");
3081 pw.println(sb.toString());
3082
3083 sb.setLength(0);
3084 sb.append(prefix);
3085 sb.append(" Wifi states:");
3086 didOne = false;
3087 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003088 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003089 if (time == 0) {
3090 continue;
3091 }
3092 sb.append("\n ");
3093 didOne = true;
3094 sb.append(WIFI_STATE_NAMES[i]);
3095 sb.append(" ");
3096 formatTimeMs(sb, time/1000);
3097 sb.append("(");
3098 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3099 sb.append(") ");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003100 sb.append(getWifiStateCount(i, which));
3101 sb.append("x");
3102 }
3103 if (!didOne) sb.append(" (no activity)");
3104 pw.println(sb.toString());
3105
3106 sb.setLength(0);
3107 sb.append(prefix);
3108 sb.append(" Wifi supplicant states:");
3109 didOne = false;
3110 for (int i=0; i<NUM_WIFI_SUPPL_STATES; i++) {
3111 final long time = getWifiSupplStateTime(i, rawRealtime, which);
3112 if (time == 0) {
3113 continue;
3114 }
3115 sb.append("\n ");
3116 didOne = true;
3117 sb.append(WIFI_SUPPL_STATE_NAMES[i]);
3118 sb.append(" ");
3119 formatTimeMs(sb, time/1000);
3120 sb.append("(");
3121 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3122 sb.append(") ");
3123 sb.append(getWifiSupplStateCount(i, which));
3124 sb.append("x");
3125 }
3126 if (!didOne) sb.append(" (no activity)");
3127 pw.println(sb.toString());
3128
3129 sb.setLength(0);
3130 sb.append(prefix);
3131 sb.append(" Wifi signal levels:");
3132 didOne = false;
3133 for (int i=0; i<NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
3134 final long time = getWifiSignalStrengthTime(i, rawRealtime, which);
3135 if (time == 0) {
3136 continue;
3137 }
3138 sb.append("\n ");
3139 sb.append(prefix);
3140 didOne = true;
3141 sb.append("level(");
3142 sb.append(i);
3143 sb.append(") ");
3144 formatTimeMs(sb, time/1000);
3145 sb.append("(");
3146 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3147 sb.append(") ");
3148 sb.append(getWifiSignalStrengthCount(i, which));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003149 sb.append("x");
3150 }
3151 if (!didOne) sb.append(" (no activity)");
3152 pw.println(sb.toString());
3153
Adam Lesinski33dac552015-03-09 15:24:48 -07003154 final long wifiIdleTimeMs = getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which);
3155 final long wifiRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which);
3156 final long wifiTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which);
3157 final long wifiTotalTimeMs = wifiIdleTimeMs + wifiRxTimeMs + wifiTxTimeMs;
3158
3159 sb.setLength(0);
3160 sb.append(prefix);
3161 sb.append(" WiFi Idle time: "); formatTimeMs(sb, wifiIdleTimeMs);
3162 sb.append(" (");
3163 sb.append(formatRatioLocked(wifiIdleTimeMs, wifiTotalTimeMs));
3164 sb.append(")");
3165 pw.println(sb.toString());
3166
3167 sb.setLength(0);
3168 sb.append(prefix);
3169 sb.append(" WiFi Rx time: "); formatTimeMs(sb, wifiRxTimeMs);
3170 sb.append(" (");
3171 sb.append(formatRatioLocked(wifiRxTimeMs, wifiTotalTimeMs));
3172 sb.append(")");
3173 pw.println(sb.toString());
3174
3175 sb.setLength(0);
3176 sb.append(prefix);
3177 sb.append(" WiFi Tx time: "); formatTimeMs(sb, wifiTxTimeMs);
3178 sb.append(" (");
3179 sb.append(formatRatioLocked(wifiTxTimeMs, wifiTotalTimeMs));
3180 sb.append(")");
3181 pw.println(sb.toString());
3182
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003183 sb.setLength(0);
3184 sb.append(prefix);
3185 sb.append(" Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003186 sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime));
3187 sb.append(")");
3188 pw.println(sb.toString());
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003189
3190 sb.setLength(0);
3191 sb.append(prefix);
3192 sb.append(" Bluetooth states:");
3193 didOne = false;
3194 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003195 final long time = getBluetoothStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003196 if (time == 0) {
3197 continue;
3198 }
3199 sb.append("\n ");
3200 didOne = true;
3201 sb.append(BLUETOOTH_STATE_NAMES[i]);
3202 sb.append(" ");
3203 formatTimeMs(sb, time/1000);
3204 sb.append("(");
3205 sb.append(formatRatioLocked(time, whichBatteryRealtime));
3206 sb.append(") ");
3207 sb.append(getPhoneDataConnectionCount(i, which));
3208 sb.append("x");
3209 }
Adam Lesinski33dac552015-03-09 15:24:48 -07003210
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003211 if (!didOne) sb.append(" (no activity)");
3212 pw.println(sb.toString());
3213
Adam Lesinski33dac552015-03-09 15:24:48 -07003214 final long bluetoothIdleTimeMs =
3215 getBluetoothControllerActivity(CONTROLLER_IDLE_TIME, which);
3216 final long bluetoothRxTimeMs = getBluetoothControllerActivity(CONTROLLER_RX_TIME, which);
3217 final long bluetoothTxTimeMs = getBluetoothControllerActivity(CONTROLLER_TX_TIME, which);
3218 final long bluetoothTotalTimeMs = bluetoothIdleTimeMs + bluetoothRxTimeMs +
3219 bluetoothTxTimeMs;
3220
3221 sb.setLength(0);
3222 sb.append(prefix);
3223 sb.append(" Bluetooth Idle time: "); formatTimeMs(sb, bluetoothIdleTimeMs);
3224 sb.append(" (");
3225 sb.append(formatRatioLocked(bluetoothIdleTimeMs, bluetoothTotalTimeMs));
3226 sb.append(")");
3227 pw.println(sb.toString());
3228
3229 sb.setLength(0);
3230 sb.append(prefix);
3231 sb.append(" Bluetooth Rx time: "); formatTimeMs(sb, bluetoothRxTimeMs);
3232 sb.append(" (");
3233 sb.append(formatRatioLocked(bluetoothRxTimeMs, bluetoothTotalTimeMs));
3234 sb.append(")");
3235 pw.println(sb.toString());
3236
3237 sb.setLength(0);
3238 sb.append(prefix);
3239 sb.append(" Bluetooth Tx time: "); formatTimeMs(sb, bluetoothTxTimeMs);
3240 sb.append(" (");
3241 sb.append(formatRatioLocked(bluetoothTxTimeMs, bluetoothTotalTimeMs));
3242 sb.append(")");
3243 pw.println(sb.toString());
3244
Dianne Hackbornca1bf212014-02-14 14:18:36 -08003245 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003246
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003247 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07003248 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003249 pw.print(prefix); pw.println(" Device is currently unplugged");
3250 pw.print(prefix); pw.print(" Discharge cycle start level: ");
3251 pw.println(getDischargeStartLevel());
3252 pw.print(prefix); pw.print(" Discharge cycle current level: ");
3253 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07003254 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003255 pw.print(prefix); pw.println(" Device is currently plugged into power");
3256 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
3257 pw.println(getDischargeStartLevel());
3258 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
3259 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07003260 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003261 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3262 pw.println(getDischargeAmountScreenOn());
3263 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3264 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07003265 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003266 } else {
3267 pw.print(prefix); pw.println(" Device battery use since last full charge");
3268 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
3269 pw.println(getLowDischargeAmountSinceCharge());
3270 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
3271 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08003272 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
3273 pw.println(getDischargeAmountScreenOnSinceCharge());
3274 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
3275 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08003276 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07003277 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003278
Dianne Hackbornd953c532014-08-16 18:17:38 -07003279 BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003280 helper.create(this);
3281 helper.refreshStats(which, UserHandle.USER_ALL);
3282 List<BatterySipper> sippers = helper.getUsageList();
3283 if (sippers != null && sippers.size() > 0) {
3284 pw.print(prefix); pw.println(" Estimated power use (mAh):");
3285 pw.print(prefix); pw.print(" Capacity: ");
3286 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08003287 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborn536456f2014-05-23 16:51:05 -07003288 pw.print(", actual drain: "); printmAh(pw, helper.getMinDrainedPower());
3289 if (helper.getMinDrainedPower() != helper.getMaxDrainedPower()) {
3290 pw.print("-"); printmAh(pw, helper.getMaxDrainedPower());
3291 }
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003292 pw.println();
3293 for (int i=0; i<sippers.size(); i++) {
3294 BatterySipper bs = sippers.get(i);
3295 switch (bs.drainType) {
3296 case IDLE:
3297 pw.print(prefix); pw.print(" Idle: "); printmAh(pw, bs.value);
3298 pw.println();
3299 break;
3300 case CELL:
3301 pw.print(prefix); pw.print(" Cell standby: "); printmAh(pw, bs.value);
3302 pw.println();
3303 break;
3304 case PHONE:
3305 pw.print(prefix); pw.print(" Phone calls: "); printmAh(pw, bs.value);
3306 pw.println();
3307 break;
3308 case WIFI:
3309 pw.print(prefix); pw.print(" Wifi: "); printmAh(pw, bs.value);
3310 pw.println();
3311 break;
3312 case BLUETOOTH:
3313 pw.print(prefix); pw.print(" Bluetooth: "); printmAh(pw, bs.value);
3314 pw.println();
3315 break;
3316 case SCREEN:
3317 pw.print(prefix); pw.print(" Screen: "); printmAh(pw, bs.value);
3318 pw.println();
3319 break;
Dianne Hackbornabc7c492014-06-30 16:57:46 -07003320 case FLASHLIGHT:
3321 pw.print(prefix); pw.print(" Flashlight: "); printmAh(pw, bs.value);
3322 pw.println();
3323 break;
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003324 case APP:
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003325 pw.print(prefix); pw.print(" Uid ");
3326 UserHandle.formatUid(pw, bs.uidObj.getUid());
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003327 pw.print(": "); printmAh(pw, bs.value); pw.println();
3328 break;
3329 case USER:
3330 pw.print(prefix); pw.print(" User "); pw.print(bs.userId);
3331 pw.print(": "); printmAh(pw, bs.value); pw.println();
3332 break;
3333 case UNACCOUNTED:
3334 pw.print(prefix); pw.print(" Unaccounted: "); printmAh(pw, bs.value);
3335 pw.println();
3336 break;
3337 case OVERCOUNTED:
3338 pw.print(prefix); pw.print(" Over-counted: "); printmAh(pw, bs.value);
3339 pw.println();
3340 break;
3341 }
3342 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08003343 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003344 }
3345
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003346 sippers = helper.getMobilemsppList();
3347 if (sippers != null && sippers.size() > 0) {
3348 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003349 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003350 for (int i=0; i<sippers.size(); i++) {
3351 BatterySipper bs = sippers.get(i);
3352 sb.setLength(0);
3353 sb.append(prefix); sb.append(" Uid ");
3354 UserHandle.formatUid(sb, bs.uidObj.getUid());
3355 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
3356 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
3357 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003358 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003359 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003360 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003361 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08003362 sb.setLength(0);
3363 sb.append(prefix);
3364 sb.append(" TOTAL TIME: ");
3365 formatTimeMs(sb, totalTime);
3366 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
3367 sb.append(")");
3368 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003369 pw.println();
3370 }
3371
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003372 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
3373 @Override
3374 public int compare(TimerEntry lhs, TimerEntry rhs) {
3375 long lhsTime = lhs.mTime;
3376 long rhsTime = rhs.mTime;
3377 if (lhsTime < rhsTime) {
3378 return 1;
3379 }
3380 if (lhsTime > rhsTime) {
3381 return -1;
3382 }
3383 return 0;
3384 }
3385 };
3386
3387 if (reqUid < 0) {
3388 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
3389 if (kernelWakelocks.size() > 0) {
3390 final ArrayList<TimerEntry> ktimers = new ArrayList<TimerEntry>();
3391 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
3392 BatteryStats.Timer timer = ent.getValue();
3393 long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
3394 if (totalTimeMillis > 0) {
3395 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
3396 }
3397 }
3398 if (ktimers.size() > 0) {
3399 Collections.sort(ktimers, timerComparator);
3400 pw.print(prefix); pw.println(" All kernel wake locks:");
3401 for (int i=0; i<ktimers.size(); i++) {
3402 TimerEntry timer = ktimers.get(i);
3403 String linePrefix = ": ";
3404 sb.setLength(0);
3405 sb.append(prefix);
3406 sb.append(" Kernel Wake lock ");
3407 sb.append(timer.mName);
3408 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
3409 which, linePrefix);
3410 if (!linePrefix.equals(": ")) {
3411 sb.append(" realtime");
3412 // Only print out wake locks that were held
3413 pw.println(sb.toString());
3414 }
3415 }
3416 pw.println();
3417 }
3418 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003419
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003420 if (timers.size() > 0) {
3421 Collections.sort(timers, timerComparator);
3422 pw.print(prefix); pw.println(" All partial wake locks:");
3423 for (int i=0; i<timers.size(); i++) {
3424 TimerEntry timer = timers.get(i);
3425 sb.setLength(0);
3426 sb.append(" Wake lock ");
3427 UserHandle.formatUid(sb, timer.mId);
3428 sb.append(" ");
3429 sb.append(timer.mName);
3430 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3431 sb.append(" realtime");
3432 pw.println(sb.toString());
3433 }
3434 timers.clear();
3435 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08003436 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003437
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003438 Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003439 if (wakeupReasons.size() > 0) {
3440 pw.print(prefix); pw.println(" All wakeup reasons:");
3441 final ArrayList<TimerEntry> reasons = new ArrayList<TimerEntry>();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003442 for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
3443 Timer timer = ent.getValue();
3444 reasons.add(new TimerEntry(ent.getKey(), 0, timer,
3445 timer.getCountLocked(which)));
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003446 }
3447 Collections.sort(reasons, timerComparator);
3448 for (int i=0; i<reasons.size(); i++) {
3449 TimerEntry timer = reasons.get(i);
3450 String linePrefix = ": ";
3451 sb.setLength(0);
3452 sb.append(prefix);
3453 sb.append(" Wakeup reason ");
3454 sb.append(timer.mName);
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003455 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
3456 sb.append(" realtime");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003457 pw.println(sb.toString());
3458 }
3459 pw.println();
3460 }
Dianne Hackborn81038902012-11-26 17:04:09 -08003461 }
Evan Millar22ac0432009-03-31 11:33:18 -07003462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003463 for (int iu=0; iu<NU; iu++) {
3464 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08003465 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003466 continue;
3467 }
3468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003469 Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07003470
3471 pw.print(prefix);
3472 pw.print(" ");
3473 UserHandle.formatUid(pw, uid);
3474 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003475 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003476
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003477 long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
3478 long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
3479 long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
3480 long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
3481 long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
3482 long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003483 long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
3484 int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003485 long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
3486 long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003487 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
3488 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
Dianne Hackborn62793e42015-03-09 11:15:41 -07003489 int wifiScanCount = u.getWifiScanCount(which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003490 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003491
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003492 if (mobileRxBytes > 0 || mobileTxBytes > 0
3493 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003494 pw.print(prefix); pw.print(" Mobile network: ");
3495 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003496 pw.print(formatBytesLocked(mobileTxBytes));
3497 pw.print(" sent (packets "); pw.print(mobileRxPackets);
3498 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003499 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003500 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
3501 sb.setLength(0);
3502 sb.append(prefix); sb.append(" Mobile radio active: ");
3503 formatTimeMs(sb, uidMobileActiveTime / 1000);
3504 sb.append("(");
3505 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
3506 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
3507 long packets = mobileRxPackets + mobileTxPackets;
3508 if (packets == 0) {
3509 packets = 1;
3510 }
3511 sb.append(" @ ");
3512 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
3513 sb.append(" mspp");
3514 pw.println(sb.toString());
3515 }
3516
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003517 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003518 pw.print(prefix); pw.print(" Wi-Fi network: ");
3519 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003520 pw.print(formatBytesLocked(wifiTxBytes));
3521 pw.print(" sent (packets "); pw.print(wifiRxPackets);
3522 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07003523 }
3524
Dianne Hackborn62793e42015-03-09 11:15:41 -07003525 if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003526 || uidWifiRunningTime != 0) {
3527 sb.setLength(0);
3528 sb.append(prefix); sb.append(" Wifi Running: ");
3529 formatTimeMs(sb, uidWifiRunningTime / 1000);
3530 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
3531 whichBatteryRealtime)); sb.append(")\n");
3532 sb.append(prefix); sb.append(" Full Wifi Lock: ");
3533 formatTimeMs(sb, fullWifiLockOnTime / 1000);
3534 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
3535 whichBatteryRealtime)); sb.append(")\n");
3536 sb.append(prefix); sb.append(" Wifi Scan: ");
3537 formatTimeMs(sb, wifiScanTime / 1000);
3538 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
Dianne Hackborn62793e42015-03-09 11:15:41 -07003539 whichBatteryRealtime)); sb.append(") ");
3540 sb.append(wifiScanCount);
3541 sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08003542 pw.println(sb.toString());
3543 }
3544
Dianne Hackborn617f8772009-03-31 15:04:46 -07003545 if (u.hasUserActivity()) {
3546 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07003547 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07003548 int val = u.getUserActivityCount(i, which);
3549 if (val != 0) {
3550 if (!hasData) {
3551 sb.setLength(0);
3552 sb.append(" User activity: ");
3553 hasData = true;
3554 } else {
3555 sb.append(", ");
3556 }
3557 sb.append(val);
3558 sb.append(" ");
3559 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
3560 }
3561 }
3562 if (hasData) {
3563 pw.println(sb.toString());
3564 }
3565 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566
3567 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
3568 if (wakelocks.size() > 0) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003569 long totalFull = 0, totalPartial = 0, totalWindow = 0;
3570 int count = 0;
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003571 for (Map.Entry<String, ? extends Uid.Wakelock> ent : wakelocks.entrySet()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003572 Uid.Wakelock wl = ent.getValue();
3573 String linePrefix = ": ";
3574 sb.setLength(0);
3575 sb.append(prefix);
3576 sb.append(" Wake lock ");
3577 sb.append(ent.getKey());
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003578 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 "full", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003580 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 "partial", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003582 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 "window", which, linePrefix);
Dianne Hackbornacc4a122014-08-18 16:33:44 -07003584 if (true || !linePrefix.equals(": ")) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05003586 // Only print out wake locks that were held
3587 pw.println(sb.toString());
3588 uidActivity = true;
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003589 count++;
3590 }
3591 totalFull += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003592 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003593 totalPartial += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003594 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003595 totalWindow += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003596 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07003597 }
3598 if (count > 1) {
3599 if (totalFull != 0 || totalPartial != 0 || totalWindow != 0) {
3600 sb.setLength(0);
3601 sb.append(prefix);
3602 sb.append(" TOTAL wake: ");
3603 boolean needComma = false;
3604 if (totalFull != 0) {
3605 needComma = true;
3606 formatTimeMs(sb, totalFull);
3607 sb.append("full");
3608 }
3609 if (totalPartial != 0) {
3610 if (needComma) {
3611 sb.append(", ");
3612 }
3613 needComma = true;
3614 formatTimeMs(sb, totalPartial);
3615 sb.append("partial");
3616 }
3617 if (totalWindow != 0) {
3618 if (needComma) {
3619 sb.append(", ");
3620 }
3621 needComma = true;
3622 formatTimeMs(sb, totalWindow);
3623 sb.append("window");
3624 }
3625 sb.append(" realtime");
3626 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 }
3629 }
3630
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003631 Map<String, ? extends Timer> syncs = u.getSyncStats();
3632 if (syncs.size() > 0) {
3633 for (Map.Entry<String, ? extends Timer> ent : syncs.entrySet()) {
3634 Timer timer = ent.getValue();
3635 // Convert from microseconds to milliseconds with rounding
3636 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3637 int count = timer.getCountLocked(which);
3638 sb.setLength(0);
3639 sb.append(prefix);
3640 sb.append(" Sync ");
3641 sb.append(ent.getKey());
3642 sb.append(": ");
3643 if (totalTime != 0) {
3644 formatTimeMs(sb, totalTime);
3645 sb.append("realtime (");
3646 sb.append(count);
3647 sb.append(" times)");
3648 } else {
3649 sb.append("(not used)");
3650 }
3651 pw.println(sb.toString());
3652 uidActivity = true;
3653 }
3654 }
3655
3656 Map<String, ? extends Timer> jobs = u.getJobStats();
Dianne Hackbornc3940bc2014-09-05 15:50:25 -07003657 if (jobs.size() > 0) {
Dianne Hackbornfdb19562014-07-11 16:03:36 -07003658 for (Map.Entry<String, ? extends Timer> ent : jobs.entrySet()) {
3659 Timer timer = ent.getValue();
3660 // Convert from microseconds to milliseconds with rounding
3661 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
3662 int count = timer.getCountLocked(which);
3663 sb.setLength(0);
3664 sb.append(prefix);
3665 sb.append(" Job ");
3666 sb.append(ent.getKey());
3667 sb.append(": ");
3668 if (totalTime != 0) {
3669 formatTimeMs(sb, totalTime);
3670 sb.append("realtime (");
3671 sb.append(count);
3672 sb.append(" times)");
3673 } else {
3674 sb.append("(not used)");
3675 }
3676 pw.println(sb.toString());
3677 uidActivity = true;
3678 }
3679 }
3680
Dianne Hackborn61659e52014-07-09 16:13:01 -07003681 SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
3682 int NSE = sensors.size();
3683 for (int ise=0; ise<NSE; ise++) {
3684 Uid.Sensor se = sensors.valueAt(ise);
3685 int sensorNumber = sensors.keyAt(ise);
3686 sb.setLength(0);
3687 sb.append(prefix);
3688 sb.append(" Sensor ");
3689 int handle = se.getHandle();
3690 if (handle == Uid.Sensor.GPS) {
3691 sb.append("GPS");
3692 } else {
3693 sb.append(handle);
3694 }
3695 sb.append(": ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696
Dianne Hackborn61659e52014-07-09 16:13:01 -07003697 Timer timer = se.getSensorTime();
3698 if (timer != null) {
3699 // Convert from microseconds to milliseconds with rounding
3700 long totalTime = (timer.getTotalTimeLocked(
3701 rawRealtime, which) + 500) / 1000;
3702 int count = timer.getCountLocked(which);
3703 //timer.logState();
3704 if (totalTime != 0) {
3705 formatTimeMs(sb, totalTime);
3706 sb.append("realtime (");
3707 sb.append(count);
3708 sb.append(" times)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 } else {
3710 sb.append("(not used)");
3711 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003712 } else {
3713 sb.append("(not used)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 }
Dianne Hackborn61659e52014-07-09 16:13:01 -07003715
3716 pw.println(sb.toString());
3717 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003718 }
3719
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003720 Timer vibTimer = u.getVibratorOnTimer();
3721 if (vibTimer != null) {
3722 // Convert from microseconds to milliseconds with rounding
3723 long totalTime = (vibTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003724 rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003725 int count = vibTimer.getCountLocked(which);
3726 //timer.logState();
3727 if (totalTime != 0) {
3728 sb.setLength(0);
3729 sb.append(prefix);
3730 sb.append(" Vibrator: ");
3731 formatTimeMs(sb, totalTime);
3732 sb.append("realtime (");
3733 sb.append(count);
3734 sb.append(" times)");
3735 pw.println(sb.toString());
3736 uidActivity = true;
3737 }
3738 }
3739
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003740 Timer fgTimer = u.getForegroundActivityTimer();
3741 if (fgTimer != null) {
3742 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08003743 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003744 int count = fgTimer.getCountLocked(which);
3745 if (totalTime != 0) {
3746 sb.setLength(0);
3747 sb.append(prefix);
3748 sb.append(" Foreground activities: ");
3749 formatTimeMs(sb, totalTime);
3750 sb.append("realtime (");
3751 sb.append(count);
3752 sb.append(" times)");
3753 pw.println(sb.toString());
3754 uidActivity = true;
3755 }
3756 }
3757
Dianne Hackborn61659e52014-07-09 16:13:01 -07003758 long totalStateTime = 0;
3759 for (int ips=0; ips<Uid.NUM_PROCESS_STATE; ips++) {
3760 long time = u.getProcessStateTime(ips, rawRealtime, which);
3761 if (time > 0) {
3762 totalStateTime += time;
3763 sb.setLength(0);
3764 sb.append(prefix);
3765 sb.append(" ");
3766 sb.append(Uid.PROCESS_STATE_NAMES[ips]);
3767 sb.append(" for: ");
3768 formatTimeMs(sb, (totalStateTime + 500) / 1000);
3769 pw.println(sb.toString());
3770 uidActivity = true;
3771 }
3772 }
3773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
3775 if (processStats.size() > 0) {
3776 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
3777 : processStats.entrySet()) {
3778 Uid.Proc ps = ent.getValue();
3779 long userTime;
3780 long systemTime;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003781 long foregroundTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003782 int starts;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003783 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003784
3785 userTime = ps.getUserTime(which);
3786 systemTime = ps.getSystemTime(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003787 foregroundTime = ps.getForegroundTime(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003788 starts = ps.getStarts(which);
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003789 final int numCrashes = ps.getNumCrashes(which);
3790 final int numAnrs = ps.getNumAnrs(which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003791 numExcessive = which == STATS_SINCE_CHARGED
Dianne Hackborn287952c2010-09-22 22:34:31 -07003792 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003793
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003794 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003795 || numExcessive != 0 || numCrashes != 0 || numAnrs != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003796 sb.setLength(0);
3797 sb.append(prefix); sb.append(" Proc ");
3798 sb.append(ent.getKey()); sb.append(":\n");
3799 sb.append(prefix); sb.append(" CPU: ");
Dianne Hackborn62793e42015-03-09 11:15:41 -07003800 formatTimeMs(sb, userTime); sb.append("usr + ");
3801 formatTimeMs(sb, systemTime); sb.append("krn ; ");
3802 formatTimeMs(sb, foregroundTime); sb.append("fg");
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003803 if (starts != 0 || numCrashes != 0 || numAnrs != 0) {
Dianne Hackbornb8071d792010-09-09 16:45:15 -07003804 sb.append("\n"); sb.append(prefix); sb.append(" ");
Dianne Hackborn1e01d162014-12-04 17:46:42 -08003805 boolean hasOne = false;
3806 if (starts != 0) {
3807 hasOne = true;
3808 sb.append(starts); sb.append(" starts");
3809 }
3810 if (numCrashes != 0) {
3811 if (hasOne) {
3812 sb.append(", ");
3813 }
3814 hasOne = true;
3815 sb.append(numCrashes); sb.append(" crashes");
3816 }
3817 if (numAnrs != 0) {
3818 if (hasOne) {
3819 sb.append(", ");
3820 }
3821 sb.append(numAnrs); sb.append(" anrs");
3822 }
Dianne Hackborn0d903a82010-09-07 23:51:03 -07003823 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003824 pw.println(sb.toString());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003825 for (int e=0; e<numExcessive; e++) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07003826 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003827 if (ew != null) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07003828 pw.print(prefix); pw.print(" * Killed for ");
3829 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
3830 pw.print("wake lock");
3831 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
3832 pw.print("cpu");
3833 } else {
3834 pw.print("unknown");
3835 }
3836 pw.print(" use: ");
Dianne Hackborn1ebccf52010-08-15 13:04:34 -07003837 TimeUtils.formatDuration(ew.usedTime, pw);
3838 pw.print(" over ");
3839 TimeUtils.formatDuration(ew.overTime, pw);
Robert Greenwalta029ea12013-09-25 16:38:12 -07003840 if (ew.overTime != 0) {
3841 pw.print(" (");
3842 pw.print((ew.usedTime*100)/ew.overTime);
3843 pw.println("%)");
3844 }
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07003845 }
3846 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 uidActivity = true;
3848 }
3849 }
3850 }
3851
3852 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
3853 if (packageStats.size() > 0) {
3854 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
3855 : packageStats.entrySet()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003856 pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003857 boolean apkActivity = false;
3858 Uid.Pkg ps = ent.getValue();
3859 int wakeups = ps.getWakeups(which);
3860 if (wakeups != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003861 pw.print(prefix); pw.print(" ");
3862 pw.print(wakeups); pw.println(" wakeup alarms");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003863 apkActivity = true;
3864 }
3865 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
3866 if (serviceStats.size() > 0) {
3867 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
3868 : serviceStats.entrySet()) {
3869 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
3870 long startTime = ss.getStartTime(batteryUptime, which);
3871 int starts = ss.getStarts(which);
3872 int launches = ss.getLaunches(which);
3873 if (startTime != 0 || starts != 0 || launches != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003874 sb.setLength(0);
3875 sb.append(prefix); sb.append(" Service ");
3876 sb.append(sent.getKey()); sb.append(":\n");
3877 sb.append(prefix); sb.append(" Created for: ");
3878 formatTimeMs(sb, startTime / 1000);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07003879 sb.append("uptime\n");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003880 sb.append(prefix); sb.append(" Starts: ");
3881 sb.append(starts);
3882 sb.append(", launches: "); sb.append(launches);
3883 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003884 apkActivity = true;
3885 }
3886 }
3887 }
3888 if (!apkActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003889 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003890 }
3891 uidActivity = true;
3892 }
3893 }
3894 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07003895 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896 }
3897 }
3898 }
3899
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003900 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003901 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003902 int diff = oldval ^ newval;
3903 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003904 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003905 for (int i=0; i<descriptions.length; i++) {
3906 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003907 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003908 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003909 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003910 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003911 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003912 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
3913 didWake = true;
3914 pw.print("=");
3915 if (longNames) {
3916 UserHandle.formatUid(pw, wakelockTag.uid);
3917 pw.print(":\"");
3918 pw.print(wakelockTag.string);
3919 pw.print("\"");
3920 } else {
3921 pw.print(wakelockTag.poolIdx);
3922 }
3923 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003924 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003925 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003926 pw.print("=");
3927 int val = (newval&bd.mask)>>bd.shift;
3928 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003929 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003930 } else {
3931 pw.print(val);
3932 }
3933 }
3934 }
3935 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003936 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07003937 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003938 if (longNames) {
3939 UserHandle.formatUid(pw, wakelockTag.uid);
3940 pw.print(":\"");
3941 pw.print(wakelockTag.string);
3942 pw.print("\"");
3943 } else {
3944 pw.print(wakelockTag.poolIdx);
3945 }
3946 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07003947 }
3948
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003949 public void prepareForDumpLocked() {
3950 }
3951
3952 public static class HistoryPrinter {
3953 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003954 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003955 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003956 int oldStatus = -1;
3957 int oldHealth = -1;
3958 int oldPlug = -1;
3959 int oldTemp = -1;
3960 int oldVolt = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003961 long lastTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003962
Dianne Hackborn3251b902014-06-20 14:40:53 -07003963 void reset() {
3964 oldState = oldState2 = 0;
3965 oldLevel = -1;
3966 oldStatus = -1;
3967 oldHealth = -1;
3968 oldPlug = -1;
3969 oldTemp = -1;
3970 oldVolt = -1;
3971 }
3972
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003973 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003974 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003975 if (!checkin) {
3976 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003977 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003978 pw.print(" (");
3979 pw.print(rec.numReadInts);
3980 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003981 } else {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07003982 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
3983 pw.print(HISTORY_DATA); pw.print(',');
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003984 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003985 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003986 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003987 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003988 }
3989 lastTime = rec.time;
3990 }
3991 if (rec.cmd == HistoryItem.CMD_START) {
3992 if (checkin) {
3993 pw.print(":");
3994 }
3995 pw.println("START");
Dianne Hackborn3251b902014-06-20 14:40:53 -07003996 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07003997 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
3998 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08003999 if (checkin) {
4000 pw.print(":");
4001 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004002 if (rec.cmd == HistoryItem.CMD_RESET) {
4003 pw.print("RESET:");
Dianne Hackborn3251b902014-06-20 14:40:53 -07004004 reset();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004005 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004006 pw.print("TIME:");
4007 if (checkin) {
4008 pw.println(rec.currentTime);
4009 } else {
4010 pw.print(" ");
4011 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4012 rec.currentTime).toString());
4013 }
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004014 } else if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
4015 if (checkin) {
4016 pw.print(":");
4017 }
4018 pw.println("SHUTDOWN");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004019 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
4020 if (checkin) {
4021 pw.print(":");
4022 }
4023 pw.println("*OVERFLOW*");
4024 } else {
4025 if (!checkin) {
4026 if (rec.batteryLevel < 10) pw.print("00");
4027 else if (rec.batteryLevel < 100) pw.print("0");
4028 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004029 if (verbose) {
4030 pw.print(" ");
4031 if (rec.states < 0) ;
4032 else if (rec.states < 0x10) pw.print("0000000");
4033 else if (rec.states < 0x100) pw.print("000000");
4034 else if (rec.states < 0x1000) pw.print("00000");
4035 else if (rec.states < 0x10000) pw.print("0000");
4036 else if (rec.states < 0x100000) pw.print("000");
4037 else if (rec.states < 0x1000000) pw.print("00");
4038 else if (rec.states < 0x10000000) pw.print("0");
4039 pw.print(Integer.toHexString(rec.states));
4040 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004041 } else {
4042 if (oldLevel != rec.batteryLevel) {
4043 oldLevel = rec.batteryLevel;
4044 pw.print(",Bl="); pw.print(rec.batteryLevel);
4045 }
4046 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004047 if (oldStatus != rec.batteryStatus) {
4048 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004049 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004050 switch (oldStatus) {
4051 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004052 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004053 break;
4054 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004055 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004056 break;
4057 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004058 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004059 break;
4060 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004061 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004062 break;
4063 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004064 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004065 break;
4066 default:
4067 pw.print(oldStatus);
4068 break;
4069 }
4070 }
4071 if (oldHealth != rec.batteryHealth) {
4072 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004073 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004074 switch (oldHealth) {
4075 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004076 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004077 break;
4078 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004079 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004080 break;
4081 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004082 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004083 break;
4084 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004085 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004086 break;
4087 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004088 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004089 break;
4090 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004091 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004092 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004093 case BatteryManager.BATTERY_HEALTH_COLD:
4094 pw.print(checkin ? "c" : "cold");
4095 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004096 default:
4097 pw.print(oldHealth);
4098 break;
4099 }
4100 }
4101 if (oldPlug != rec.batteryPlugType) {
4102 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004103 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004104 switch (oldPlug) {
4105 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004106 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004107 break;
4108 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004109 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004110 break;
4111 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004112 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004113 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004114 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004115 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07004116 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004117 default:
4118 pw.print(oldPlug);
4119 break;
4120 }
4121 }
4122 if (oldTemp != rec.batteryTemperature) {
4123 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004124 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004125 pw.print(oldTemp);
4126 }
4127 if (oldVolt != rec.batteryVoltage) {
4128 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004129 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004130 pw.print(oldVolt);
4131 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004132 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08004133 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07004134 printBitDescriptions(pw, oldState2, rec.states2, null,
4135 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004136 if (rec.wakeReasonTag != null) {
4137 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004138 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004139 pw.print(rec.wakeReasonTag.poolIdx);
4140 } else {
4141 pw.print(" wake_reason=");
4142 pw.print(rec.wakeReasonTag.uid);
4143 pw.print(":\"");
4144 pw.print(rec.wakeReasonTag.string);
4145 pw.print("\"");
4146 }
4147 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08004148 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004149 pw.print(checkin ? "," : " ");
4150 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
4151 pw.print("+");
4152 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
4153 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004154 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08004155 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
4156 : HISTORY_EVENT_NAMES;
4157 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
4158 | HistoryItem.EVENT_FLAG_FINISH);
4159 if (idx >= 0 && idx < eventNames.length) {
4160 pw.print(eventNames[idx]);
4161 } else {
4162 pw.print(checkin ? "Ev" : "event");
4163 pw.print(idx);
4164 }
4165 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004166 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004167 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08004168 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004169 UserHandle.formatUid(pw, rec.eventTag.uid);
4170 pw.print(":\"");
4171 pw.print(rec.eventTag.string);
4172 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08004173 }
4174 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004175 pw.println();
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004176 if (rec.stepDetails != null) {
4177 if (!checkin) {
4178 pw.print(" Details: cpu=");
4179 pw.print(rec.stepDetails.userTime);
4180 pw.print("u+");
4181 pw.print(rec.stepDetails.systemTime);
4182 pw.print("s");
4183 if (rec.stepDetails.appCpuUid1 >= 0) {
4184 pw.print(" (");
4185 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid1,
4186 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4187 if (rec.stepDetails.appCpuUid2 >= 0) {
4188 pw.print(", ");
4189 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid2,
4190 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4191 }
4192 if (rec.stepDetails.appCpuUid3 >= 0) {
4193 pw.print(", ");
4194 printStepCpuUidDetails(pw, rec.stepDetails.appCpuUid3,
4195 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4196 }
4197 pw.print(')');
4198 }
4199 pw.println();
4200 pw.print(" /proc/stat=");
4201 pw.print(rec.stepDetails.statUserTime);
4202 pw.print(" usr, ");
4203 pw.print(rec.stepDetails.statSystemTime);
4204 pw.print(" sys, ");
4205 pw.print(rec.stepDetails.statIOWaitTime);
4206 pw.print(" io, ");
4207 pw.print(rec.stepDetails.statIrqTime);
4208 pw.print(" irq, ");
4209 pw.print(rec.stepDetails.statSoftIrqTime);
4210 pw.print(" sirq, ");
4211 pw.print(rec.stepDetails.statIdlTime);
4212 pw.print(" idle");
4213 int totalRun = rec.stepDetails.statUserTime + rec.stepDetails.statSystemTime
4214 + rec.stepDetails.statIOWaitTime + rec.stepDetails.statIrqTime
4215 + rec.stepDetails.statSoftIrqTime;
4216 int total = totalRun + rec.stepDetails.statIdlTime;
4217 if (total > 0) {
4218 pw.print(" (");
4219 float perc = ((float)totalRun) / ((float)total) * 100;
4220 pw.print(String.format("%.1f%%", perc));
4221 pw.print(" of ");
4222 StringBuilder sb = new StringBuilder(64);
4223 formatTimeMsNoSpace(sb, total*10);
4224 pw.print(sb);
4225 pw.print(")");
4226 }
4227 pw.println();
4228 } else {
4229 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4230 pw.print(HISTORY_DATA); pw.print(",0,Dcpu=");
4231 pw.print(rec.stepDetails.userTime);
4232 pw.print(":");
4233 pw.print(rec.stepDetails.systemTime);
4234 if (rec.stepDetails.appCpuUid1 >= 0) {
4235 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid1,
4236 rec.stepDetails.appCpuUTime1, rec.stepDetails.appCpuSTime1);
4237 if (rec.stepDetails.appCpuUid2 >= 0) {
4238 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid2,
4239 rec.stepDetails.appCpuUTime2, rec.stepDetails.appCpuSTime2);
4240 }
4241 if (rec.stepDetails.appCpuUid3 >= 0) {
4242 printStepCpuUidCheckinDetails(pw, rec.stepDetails.appCpuUid3,
4243 rec.stepDetails.appCpuUTime3, rec.stepDetails.appCpuSTime3);
4244 }
4245 }
4246 pw.println();
4247 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4248 pw.print(HISTORY_DATA); pw.print(",0,Dpst=");
4249 pw.print(rec.stepDetails.statUserTime);
4250 pw.print(',');
4251 pw.print(rec.stepDetails.statSystemTime);
4252 pw.print(',');
4253 pw.print(rec.stepDetails.statIOWaitTime);
4254 pw.print(',');
4255 pw.print(rec.stepDetails.statIrqTime);
4256 pw.print(',');
4257 pw.print(rec.stepDetails.statSoftIrqTime);
4258 pw.print(',');
4259 pw.print(rec.stepDetails.statIdlTime);
4260 pw.println();
4261 }
4262 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004263 oldState = rec.states;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004264 oldState2 = rec.states2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004265 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004266 }
Dianne Hackbornd1eccbe2015-02-18 14:02:14 -08004267
4268 private void printStepCpuUidDetails(PrintWriter pw, int uid, int utime, int stime) {
4269 UserHandle.formatUid(pw, uid);
4270 pw.print("=");
4271 pw.print(utime);
4272 pw.print("u+");
4273 pw.print(stime);
4274 pw.print("s");
4275 }
4276
4277 private void printStepCpuUidCheckinDetails(PrintWriter pw, int uid, int utime, int stime) {
4278 pw.print('/');
4279 pw.print(uid);
4280 pw.print(":");
4281 pw.print(utime);
4282 pw.print(":");
4283 pw.print(stime);
4284 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004285 }
4286
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004287 private void printSizeValue(PrintWriter pw, long size) {
4288 float result = size;
4289 String suffix = "";
4290 if (result >= 10*1024) {
4291 suffix = "KB";
4292 result = result / 1024;
4293 }
4294 if (result >= 10*1024) {
4295 suffix = "MB";
4296 result = result / 1024;
4297 }
4298 if (result >= 10*1024) {
4299 suffix = "GB";
4300 result = result / 1024;
4301 }
4302 if (result >= 10*1024) {
4303 suffix = "TB";
4304 result = result / 1024;
4305 }
4306 if (result >= 10*1024) {
4307 suffix = "PB";
4308 result = result / 1024;
4309 }
4310 pw.print((int)result);
4311 pw.print(suffix);
4312 }
4313
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004314 private static boolean dumpTimeEstimate(PrintWriter pw, String label1, String label2,
4315 String label3, long estimatedTime) {
4316 if (estimatedTime < 0) {
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004317 return false;
4318 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004319 pw.print(label1);
4320 pw.print(label2);
4321 pw.print(label3);
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004322 StringBuilder sb = new StringBuilder(64);
4323 formatTimeMs(sb, estimatedTime);
4324 pw.print(sb);
4325 pw.println();
Dianne Hackbornad6a99b2014-11-18 10:11:10 -08004326 return true;
4327 }
4328
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004329 private static boolean dumpDurationSteps(PrintWriter pw, String prefix, String header,
4330 LevelStepTracker steps, boolean checkin) {
4331 if (steps == null) {
4332 return false;
4333 }
4334 int count = steps.mNumStepDurations;
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004335 if (count <= 0) {
4336 return false;
4337 }
4338 if (!checkin) {
4339 pw.println(header);
4340 }
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004341 String[] lineArgs = new String[4];
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004342 for (int i=0; i<count; i++) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004343 long duration = steps.getDurationAt(i);
4344 int level = steps.getLevelAt(i);
4345 long initMode = steps.getInitModeAt(i);
4346 long modMode = steps.getModModeAt(i);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004347 if (checkin) {
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004348 lineArgs[0] = Long.toString(duration);
4349 lineArgs[1] = Integer.toString(level);
4350 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4351 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4352 case Display.STATE_OFF: lineArgs[2] = "s-"; break;
4353 case Display.STATE_ON: lineArgs[2] = "s+"; break;
4354 case Display.STATE_DOZE: lineArgs[2] = "sd"; break;
4355 case Display.STATE_DOZE_SUSPEND: lineArgs[2] = "sds"; break;
4356 default: lineArgs[1] = "?"; break;
4357 }
4358 } else {
4359 lineArgs[2] = "";
4360 }
4361 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4362 lineArgs[3] = (initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0 ? "p+" : "p-";
4363 } else {
4364 lineArgs[3] = "";
4365 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004366 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
4367 } else {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004368 pw.print(prefix);
4369 pw.print("#"); pw.print(i); pw.print(": ");
Dianne Hackborn0068d3dc2014-08-06 19:20:25 -07004370 TimeUtils.formatDuration(duration, pw);
4371 pw.print(" to "); pw.print(level);
4372 boolean haveModes = false;
4373 if ((modMode&STEP_LEVEL_MODE_SCREEN_STATE) == 0) {
4374 pw.print(" (");
4375 switch ((int)(initMode&STEP_LEVEL_MODE_SCREEN_STATE) + 1) {
4376 case Display.STATE_OFF: pw.print("screen-off"); break;
4377 case Display.STATE_ON: pw.print("screen-on"); break;
4378 case Display.STATE_DOZE: pw.print("screen-doze"); break;
4379 case Display.STATE_DOZE_SUSPEND: pw.print("screen-doze-suspend"); break;
4380 default: lineArgs[1] = "screen-?"; break;
4381 }
4382 haveModes = true;
4383 }
4384 if ((modMode&STEP_LEVEL_MODE_POWER_SAVE) == 0) {
4385 pw.print(haveModes ? ", " : " (");
4386 pw.print((initMode&STEP_LEVEL_MODE_POWER_SAVE) != 0
4387 ? "power-save-on" : "power-save-off");
4388 haveModes = true;
4389 }
4390 if (haveModes) {
4391 pw.print(")");
4392 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004393 pw.println();
4394 }
4395 }
4396 return true;
4397 }
4398
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004399 public static final int DUMP_UNPLUGGED_ONLY = 1<<0;
4400 public static final int DUMP_CHARGED_ONLY = 1<<1;
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004401 public static final int DUMP_DAILY_ONLY = 1<<2;
4402 public static final int DUMP_HISTORY_ONLY = 1<<3;
4403 public static final int DUMP_INCLUDE_HISTORY = 1<<4;
4404 public static final int DUMP_VERBOSE = 1<<5;
4405 public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004406
Dianne Hackborn37de0982014-05-09 09:32:18 -07004407 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
4408 final HistoryPrinter hprinter = new HistoryPrinter();
4409 final HistoryItem rec = new HistoryItem();
4410 long lastTime = -1;
4411 long baseTime = -1;
4412 boolean printed = false;
4413 HistoryEventTracker tracker = null;
4414 while (getNextHistoryLocked(rec)) {
4415 lastTime = rec.time;
4416 if (baseTime < 0) {
4417 baseTime = lastTime;
4418 }
4419 if (rec.time >= histStart) {
4420 if (histStart >= 0 && !printed) {
4421 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
Ashish Sharma60200712014-05-23 18:22:20 -07004422 || rec.cmd == HistoryItem.CMD_RESET
Dianne Hackborn29cd7f12015-01-08 10:37:05 -08004423 || rec.cmd == HistoryItem.CMD_START
4424 || rec.cmd == HistoryItem.CMD_SHUTDOWN) {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004425 printed = true;
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004426 hprinter.printNextItem(pw, rec, baseTime, checkin,
4427 (flags&DUMP_VERBOSE) != 0);
4428 rec.cmd = HistoryItem.CMD_UPDATE;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004429 } else if (rec.currentTime != 0) {
4430 printed = true;
4431 byte cmd = rec.cmd;
4432 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004433 hprinter.printNextItem(pw, rec, baseTime, checkin,
4434 (flags&DUMP_VERBOSE) != 0);
4435 rec.cmd = cmd;
4436 }
4437 if (tracker != null) {
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004438 if (rec.cmd != HistoryItem.CMD_UPDATE) {
4439 hprinter.printNextItem(pw, rec, baseTime, checkin,
4440 (flags&DUMP_VERBOSE) != 0);
4441 rec.cmd = HistoryItem.CMD_UPDATE;
4442 }
4443 int oldEventCode = rec.eventCode;
4444 HistoryTag oldEventTag = rec.eventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004445 rec.eventTag = new HistoryTag();
4446 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
4447 HashMap<String, SparseIntArray> active
4448 = tracker.getStateForEvent(i);
4449 if (active == null) {
4450 continue;
4451 }
4452 for (HashMap.Entry<String, SparseIntArray> ent
4453 : active.entrySet()) {
4454 SparseIntArray uids = ent.getValue();
4455 for (int j=0; j<uids.size(); j++) {
4456 rec.eventCode = i;
4457 rec.eventTag.string = ent.getKey();
4458 rec.eventTag.uid = uids.keyAt(j);
4459 rec.eventTag.poolIdx = uids.valueAt(j);
Dianne Hackborn37de0982014-05-09 09:32:18 -07004460 hprinter.printNextItem(pw, rec, baseTime, checkin,
4461 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004462 rec.wakeReasonTag = null;
4463 rec.wakelockTag = null;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004464 }
4465 }
4466 }
Dianne Hackborncbefd8d2014-05-14 11:42:00 -07004467 rec.eventCode = oldEventCode;
4468 rec.eventTag = oldEventTag;
Dianne Hackborn37de0982014-05-09 09:32:18 -07004469 tracker = null;
4470 }
4471 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004472 hprinter.printNextItem(pw, rec, baseTime, checkin,
4473 (flags&DUMP_VERBOSE) != 0);
Dianne Hackborn536456f2014-05-23 16:51:05 -07004474 } else if (false && rec.eventCode != HistoryItem.EVENT_NONE) {
4475 // This is an attempt to aggregate the previous state and generate
4476 // fake events to reflect that state at the point where we start
4477 // printing real events. It doesn't really work right, so is turned off.
Dianne Hackborn37de0982014-05-09 09:32:18 -07004478 if (tracker == null) {
4479 tracker = new HistoryEventTracker();
4480 }
4481 tracker.updateState(rec.eventCode, rec.eventTag.string,
4482 rec.eventTag.uid, rec.eventTag.poolIdx);
4483 }
4484 }
4485 if (histStart >= 0) {
Dianne Hackbornfc064132014-06-02 12:42:12 -07004486 commitCurrentHistoryBatchLocked();
Dianne Hackborn37de0982014-05-09 09:32:18 -07004487 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
4488 }
4489 }
4490
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004491 private void dumpDailyLevelStepSummary(PrintWriter pw, String prefix, String label,
4492 LevelStepTracker steps, StringBuilder tmpSb, int[] tmpOutInt) {
4493 if (steps == null) {
4494 return;
4495 }
4496 long timeRemaining = steps.computeTimeEstimate(0, 0, tmpOutInt);
4497 if (timeRemaining >= 0) {
4498 pw.print(prefix); pw.print(label); pw.print(" total time: ");
4499 tmpSb.setLength(0);
4500 formatTimeMs(tmpSb, timeRemaining);
4501 pw.print(tmpSb);
4502 pw.print(" (from "); pw.print(tmpOutInt[0]);
4503 pw.println(" steps)");
4504 }
4505 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
4506 long estimatedTime = steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
4507 STEP_LEVEL_MODE_VALUES[i], tmpOutInt);
4508 if (estimatedTime > 0) {
4509 pw.print(prefix); pw.print(label); pw.print(" ");
4510 pw.print(STEP_LEVEL_MODE_LABELS[i]);
4511 pw.print(" time: ");
4512 tmpSb.setLength(0);
4513 formatTimeMs(tmpSb, estimatedTime);
4514 pw.print(tmpSb);
4515 pw.print(" (from "); pw.print(tmpOutInt[0]);
4516 pw.println(" steps)");
4517 }
4518 }
4519 }
4520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004521 /**
4522 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
4523 *
4524 * @param pw a Printer to receive the dump output.
4525 */
4526 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004527 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004528 prepareForDumpLocked();
4529
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004530 final boolean filtering = (flags
4531 & (DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004532
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004533 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004534 final long historyTotalSize = getHistoryTotalSize();
4535 final long historyUsedSize = getHistoryUsedSize();
4536 if (startIteratingHistoryLocked()) {
4537 try {
4538 pw.print("Battery History (");
4539 pw.print((100*historyUsedSize)/historyTotalSize);
4540 pw.print("% used, ");
4541 printSizeValue(pw, historyUsedSize);
4542 pw.print(" used of ");
4543 printSizeValue(pw, historyTotalSize);
4544 pw.print(", ");
4545 pw.print(getHistoryStringPoolSize());
4546 pw.print(" strings using ");
4547 printSizeValue(pw, getHistoryStringPoolBytes());
4548 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07004549 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004550 pw.println();
4551 } finally {
4552 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004553 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004554 }
4555
4556 if (startIteratingOldHistoryLocked()) {
4557 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07004558 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004559 pw.println("Old battery History:");
4560 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004561 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004562 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004563 if (baseTime < 0) {
4564 baseTime = rec.time;
4565 }
4566 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004567 }
4568 pw.println();
4569 } finally {
4570 finishIteratingOldHistoryLocked();
4571 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07004572 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004573 }
4574
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004575 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08004576 return;
4577 }
4578
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004579 if (!filtering) {
4580 SparseArray<? extends Uid> uidStats = getUidStats();
4581 final int NU = uidStats.size();
4582 boolean didPid = false;
4583 long nowRealtime = SystemClock.elapsedRealtime();
4584 for (int i=0; i<NU; i++) {
4585 Uid uid = uidStats.valueAt(i);
4586 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
4587 if (pids != null) {
4588 for (int j=0; j<pids.size(); j++) {
4589 Uid.Pid pid = pids.valueAt(j);
4590 if (!didPid) {
4591 pw.println("Per-PID Stats:");
4592 didPid = true;
4593 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08004594 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
4595 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004596 pw.print(" PID "); pw.print(pids.keyAt(j));
4597 pw.print(" wake time: ");
4598 TimeUtils.formatDuration(time, pw);
4599 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004600 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07004601 }
4602 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004603 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004604 pw.println();
4605 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004606 }
4607
4608 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004609 if (dumpDurationSteps(pw, " ", "Discharge step durations:",
4610 getDischargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004611 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
4612 if (timeRemaining >= 0) {
4613 pw.print(" Estimated discharge time remaining: ");
4614 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4615 pw.println();
4616 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004617 final LevelStepTracker steps = getDischargeLevelStepTracker();
4618 for (int i=0; i< STEP_LEVEL_MODES_OF_INTEREST.length; i++) {
4619 dumpTimeEstimate(pw, " Estimated ", STEP_LEVEL_MODE_LABELS[i], " time: ",
4620 steps.computeTimeEstimate(STEP_LEVEL_MODES_OF_INTEREST[i],
4621 STEP_LEVEL_MODE_VALUES[i], null));
4622 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004623 pw.println();
4624 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004625 if (dumpDurationSteps(pw, " ", "Charge step durations:",
4626 getChargeLevelStepTracker(), false)) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004627 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
4628 if (timeRemaining >= 0) {
4629 pw.print(" Estimated charge time remaining: ");
4630 TimeUtils.formatDuration(timeRemaining / 1000, pw);
4631 pw.println();
4632 }
4633 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004634 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004635 }
4636 if (!filtering || (flags&(DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0) {
4637 pw.println("Daily stats:");
4638 pw.print(" Current start time: ");
4639 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4640 getCurrentDailyStartTime()).toString());
4641 pw.print(" Next min deadline: ");
4642 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4643 getNextMinDailyDeadline()).toString());
4644 pw.print(" Next max deadline: ");
4645 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
4646 getNextMaxDailyDeadline()).toString());
4647 StringBuilder sb = new StringBuilder(64);
4648 int[] outInt = new int[1];
4649 LevelStepTracker dsteps = getDailyDischargeLevelStepTracker();
4650 LevelStepTracker csteps = getDailyChargeLevelStepTracker();
4651 if (dsteps.mNumStepDurations > 0 || csteps.mNumStepDurations > 0) {
4652 if ((flags&DUMP_DAILY_ONLY) != 0) {
4653 if (dumpDurationSteps(pw, " ", " Current daily discharge step durations:",
4654 dsteps, false)) {
4655 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
4656 sb, outInt);
4657 }
4658 if (dumpDurationSteps(pw, " ", " Current daily charge step durations:",
4659 csteps, false)) {
4660 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
4661 sb, outInt);
4662 }
4663 } else {
4664 pw.println(" Current daily steps:");
4665 dumpDailyLevelStepSummary(pw, " ", "Discharge", dsteps,
4666 sb, outInt);
4667 dumpDailyLevelStepSummary(pw, " ", "Charge", csteps,
4668 sb, outInt);
4669 }
4670 }
4671 DailyItem dit;
4672 int curIndex = 0;
4673 while ((dit=getDailyItemLocked(curIndex)) != null) {
4674 curIndex++;
4675 if ((flags&DUMP_DAILY_ONLY) != 0) {
4676 pw.println();
4677 }
4678 pw.print(" Daily from ");
4679 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mStartTime).toString());
4680 pw.print(" to ");
4681 pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", dit.mEndTime).toString());
4682 pw.println(":");
4683 if ((flags&DUMP_DAILY_ONLY) != 0) {
4684 if (dumpDurationSteps(pw, " ",
4685 " Discharge step durations:", dit.mDischargeSteps, false)) {
4686 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
4687 sb, outInt);
4688 }
4689 if (dumpDurationSteps(pw, " ",
4690 " Charge step durations:", dit.mChargeSteps, false)) {
4691 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
4692 sb, outInt);
4693 }
4694 } else {
4695 dumpDailyLevelStepSummary(pw, " ", "Discharge", dit.mDischargeSteps,
4696 sb, outInt);
4697 dumpDailyLevelStepSummary(pw, " ", "Charge", dit.mChargeSteps,
4698 sb, outInt);
4699 }
4700 }
4701 pw.println();
4702 }
4703 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004704 pw.println("Statistics since last charge:");
4705 pw.println(" System starts: " + getStartCount()
4706 + ", currently on battery: " + getIsOnBattery());
Dianne Hackbornd953c532014-08-16 18:17:38 -07004707 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid,
4708 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07004709 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07004710 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004711 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
4712 pw.println("Statistics since last unplugged:");
Dianne Hackbornd953c532014-08-16 18:17:38 -07004713 dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid,
4714 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004715 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004716 }
4717
4718 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004719 public void dumpCheckinLocked(Context context, PrintWriter pw,
4720 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07004721 prepareForDumpLocked();
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004722
4723 dumpLine(pw, 0 /* uid */, "i" /* category */, VERSION_DATA,
Dianne Hackborn0ee10f62015-01-14 16:16:13 -08004724 "12", getParcelVersion(), getStartPlatformVersion(), getEndPlatformVersion());
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004725
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004726 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
4727
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004728 final boolean filtering = (flags &
4729 (DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004730
4731 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07004732 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004733 try {
4734 for (int i=0; i<getHistoryStringPoolSize(); i++) {
4735 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
4736 pw.print(HISTORY_STRING_POOL); pw.print(',');
4737 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004738 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004739 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07004740 pw.print(",\"");
4741 String str = getHistoryTagPoolString(i);
4742 str = str.replace("\\", "\\\\");
4743 str = str.replace("\"", "\\\"");
4744 pw.print(str);
4745 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004746 pw.println();
4747 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07004748 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08004749 } finally {
4750 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08004751 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004752 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07004753 }
4754
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004755 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08004756 return;
4757 }
4758
Dianne Hackborne4a59512010-12-07 11:08:07 -08004759 if (apps != null) {
4760 SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
4761 for (int i=0; i<apps.size(); i++) {
4762 ApplicationInfo ai = apps.get(i);
4763 ArrayList<String> pkgs = uids.get(ai.uid);
4764 if (pkgs == null) {
4765 pkgs = new ArrayList<String>();
4766 uids.put(ai.uid, pkgs);
4767 }
4768 pkgs.add(ai.packageName);
4769 }
4770 SparseArray<? extends Uid> uidStats = getUidStats();
4771 final int NU = uidStats.size();
4772 String[] lineArgs = new String[2];
4773 for (int i=0; i<NU; i++) {
4774 int uid = uidStats.keyAt(i);
4775 ArrayList<String> pkgs = uids.get(uid);
4776 if (pkgs != null) {
4777 for (int j=0; j<pkgs.size(); j++) {
4778 lineArgs[0] = Integer.toString(uid);
4779 lineArgs[1] = pkgs.get(j);
4780 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
4781 (Object[])lineArgs);
4782 }
4783 }
4784 }
4785 }
Dianne Hackborncd0e3352014-08-07 17:08:09 -07004786 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004787 dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004788 String[] lineArgs = new String[1];
4789 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
4790 if (timeRemaining >= 0) {
4791 lineArgs[0] = Long.toString(timeRemaining);
4792 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
4793 (Object[])lineArgs);
4794 }
Dianne Hackbornd4a8af72015-03-03 10:06:15 -08004795 dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07004796 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
4797 if (timeRemaining >= 0) {
4798 lineArgs[0] = Long.toString(timeRemaining);
4799 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
4800 (Object[])lineArgs);
4801 }
Dianne Hackbornd953c532014-08-16 18:17:38 -07004802 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1,
4803 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08004804 }
4805 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
Dianne Hackbornd953c532014-08-16 18:17:38 -07004806 dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1,
4807 (flags&DUMP_DEVICE_WIFI_ONLY) != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004808 }
4809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004810}