blob: 4857533a133750053b5ae38949329ac28cbfa316 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.os;
18
19import java.io.PrintWriter;
Dianne Hackborne4a59512010-12-07 11:08:07 -080020import java.util.ArrayList;
Dianne Hackborn81038902012-11-26 17:04:09 -080021import java.util.Collections;
22import java.util.Comparator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import java.util.Formatter;
Dianne Hackborn37de0982014-05-09 09:32:18 -070024import java.util.HashMap;
Dianne Hackborne4a59512010-12-07 11:08:07 -080025import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import java.util.Map;
27
Dianne Hackborna7c837f2014-01-15 16:20:44 -080028import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080029import android.content.pm.ApplicationInfo;
Wink Saville52840902011-02-18 12:40:47 -080030import android.telephony.SignalStrength;
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -080031import android.text.format.DateFormat;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.util.Printer;
33import android.util.SparseArray;
Dianne Hackborn37de0982014-05-09 09:32:18 -070034import android.util.SparseBooleanArray;
35import android.util.SparseIntArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070036import android.util.TimeUtils;
Dianne Hackborna7c837f2014-01-15 16:20:44 -080037import com.android.internal.os.BatterySipper;
38import com.android.internal.os.BatteryStatsHelper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40/**
41 * A class providing access to battery usage statistics, including information on
42 * wakelocks, processes, packages, and services. All times are represented in microseconds
43 * except where indicated otherwise.
44 * @hide
45 */
46public abstract class BatteryStats implements Parcelable {
47
48 private static final boolean LOCAL_LOGV = false;
Dianne Hackborn91268cf2013-06-13 19:06:50 -070049
50 /** @hide */
51 public static final String SERVICE_NAME = "batterystats";
52
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053 /**
54 * A constant indicating a partial wake lock timer.
55 */
56 public static final int WAKE_TYPE_PARTIAL = 0;
57
58 /**
59 * A constant indicating a full wake lock timer.
60 */
61 public static final int WAKE_TYPE_FULL = 1;
62
63 /**
64 * A constant indicating a window wake lock timer.
65 */
66 public static final int WAKE_TYPE_WINDOW = 2;
67
68 /**
69 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 */
71 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070072
73 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070074 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070075 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070076 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070077
78 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070079 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070080 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070081 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070082
83 /**
Nick Pelly6ccaa542012-06-15 15:22:47 -070084 * A constant indicating a wifi scan
The Android Open Source Project10592532009-03-18 17:39:46 -070085 */
Nick Pelly6ccaa542012-06-15 15:22:47 -070086 public static final int WIFI_SCAN = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087
Robert Greenwalt5347bd42009-05-13 15:10:16 -070088 /**
89 * A constant indicating a wifi multicast timer
Robert Greenwalt5347bd42009-05-13 15:10:16 -070090 */
91 public static final int WIFI_MULTICAST_ENABLED = 7;
92
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070094 * A constant indicating an audio turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070095 */
96 public static final int AUDIO_TURNED_ON = 7;
97
98 /**
99 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700100 */
101 public static final int VIDEO_TURNED_ON = 8;
102
103 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800104 * A constant indicating a vibrator on timer
105 */
106 public static final int VIBRATOR_ON = 9;
107
108 /**
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700109 * A constant indicating a foreground activity timer
110 */
111 public static final int FOREGROUND_ACTIVITY = 10;
112
113 /**
Robert Greenwalta029ea12013-09-25 16:38:12 -0700114 * A constant indicating a wifi batched scan is active
115 */
116 public static final int WIFI_BATCHED_SCAN = 11;
117
118 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 * Include all of the data in the stats, including previously saved data.
120 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700121 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
123 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 * Include only the current run in the stats.
125 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700126 public static final int STATS_CURRENT = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127
128 /**
129 * Include only the run since the last time the device was unplugged in the stats.
130 */
Dianne Hackborn4590e522014-03-24 13:36:46 -0700131 public static final int STATS_SINCE_UNPLUGGED = 2;
Evan Millare84de8d2009-04-02 22:16:12 -0700132
133 // NOTE: Update this list if you add/change any stats above.
134 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700135 // and "unplugged". They were shortened for efficiency sake.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700136 private static final String[] STAT_NAMES = { "l", "c", "u" };
137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 /**
139 * Bump the version on this if the checkin format changes.
140 */
Ashish Sharmabffcf1c2014-05-08 17:11:28 -0700141 private static final int BATTERY_STATS_CHECKIN_VERSION = 8;
Evan Millar22ac0432009-03-31 11:33:18 -0700142
143 private static final long BYTES_PER_KB = 1024;
144 private static final long BYTES_PER_MB = 1048576; // 1024^2
145 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147
Dianne Hackborne4a59512010-12-07 11:08:07 -0800148 private static final String UID_DATA = "uid";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700150 private static final String PROCESS_DATA = "pr";
151 private static final String SENSOR_DATA = "sr";
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800152 private static final String VIBRATOR_DATA = "vib";
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700153 private static final String FOREGROUND_DATA = "fg";
Evan Millare84de8d2009-04-02 22:16:12 -0700154 private static final String WAKELOCK_DATA = "wl";
Evan Millarc64edde2009-04-18 12:26:32 -0700155 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700156 private static final String WAKEUP_REASON_DATA = "wr";
Evan Millare84de8d2009-04-02 22:16:12 -0700157 private static final String NETWORK_DATA = "nt";
158 private static final String USER_ACTIVITY_DATA = "ua";
159 private static final String BATTERY_DATA = "bt";
Dianne Hackbornc1b40e32011-01-05 18:27:40 -0800160 private static final String BATTERY_DISCHARGE_DATA = "dc";
Evan Millare84de8d2009-04-02 22:16:12 -0700161 private static final String BATTERY_LEVEL_DATA = "lv";
Nick Pelly6ccaa542012-06-15 15:22:47 -0700162 private static final String WIFI_DATA = "wfl";
Evan Millare84de8d2009-04-02 22:16:12 -0700163 private static final String MISC_DATA = "m";
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800164 private static final String GLOBAL_NETWORK_DATA = "gn";
Dianne Hackborn099bc622014-01-22 13:39:16 -0800165 private static final String HISTORY_STRING_POOL = "hsp";
Dianne Hackborn8a0de582013-08-07 15:22:07 -0700166 private static final String HISTORY_DATA = "h";
Evan Millare84de8d2009-04-02 22:16:12 -0700167 private static final String SCREEN_BRIGHTNESS_DATA = "br";
168 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700169 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700170 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
171 private static final String DATA_CONNECTION_TIME_DATA = "dct";
172 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800173 private static final String WIFI_STATE_TIME_DATA = "wst";
174 private static final String WIFI_STATE_COUNT_DATA = "wsc";
175 private static final String BLUETOOTH_STATE_TIME_DATA = "bst";
176 private static final String BLUETOOTH_STATE_COUNT_DATA = "bsc";
Dianne Hackborna7c837f2014-01-15 16:20:44 -0800177 private static final String POWER_USE_SUMMARY_DATA = "pws";
178 private static final String POWER_USE_ITEM_DATA = "pwi";
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -0700179 private static final String DISCHARGE_STEP_DATA = "dsd";
180 private static final String CHARGE_STEP_DATA = "csd";
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -0700181 private static final String DISCHARGE_TIME_REMAIN_DATA = "dtr";
182 private static final String CHARGE_TIME_REMAIN_DATA = "ctr";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700184 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 private final Formatter mFormatter = new Formatter(mFormatBuilder);
186
187 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700188 * State for keeping track of counting information.
189 */
190 public static abstract class Counter {
191
192 /**
193 * Returns the count associated with this Counter for the
194 * selected type of statistics.
195 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700196 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborn617f8772009-03-31 15:04:46 -0700197 */
Evan Millarc64edde2009-04-18 12:26:32 -0700198 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700199
200 /**
201 * Temporary for debugging.
202 */
203 public abstract void logState(Printer pw, String prefix);
204 }
205
206 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700207 * State for keeping track of long counting information.
208 */
209 public static abstract class LongCounter {
210
211 /**
212 * Returns the count associated with this Counter for the
213 * selected type of statistics.
214 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700215 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700216 */
217 public abstract long getCountLocked(int which);
218
219 /**
220 * Temporary for debugging.
221 */
222 public abstract void logState(Printer pw, String prefix);
223 }
224
225 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 * State for keeping track of timing information.
227 */
228 public static abstract class Timer {
229
230 /**
231 * Returns the count associated with this Timer for the
232 * selected type of statistics.
233 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700234 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 */
Evan Millarc64edde2009-04-18 12:26:32 -0700236 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237
238 /**
239 * Returns the total time in microseconds associated with this Timer for the
240 * selected type of statistics.
241 *
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800242 * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700243 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 * @return a time in microseconds
245 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800246 public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 /**
249 * Temporary for debugging.
250 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700251 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 }
253
254 /**
255 * The statistics associated with a particular uid.
256 */
257 public static abstract class Uid {
258
259 /**
260 * Returns a mapping containing wakelock statistics.
261 *
262 * @return a Map from Strings to Uid.Wakelock objects.
263 */
264 public abstract Map<String, ? extends Wakelock> getWakelockStats();
265
266 /**
267 * The statistics associated with a particular wake lock.
268 */
269 public static abstract class Wakelock {
270 public abstract Timer getWakeTime(int type);
271 }
272
273 /**
274 * Returns a mapping containing sensor statistics.
275 *
276 * @return a Map from Integer sensor ids to Uid.Sensor objects.
277 */
278 public abstract Map<Integer, ? extends Sensor> getSensorStats();
279
280 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700281 * Returns a mapping containing active process data.
282 */
283 public abstract SparseArray<? extends Pid> getPidStats();
284
285 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 * Returns a mapping containing process statistics.
287 *
288 * @return a Map from Strings to Uid.Proc objects.
289 */
290 public abstract Map<String, ? extends Proc> getProcessStats();
291
292 /**
293 * Returns a mapping containing package statistics.
294 *
295 * @return a Map from Strings to Uid.Pkg objects.
296 */
297 public abstract Map<String, ? extends Pkg> getPackageStats();
298
299 /**
300 * {@hide}
301 */
302 public abstract int getUid();
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700303
Dianne Hackbornca1bf212014-02-14 14:18:36 -0800304 public abstract void noteWifiRunningLocked(long elapsedRealtime);
305 public abstract void noteWifiStoppedLocked(long elapsedRealtime);
306 public abstract void noteFullWifiLockAcquiredLocked(long elapsedRealtime);
307 public abstract void noteFullWifiLockReleasedLocked(long elapsedRealtime);
308 public abstract void noteWifiScanStartedLocked(long elapsedRealtime);
309 public abstract void noteWifiScanStoppedLocked(long elapsedRealtime);
310 public abstract void noteWifiBatchedScanStartedLocked(int csph, long elapsedRealtime);
311 public abstract void noteWifiBatchedScanStoppedLocked(long elapsedRealtime);
312 public abstract void noteWifiMulticastEnabledLocked(long elapsedRealtime);
313 public abstract void noteWifiMulticastDisabledLocked(long elapsedRealtime);
314 public abstract void noteAudioTurnedOnLocked(long elapsedRealtime);
315 public abstract void noteAudioTurnedOffLocked(long elapsedRealtime);
316 public abstract void noteVideoTurnedOnLocked(long elapsedRealtime);
317 public abstract void noteVideoTurnedOffLocked(long elapsedRealtime);
318 public abstract void noteActivityResumedLocked(long elapsedRealtime);
319 public abstract void noteActivityPausedLocked(long elapsedRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800320 public abstract long getWifiRunningTime(long elapsedRealtimeUs, int which);
321 public abstract long getFullWifiLockTime(long elapsedRealtimeUs, int which);
322 public abstract long getWifiScanTime(long elapsedRealtimeUs, int which);
323 public abstract long getWifiBatchedScanTime(int csphBin, long elapsedRealtimeUs, int which);
324 public abstract long getWifiMulticastTime(long elapsedRealtimeUs, int which);
325 public abstract long getAudioTurnedOnTime(long elapsedRealtimeUs, int which);
326 public abstract long getVideoTurnedOnTime(long elapsedRealtimeUs, int which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -0700327 public abstract Timer getForegroundActivityTimer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800328 public abstract Timer getVibratorOnTimer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329
Robert Greenwalta029ea12013-09-25 16:38:12 -0700330 public static final int NUM_WIFI_BATCHED_SCAN_BINS = 5;
331
Dianne Hackborn617f8772009-03-31 15:04:46 -0700332 /**
Jeff Browndf693de2012-07-27 12:03:38 -0700333 * Note that these must match the constants in android.os.PowerManager.
334 * Also, if the user activity types change, the BatteryStatsImpl.VERSION must
335 * also be bumped.
Dianne Hackborn617f8772009-03-31 15:04:46 -0700336 */
337 static final String[] USER_ACTIVITY_TYPES = {
Jeff Browndf693de2012-07-27 12:03:38 -0700338 "other", "button", "touch"
Dianne Hackborn617f8772009-03-31 15:04:46 -0700339 };
340
Jeff Browndf693de2012-07-27 12:03:38 -0700341 public static final int NUM_USER_ACTIVITY_TYPES = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700342
Dianne Hackborn617f8772009-03-31 15:04:46 -0700343 public abstract void noteUserActivityLocked(int type);
344 public abstract boolean hasUserActivity();
345 public abstract int getUserActivityCount(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700346
347 public abstract boolean hasNetworkActivity();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800348 public abstract long getNetworkActivityBytes(int type, int which);
349 public abstract long getNetworkActivityPackets(int type, int which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -0800350 public abstract long getMobileRadioActiveTime(int which);
351 public abstract int getMobileRadioActiveCount(int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 public static abstract class Sensor {
Mathias Agopian7f84c062013-02-04 19:22:47 -0800354 /*
355 * FIXME: it's not correct to use this magic value because it
356 * could clash with a sensor handle (which are defined by
357 * the sensor HAL, and therefore out of our control
358 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 // Magic sensor number for the GPS.
360 public static final int GPS = -10000;
361
362 public abstract int getHandle();
363
364 public abstract Timer getSensorTime();
365 }
366
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700367 public class Pid {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800368 public int mWakeNesting;
369 public long mWakeSumMs;
370 public long mWakeStartMs;
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700371 }
372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 /**
374 * The statistics associated with a particular process.
375 */
376 public static abstract class Proc {
377
Dianne Hackborn287952c2010-09-22 22:34:31 -0700378 public static class ExcessivePower {
379 public static final int TYPE_WAKE = 1;
380 public static final int TYPE_CPU = 2;
381
382 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700383 public long overTime;
384 public long usedTime;
385 }
386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 /**
Dianne Hackborn099bc622014-01-22 13:39:16 -0800388 * Returns true if this process is still active in the battery stats.
389 */
390 public abstract boolean isActive();
391
392 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 * Returns the total time (in 1/100 sec) spent executing in user code.
394 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700395 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 */
397 public abstract long getUserTime(int which);
398
399 /**
400 * Returns the total time (in 1/100 sec) spent executing in system code.
401 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700402 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 */
404 public abstract long getSystemTime(int which);
405
406 /**
407 * Returns the number of times the process has been started.
408 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700409 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 */
411 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700412
413 /**
414 * Returns the cpu time spent in microseconds while the process was in the foreground.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700415 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700416 * @return foreground cpu time in microseconds
417 */
418 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700419
420 /**
421 * Returns the approximate cpu time spent in microseconds, at a certain CPU speed.
422 * @param speedStep the index of the CPU speed. This is not the actual speed of the
423 * CPU.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700424 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Amith Yamasanie43530a2009-08-21 13:11:37 -0700425 * @see BatteryStats#getCpuSpeedSteps()
426 */
427 public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700428
Dianne Hackborn287952c2010-09-22 22:34:31 -0700429 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700430
Dianne Hackborn287952c2010-09-22 22:34:31 -0700431 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 }
433
434 /**
435 * The statistics associated with a particular package.
436 */
437 public static abstract class Pkg {
438
439 /**
440 * Returns the number of times this package has done something that could wake up the
441 * device from sleep.
442 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700443 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 */
445 public abstract int getWakeups(int which);
446
447 /**
448 * Returns a mapping containing service statistics.
449 */
450 public abstract Map<String, ? extends Serv> getServiceStats();
451
452 /**
453 * The statistics associated with a particular service.
454 */
455 public abstract class Serv {
456
457 /**
458 * Returns the amount of time spent started.
459 *
460 * @param batteryUptime elapsed uptime on battery in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700461 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 * @return
463 */
464 public abstract long getStartTime(long batteryUptime, int which);
465
466 /**
467 * Returns the total number of times startService() has been called.
468 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700469 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 */
471 public abstract int getStarts(int which);
472
473 /**
474 * Returns the total number times the service has been launched.
475 *
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -0700476 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 */
478 public abstract int getLaunches(int which);
479 }
480 }
481 }
482
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800483 public final static class HistoryTag {
484 public String string;
485 public int uid;
486
487 public int poolIdx;
488
489 public void setTo(HistoryTag o) {
490 string = o.string;
491 uid = o.uid;
492 poolIdx = o.poolIdx;
493 }
494
495 public void setTo(String _string, int _uid) {
496 string = _string;
497 uid = _uid;
498 poolIdx = -1;
499 }
500
501 public void writeToParcel(Parcel dest, int flags) {
502 dest.writeString(string);
503 dest.writeInt(uid);
504 }
505
506 public void readFromParcel(Parcel src) {
507 string = src.readString();
508 uid = src.readInt();
509 poolIdx = -1;
510 }
511
512 @Override
513 public boolean equals(Object o) {
514 if (this == o) return true;
515 if (o == null || getClass() != o.getClass()) return false;
516
517 HistoryTag that = (HistoryTag) o;
518
519 if (uid != that.uid) return false;
520 if (!string.equals(that.string)) return false;
521
522 return true;
523 }
524
525 @Override
526 public int hashCode() {
527 int result = string.hashCode();
528 result = 31 * result + uid;
529 return result;
530 }
531 }
532
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700533 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700534 public HistoryItem next;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700535
536 public long time;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800537
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800538 public static final byte CMD_UPDATE = 0; // These can be written as deltas
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800539 public static final byte CMD_NULL = -1;
540 public static final byte CMD_START = 4;
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800541 public static final byte CMD_CURRENT_TIME = 5;
542 public static final byte CMD_OVERFLOW = 6;
Dianne Hackborn37de0982014-05-09 09:32:18 -0700543 public static final byte CMD_RESET = 7;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800544
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700545 public byte cmd = CMD_NULL;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700546
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800547 /**
548 * Return whether the command code is a delta data update.
549 */
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800550 public boolean isDeltaData() {
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800551 return cmd == CMD_UPDATE;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800552 }
553
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700554 public byte batteryLevel;
555 public byte batteryStatus;
556 public byte batteryHealth;
557 public byte batteryPlugType;
558
Sungmin Choic7e9e8b2013-01-16 12:57:36 +0900559 public short batteryTemperature;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700560 public char batteryVoltage;
561
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700562 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700563 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800564 public static final int STATE_BRIGHTNESS_MASK = 0x7;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700565 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800566 public static final int STATE_SIGNAL_STRENGTH_SHIFT = 3;
567 public static final int STATE_SIGNAL_STRENGTH_MASK = 0x7 << STATE_SIGNAL_STRENGTH_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700568 // Constants from ServiceState.STATE_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800569 public static final int STATE_PHONE_STATE_SHIFT = 6;
570 public static final int STATE_PHONE_STATE_MASK = 0x7 << STATE_PHONE_STATE_SHIFT;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700571 // Constants from DATA_CONNECTION_*
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800572 public static final int STATE_DATA_CONNECTION_SHIFT = 9;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800573 public static final int STATE_DATA_CONNECTION_MASK = 0x1f << STATE_DATA_CONNECTION_SHIFT;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800574
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700575 // These states always appear directly in the first int token
576 // of a delta change; they should be ones that change relatively
577 // frequently.
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700578 public static final int STATE_CPU_RUNNING_FLAG = 1<<31;
579 public static final int STATE_WAKE_LOCK_FLAG = 1<<30;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800580 public static final int STATE_GPS_ON_FLAG = 1<<29;
581 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<28;
Dianne Hackborne13c4c02014-02-11 17:18:35 -0800582 public static final int STATE_WIFI_SCAN_FLAG = 1<<27;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800583 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<26;
Dianne Hackborne13c4c02014-02-11 17:18:35 -0800584 public static final int STATE_MOBILE_RADIO_ACTIVE_FLAG = 1<<25;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800585 public static final int STATE_WIFI_RUNNING_FLAG = 1<<24;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700586 // These are on the lower bits used for the command; if they change
587 // we need to write another int of data.
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700588 public static final int STATE_SENSOR_ON_FLAG = 1<<23;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700589 public static final int STATE_AUDIO_ON_FLAG = 1<<22;
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700590 public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700591 public static final int STATE_SCREEN_ON_FLAG = 1<<20;
592 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19;
593 public static final int STATE_PHONE_IN_CALL_FLAG = 1<<18;
594 public static final int STATE_WIFI_ON_FLAG = 1<<17;
595 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<16;
Dianne Hackborn40c87252014-03-19 16:55:40 -0700596
Dianne Hackbornf47d8f22010-10-08 10:46:55 -0700597 public static final int MOST_INTERESTING_STATES =
598 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
599 | STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG;
600
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700601 public int states;
602
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700603 public static final int STATE2_VIDEO_ON_FLAG = 1<<0;
Dianne Hackborn40c87252014-03-19 16:55:40 -0700604 public int states2;
605
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800606 // The wake lock that was acquired at this point.
607 public HistoryTag wakelockTag;
608
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800609 // Kernel wakeup reason at this point.
610 public HistoryTag wakeReasonTag;
611
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800612 public static final int EVENT_FLAG_START = 0x8000;
613 public static final int EVENT_FLAG_FINISH = 0x4000;
614
615 // No event in this item.
616 public static final int EVENT_NONE = 0x0000;
617 // Event is about a process that is running.
618 public static final int EVENT_PROC = 0x0001;
619 // Event is about an application package that is in the foreground.
620 public static final int EVENT_FOREGROUND = 0x0002;
621 // Event is about an application package that is at the top of the screen.
622 public static final int EVENT_TOP = 0x0003;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -0800623 // Event is about an application package that is at the top of the screen.
624 public static final int EVENT_SYNC = 0x0004;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800625 // Number of event types.
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -0800626 public static final int EVENT_COUNT = 0x0005;
Dianne Hackborn37de0982014-05-09 09:32:18 -0700627 // Mask to extract out only the type part of the event.
628 public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
Dianne Hackborneaf2ac42014-02-07 13:01:07 -0800629
630 public static final int EVENT_PROC_START = EVENT_PROC | EVENT_FLAG_START;
631 public static final int EVENT_PROC_FINISH = EVENT_PROC | EVENT_FLAG_FINISH;
632 public static final int EVENT_FOREGROUND_START = EVENT_FOREGROUND | EVENT_FLAG_START;
633 public static final int EVENT_FOREGROUND_FINISH = EVENT_FOREGROUND | EVENT_FLAG_FINISH;
634 public static final int EVENT_TOP_START = EVENT_TOP | EVENT_FLAG_START;
635 public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -0800636 public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
637 public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800638
639 // For CMD_EVENT.
640 public int eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800641 public HistoryTag eventTag;
642
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800643 // Only set for CMD_CURRENT_TIME.
644 public long currentTime;
645
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800646 // Meta-data when reading.
647 public int numReadInts;
648
649 // Pre-allocated objects.
650 public final HistoryTag localWakelockTag = new HistoryTag();
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800651 public final HistoryTag localWakeReasonTag = new HistoryTag();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800652 public final HistoryTag localEventTag = new HistoryTag();
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800653
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700654 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700655 }
656
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700657 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700658 this.time = time;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800659 numReadInts = 2;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700660 readFromParcel(src);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700661 }
662
663 public int describeContents() {
664 return 0;
665 }
666
667 public void writeToParcel(Parcel dest, int flags) {
668 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700669 int bat = (((int)cmd)&0xff)
670 | ((((int)batteryLevel)<<8)&0xff00)
671 | ((((int)batteryStatus)<<16)&0xf0000)
672 | ((((int)batteryHealth)<<20)&0xf00000)
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800673 | ((((int)batteryPlugType)<<24)&0xf000000)
674 | (wakelockTag != null ? 0x10000000 : 0)
675 | (wakeReasonTag != null ? 0x20000000 : 0)
676 | (eventCode != EVENT_NONE ? 0x40000000 : 0);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700677 dest.writeInt(bat);
678 bat = (((int)batteryTemperature)&0xffff)
679 | ((((int)batteryVoltage)<<16)&0xffff0000);
680 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700681 dest.writeInt(states);
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700682 dest.writeInt(states2);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800683 if (wakelockTag != null) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800684 wakelockTag.writeToParcel(dest, flags);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800685 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800686 if (wakeReasonTag != null) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800687 wakeReasonTag.writeToParcel(dest, flags);
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800688 }
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800689 if (eventCode != EVENT_NONE) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800690 dest.writeInt(eventCode);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800691 eventTag.writeToParcel(dest, flags);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800692 }
Dianne Hackborn37de0982014-05-09 09:32:18 -0700693 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800694 dest.writeLong(currentTime);
695 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700696 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700697
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800698 public void readFromParcel(Parcel src) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800699 int start = src.dataPosition();
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700700 int bat = src.readInt();
701 cmd = (byte)(bat&0xff);
702 batteryLevel = (byte)((bat>>8)&0xff);
703 batteryStatus = (byte)((bat>>16)&0xf);
704 batteryHealth = (byte)((bat>>20)&0xf);
705 batteryPlugType = (byte)((bat>>24)&0xf);
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800706 int bat2 = src.readInt();
707 batteryTemperature = (short)(bat2&0xffff);
708 batteryVoltage = (char)((bat2>>16)&0xffff);
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700709 states = src.readInt();
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700710 states2 = src.readInt();
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800711 if ((bat&0x10000000) != 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800712 wakelockTag = localWakelockTag;
713 wakelockTag.readFromParcel(src);
714 } else {
715 wakelockTag = null;
716 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800717 if ((bat&0x20000000) != 0) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800718 wakeReasonTag = localWakeReasonTag;
719 wakeReasonTag.readFromParcel(src);
720 } else {
721 wakeReasonTag = null;
722 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800723 if ((bat&0x40000000) != 0) {
724 eventCode = src.readInt();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800725 eventTag = localEventTag;
726 eventTag.readFromParcel(src);
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800727 } else {
728 eventCode = EVENT_NONE;
729 eventTag = null;
730 }
Dianne Hackborn37de0982014-05-09 09:32:18 -0700731 if (cmd == CMD_CURRENT_TIME || cmd == CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800732 currentTime = src.readLong();
733 } else {
734 currentTime = 0;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700735 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800736 numReadInts += (src.dataPosition()-start)/4;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700737 }
738
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700739 public void clear() {
740 time = 0;
741 cmd = CMD_NULL;
742 batteryLevel = 0;
743 batteryStatus = 0;
744 batteryHealth = 0;
745 batteryPlugType = 0;
746 batteryTemperature = 0;
747 batteryVoltage = 0;
748 states = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700749 states2 = 0;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800750 wakelockTag = null;
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800751 wakeReasonTag = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800752 eventCode = EVENT_NONE;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800753 eventTag = null;
Dianne Hackborn1fadab52011-04-14 17:57:33 -0700754 }
755
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700756 public void setTo(HistoryItem o) {
757 time = o.time;
758 cmd = o.cmd;
Dianne Hackborn3d658bf2014-02-05 13:38:56 -0800759 setToCommon(o);
760 }
761
762 public void setTo(long time, byte cmd, HistoryItem o) {
763 this.time = time;
764 this.cmd = cmd;
765 setToCommon(o);
766 }
767
768 private void setToCommon(HistoryItem o) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700769 batteryLevel = o.batteryLevel;
770 batteryStatus = o.batteryStatus;
771 batteryHealth = o.batteryHealth;
772 batteryPlugType = o.batteryPlugType;
773 batteryTemperature = o.batteryTemperature;
774 batteryVoltage = o.batteryVoltage;
775 states = o.states;
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700776 states2 = o.states2;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800777 if (o.wakelockTag != null) {
778 wakelockTag = localWakelockTag;
779 wakelockTag.setTo(o.wakelockTag);
780 } else {
781 wakelockTag = null;
782 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800783 if (o.wakeReasonTag != null) {
784 wakeReasonTag = localWakeReasonTag;
785 wakeReasonTag.setTo(o.wakeReasonTag);
786 } else {
787 wakeReasonTag = null;
788 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800789 eventCode = o.eventCode;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800790 if (o.eventTag != null) {
791 eventTag = localEventTag;
792 eventTag.setTo(o.eventTag);
793 } else {
794 eventTag = null;
795 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800796 currentTime = o.currentTime;
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700797 }
798
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800799 public boolean sameNonEvent(HistoryItem o) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700800 return batteryLevel == o.batteryLevel
801 && batteryStatus == o.batteryStatus
802 && batteryHealth == o.batteryHealth
803 && batteryPlugType == o.batteryPlugType
804 && batteryTemperature == o.batteryTemperature
805 && batteryVoltage == o.batteryVoltage
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800806 && states == o.states
Dianne Hackborna1bd7922014-03-21 11:07:11 -0700807 && states2 == o.states2
Dianne Hackborne5167ca2014-03-08 14:39:10 -0800808 && currentTime == o.currentTime;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700809 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800810
811 public boolean same(HistoryItem o) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800812 if (!sameNonEvent(o) || eventCode != o.eventCode) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800813 return false;
814 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800815 if (wakelockTag != o.wakelockTag) {
816 if (wakelockTag == null || o.wakelockTag == null) {
817 return false;
818 }
819 if (!wakelockTag.equals(o.wakelockTag)) {
820 return false;
821 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800822 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -0800823 if (wakeReasonTag != o.wakeReasonTag) {
824 if (wakeReasonTag == null || o.wakeReasonTag == null) {
825 return false;
826 }
827 if (!wakeReasonTag.equals(o.wakeReasonTag)) {
828 return false;
829 }
830 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800831 if (eventTag != o.eventTag) {
832 if (eventTag == null || o.eventTag == null) {
833 return false;
834 }
835 if (!eventTag.equals(o.eventTag)) {
836 return false;
837 }
838 }
839 return true;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800840 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700841 }
Dianne Hackborn37de0982014-05-09 09:32:18 -0700842
843 public final static class HistoryEventTracker {
844 private final HashMap<String, SparseIntArray>[] mActiveEvents
845 = (HashMap<String, SparseIntArray>[]) new HashMap[HistoryItem.EVENT_COUNT];
846
847 public boolean updateState(int code, String name, int uid, int poolIdx) {
848 if ((code&HistoryItem.EVENT_FLAG_START) != 0) {
849 int idx = code&HistoryItem.EVENT_TYPE_MASK;
850 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
851 if (active == null) {
852 active = new HashMap<String, SparseIntArray>();
853 mActiveEvents[idx] = active;
854 }
855 SparseIntArray uids = active.get(name);
856 if (uids == null) {
857 uids = new SparseIntArray();
858 active.put(name, uids);
859 }
860 if (uids.indexOfKey(uid) >= 0) {
861 // Already set, nothing to do!
862 return false;
863 }
864 uids.put(uid, poolIdx);
865 } else if ((code&HistoryItem.EVENT_FLAG_FINISH) != 0) {
866 int idx = code&HistoryItem.EVENT_TYPE_MASK;
867 HashMap<String, SparseIntArray> active = mActiveEvents[idx];
868 if (active == null) {
869 // not currently active, nothing to do.
870 return false;
871 }
872 SparseIntArray uids = active.get(name);
873 if (uids == null) {
874 // not currently active, nothing to do.
875 return false;
876 }
877 idx = uids.indexOfKey(uid);
878 if (idx < 0) {
879 // not currently active, nothing to do.
880 return false;
881 }
882 uids.removeAt(idx);
883 if (uids.size() <= 0) {
884 active.remove(name);
885 }
886 }
887 return true;
888 }
889
890 public HashMap<String, SparseIntArray> getStateForEvent(int code) {
891 return mActiveEvents[code];
892 }
893 }
894
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700895 public static final class BitDescription {
896 public final int mask;
897 public final int shift;
898 public final String name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800899 public final String shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700900 public final String[] values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800901 public final String[] shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700902
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800903 public BitDescription(int mask, String name, String shortName) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700904 this.mask = mask;
905 this.shift = -1;
906 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800907 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700908 this.values = null;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800909 this.shortValues = null;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700910 }
911
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800912 public BitDescription(int mask, int shift, String name, String shortName,
913 String[] values, String[] shortValues) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700914 this.mask = mask;
915 this.shift = shift;
916 this.name = name;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800917 this.shortName = shortName;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700918 this.values = values;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800919 this.shortValues = shortValues;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700920 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700921 }
Dianne Hackborn37de0982014-05-09 09:32:18 -0700922
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800923 public abstract int getHistoryTotalSize();
924
925 public abstract int getHistoryUsedSize();
926
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700927 public abstract boolean startIteratingHistoryLocked();
928
Dianne Hackborn099bc622014-01-22 13:39:16 -0800929 public abstract int getHistoryStringPoolSize();
930
Dianne Hackborn71fc13e2014-02-03 10:50:53 -0800931 public abstract int getHistoryStringPoolBytes();
932
933 public abstract String getHistoryTagPoolString(int index);
934
935 public abstract int getHistoryTagPoolUid(int index);
Dianne Hackborn099bc622014-01-22 13:39:16 -0800936
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700937 public abstract boolean getNextHistoryLocked(HistoryItem out);
938
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700939 public abstract void finishIteratingHistoryLocked();
940
941 public abstract boolean startIteratingOldHistoryLocked();
942
943 public abstract boolean getNextOldHistoryLocked(HistoryItem out);
944
945 public abstract void finishIteratingOldHistoryLocked();
946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700948 * Return the base time offset for the battery history.
949 */
950 public abstract long getHistoryBaseTime();
951
952 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 * Returns the number of times the device has been started.
954 */
955 public abstract int getStartCount();
956
957 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700958 * 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 -0800959 * running on battery.
960 *
961 * {@hide}
962 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800963 public abstract long getScreenOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964
Dianne Hackborn77b987f2014-02-26 16:20:52 -0800965 /**
966 * Returns the number of times the screen was turned on.
967 *
968 * {@hide}
969 */
970 public abstract int getScreenOnCount(int which);
971
Jeff Browne95c3cd2014-05-02 16:59:26 -0700972 public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);
973
Dianne Hackborn617f8772009-03-31 15:04:46 -0700974 public static final int SCREEN_BRIGHTNESS_DARK = 0;
975 public static final int SCREEN_BRIGHTNESS_DIM = 1;
976 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
977 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
978 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
979
980 static final String[] SCREEN_BRIGHTNESS_NAMES = {
981 "dark", "dim", "medium", "light", "bright"
982 };
983
Dianne Hackborn57ed6a62013-12-09 18:15:56 -0800984 static final String[] SCREEN_BRIGHTNESS_SHORT_NAMES = {
985 "0", "1", "2", "3", "4"
986 };
987
Dianne Hackborn617f8772009-03-31 15:04:46 -0700988 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
989
990 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700991 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -0700992 * the given brightness
993 *
994 * {@hide}
995 */
996 public abstract long getScreenBrightnessTime(int brightnessBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -0800997 long elapsedRealtimeUs, int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001000 * 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 -08001001 * running on battery.
1002 *
1003 * {@hide}
1004 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001005 public abstract long getPhoneOnTime(long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001006
1007 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001008 * Returns the number of times a phone call was activated.
1009 *
1010 * {@hide}
1011 */
1012 public abstract int getPhoneOnCount(int which);
1013
1014 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001015 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001016 * the given signal strength.
1017 *
1018 * {@hide}
1019 */
1020 public abstract long getPhoneSignalStrengthTime(int strengthBin,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001021 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001022
Dianne Hackborn617f8772009-03-31 15:04:46 -07001023 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -07001024 * Returns the time in microseconds that the phone has been trying to
1025 * acquire a signal.
1026 *
1027 * {@hide}
1028 */
1029 public abstract long getPhoneSignalScanningTime(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001030 long elapsedRealtimeUs, int which);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001031
1032 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001033 * Returns the number of times the phone has entered the given signal strength.
1034 *
1035 * {@hide}
1036 */
1037 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
1038
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001039 /**
1040 * Returns the time in microseconds that the mobile network has been active
1041 * (in a high power state).
1042 *
1043 * {@hide}
1044 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001045 public abstract long getMobileRadioActiveTime(long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001046
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001047 /**
1048 * Returns the number of times that the mobile network has transitioned to the
1049 * active state.
1050 *
1051 * {@hide}
1052 */
1053 public abstract int getMobileRadioActiveCount(int which);
1054
1055 /**
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001056 * Returns the time in microseconds that is the difference between the mobile radio
1057 * time we saw based on the elapsed timestamp when going down vs. the given time stamp
1058 * from the radio.
1059 *
1060 * {@hide}
1061 */
1062 public abstract long getMobileRadioActiveAdjustedTime(int which);
1063
1064 /**
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001065 * Returns the time in microseconds that the mobile network has been active
1066 * (in a high power state) but not being able to blame on an app.
1067 *
1068 * {@hide}
1069 */
1070 public abstract long getMobileRadioActiveUnknownTime(int which);
1071
1072 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001073 * Return count of number of times radio was up that could not be blamed on apps.
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001074 *
1075 * {@hide}
1076 */
1077 public abstract int getMobileRadioActiveUnknownCount(int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001078
Dianne Hackborn627bba72009-03-24 22:32:56 -07001079 public static final int DATA_CONNECTION_NONE = 0;
1080 public static final int DATA_CONNECTION_GPRS = 1;
1081 public static final int DATA_CONNECTION_EDGE = 2;
1082 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001083 public static final int DATA_CONNECTION_CDMA = 4;
1084 public static final int DATA_CONNECTION_EVDO_0 = 5;
1085 public static final int DATA_CONNECTION_EVDO_A = 6;
1086 public static final int DATA_CONNECTION_1xRTT = 7;
1087 public static final int DATA_CONNECTION_HSDPA = 8;
1088 public static final int DATA_CONNECTION_HSUPA = 9;
1089 public static final int DATA_CONNECTION_HSPA = 10;
1090 public static final int DATA_CONNECTION_IDEN = 11;
1091 public static final int DATA_CONNECTION_EVDO_B = 12;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001092 public static final int DATA_CONNECTION_LTE = 13;
1093 public static final int DATA_CONNECTION_EHRPD = 14;
Patrick Tjinb71703c2013-11-06 09:27:03 -08001094 public static final int DATA_CONNECTION_HSPAP = 15;
1095 public static final int DATA_CONNECTION_OTHER = 16;
Robert Greenwalt962a9902010-11-02 11:10:25 -07001096
Dianne Hackborn627bba72009-03-24 22:32:56 -07001097 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001098 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
Robert Greenwalt962a9902010-11-02 11:10:25 -07001099 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "lte",
Patrick Tjinb71703c2013-11-06 09:27:03 -08001100 "ehrpd", "hspap", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -07001101 };
1102
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001103 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001104
1105 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001106 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -07001107 * the given data connection.
1108 *
1109 * {@hide}
1110 */
1111 public abstract long getPhoneDataConnectionTime(int dataType,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001112 long elapsedRealtimeUs, int which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -07001115 * Returns the number of times the phone has entered the given data
1116 * connection type.
1117 *
1118 * {@hide}
1119 */
1120 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001121
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001122 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
1123 = new BitDescription[] {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001124 new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001125 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
1126 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001127 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps", "g"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001128 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock", "Wl"),
1129 new BitDescription(HistoryItem.STATE_WIFI_SCAN_FLAG, "wifi_scan", "Ws"),
1130 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast", "Wm"),
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001131 new BitDescription(HistoryItem.STATE_MOBILE_RADIO_ACTIVE_FLAG, "mobile_radio", "Pr"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001132 new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running", "Wr"),
1133 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning", "Psc"),
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001134 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001135 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
1136 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
1137 new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call", "Pcl"),
1138 new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi", "W"),
1139 new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth", "b"),
1140 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
1141 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
1142 DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
1143 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
1144 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state", "Pst",
1145 new String[] {"in", "out", "emergency", "off"},
1146 new String[] {"in", "out", "em", "off"}),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001147 new BitDescription(HistoryItem.STATE_SIGNAL_STRENGTH_MASK,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001148 HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength", "Pss",
1149 SignalStrength.SIGNAL_STRENGTH_NAMES, new String[] {
1150 "0", "1", "2", "3", "4"
1151 }),
Dianne Hackborn3d658bf2014-02-05 13:38:56 -08001152 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
1153 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness", "Sb",
1154 SCREEN_BRIGHTNESS_NAMES, SCREEN_BRIGHTNESS_SHORT_NAMES),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001155 };
Dianne Hackborn617f8772009-03-31 15:04:46 -07001156
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001157 public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
1158 = new BitDescription[] {
1159 new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
1160 };
1161
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001162 public static final String[] HISTORY_EVENT_NAMES = new String[] {
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001163 "null", "proc", "fg", "top", "sync"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001164 };
1165
1166 public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
Dianne Hackborna1f1a3c2014-02-24 18:12:28 -08001167 "Enl", "Epr", "Efg", "Etp", "Esy"
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08001168 };
1169
Dianne Hackborn617f8772009-03-31 15:04:46 -07001170 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001171 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001172 * running on battery.
1173 *
1174 * {@hide}
1175 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001176 public abstract long getWifiOnTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001177
1178 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001179 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001180 * been in the running state while the device was running on battery.
1181 *
1182 * {@hide}
1183 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001184 public abstract long getGlobalWifiRunningTime(long elapsedRealtimeUs, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001185
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001186 public static final int WIFI_STATE_OFF = 0;
1187 public static final int WIFI_STATE_OFF_SCANNING = 1;
1188 public static final int WIFI_STATE_ON_NO_NETWORKS = 2;
1189 public static final int WIFI_STATE_ON_DISCONNECTED = 3;
1190 public static final int WIFI_STATE_ON_CONNECTED_STA = 4;
1191 public static final int WIFI_STATE_ON_CONNECTED_P2P = 5;
1192 public static final int WIFI_STATE_ON_CONNECTED_STA_P2P = 6;
1193 public static final int WIFI_STATE_SOFT_AP = 7;
1194
1195 static final String[] WIFI_STATE_NAMES = {
1196 "off", "scanning", "no_net", "disconn",
1197 "sta", "p2p", "sta_p2p", "soft_ap"
1198 };
1199
1200 public static final int NUM_WIFI_STATES = WIFI_STATE_SOFT_AP+1;
1201
1202 /**
1203 * Returns the time in microseconds that WiFi has been running in the given state.
1204 *
1205 * {@hide}
1206 */
1207 public abstract long getWifiStateTime(int wifiState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001208 long elapsedRealtimeUs, int which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001209
1210 /**
1211 * Returns the number of times that WiFi has entered the given state.
1212 *
1213 * {@hide}
1214 */
1215 public abstract int getWifiStateCount(int wifiState, int which);
1216
The Android Open Source Project10592532009-03-18 17:39:46 -07001217 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -07001218 * Returns the time in microseconds that bluetooth has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -07001219 * running on battery.
1220 *
1221 * {@hide}
1222 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001223 public abstract long getBluetoothOnTime(long elapsedRealtimeUs, int which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001224
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001225 public abstract int getBluetoothPingCount();
1226
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001227 public static final int BLUETOOTH_STATE_INACTIVE = 0;
1228 public static final int BLUETOOTH_STATE_LOW = 1;
1229 public static final int BLUETOOTH_STATE_MEDIUM = 2;
1230 public static final int BLUETOOTH_STATE_HIGH = 3;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001231
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001232 static final String[] BLUETOOTH_STATE_NAMES = {
1233 "inactive", "low", "med", "high"
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001234 };
1235
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001236 public static final int NUM_BLUETOOTH_STATES = BLUETOOTH_STATE_HIGH +1;
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001237
1238 /**
1239 * Returns the time in microseconds that Bluetooth has been running in the
1240 * given active state.
1241 *
1242 * {@hide}
1243 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001244 public abstract long getBluetoothStateTime(int bluetoothState,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001245 long elapsedRealtimeUs, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001246
1247 /**
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001248 * Returns the number of times that Bluetooth has entered the given active state.
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001249 *
1250 * {@hide}
1251 */
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001252 public abstract int getBluetoothStateCount(int bluetoothState, int which);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001253
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001254 public static final int NETWORK_MOBILE_RX_DATA = 0;
1255 public static final int NETWORK_MOBILE_TX_DATA = 1;
1256 public static final int NETWORK_WIFI_RX_DATA = 2;
1257 public static final int NETWORK_WIFI_TX_DATA = 3;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001258
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001259 public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001260
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001261 public abstract long getNetworkActivityBytes(int type, int which);
1262 public abstract long getNetworkActivityPackets(int type, int which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001263
The Android Open Source Project10592532009-03-18 17:39:46 -07001264 /**
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08001265 * Return the wall clock time when battery stats data collection started.
1266 */
1267 public abstract long getStartClockTime();
1268
1269 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 * Return whether we are currently running on battery.
1271 */
1272 public abstract boolean getIsOnBattery();
1273
1274 /**
1275 * Returns a SparseArray containing the statistics for each uid.
1276 */
1277 public abstract SparseArray<? extends Uid> getUidStats();
1278
1279 /**
1280 * Returns the current battery uptime in microseconds.
1281 *
1282 * @param curTime the amount of elapsed realtime in microseconds.
1283 */
1284 public abstract long getBatteryUptime(long curTime);
1285
1286 /**
1287 * Returns the current battery realtime in microseconds.
1288 *
1289 * @param curTime the amount of elapsed realtime in microseconds.
1290 */
1291 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001292
1293 /**
Evan Millar633a1742009-04-02 16:36:33 -07001294 * Returns the battery percentage level at the last time the device was unplugged from power, or
1295 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -07001296 */
Evan Millar633a1742009-04-02 16:36:33 -07001297 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -07001298
1299 /**
Evan Millar633a1742009-04-02 16:36:33 -07001300 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
1301 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -07001302 */
Evan Millar633a1742009-04-02 16:36:33 -07001303 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304
1305 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -07001306 * Get the amount the battery has discharged since the stats were
1307 * last reset after charging, as a lower-end approximation.
1308 */
1309 public abstract int getLowDischargeAmountSinceCharge();
1310
1311 /**
1312 * Get the amount the battery has discharged since the stats were
1313 * last reset after charging, as an upper-end approximation.
1314 */
1315 public abstract int getHighDischargeAmountSinceCharge();
1316
1317 /**
Dianne Hackborn40c87252014-03-19 16:55:40 -07001318 * Retrieve the discharge amount over the selected discharge period <var>which</var>.
1319 */
1320 public abstract int getDischargeAmount(int which);
1321
1322 /**
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08001323 * Get the amount the battery has discharged while the screen was on,
1324 * since the last time power was unplugged.
1325 */
1326 public abstract int getDischargeAmountScreenOn();
1327
1328 /**
1329 * Get the amount the battery has discharged while the screen was on,
1330 * since the last time the device was charged.
1331 */
1332 public abstract int getDischargeAmountScreenOnSinceCharge();
1333
1334 /**
1335 * Get the amount the battery has discharged while the screen was off,
1336 * since the last time power was unplugged.
1337 */
1338 public abstract int getDischargeAmountScreenOff();
1339
1340 /**
1341 * Get the amount the battery has discharged while the screen was off,
1342 * since the last time the device was charged.
1343 */
1344 public abstract int getDischargeAmountScreenOffSinceCharge();
1345
1346 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 * Returns the total, last, or current battery uptime in microseconds.
1348 *
1349 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001350 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001351 */
1352 public abstract long computeBatteryUptime(long curTime, int which);
1353
1354 /**
1355 * Returns the total, last, or current battery realtime in microseconds.
1356 *
1357 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001358 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 */
1360 public abstract long computeBatteryRealtime(long curTime, int which);
1361
1362 /**
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001363 * Returns the total, last, or current battery screen off uptime in microseconds.
1364 *
1365 * @param curTime the elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001366 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001367 */
1368 public abstract long computeBatteryScreenOffUptime(long curTime, int which);
1369
1370 /**
1371 * Returns the total, last, or current battery screen off realtime in microseconds.
1372 *
1373 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001374 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001375 */
1376 public abstract long computeBatteryScreenOffRealtime(long curTime, int which);
1377
1378 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 * Returns the total, last, or current uptime in microseconds.
1380 *
1381 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001382 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 */
1384 public abstract long computeUptime(long curTime, int which);
1385
1386 /**
1387 * Returns the total, last, or current realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001388 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 * @param curTime the current elapsed realtime in microseconds.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001390 * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001391 */
1392 public abstract long computeRealtime(long curTime, int which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001393
1394 /**
1395 * Compute an approximation for how much run time (in microseconds) is remaining on
1396 * the battery. Returns -1 if no time can be computed: either there is not
1397 * enough current data to make a decision, or the battery is currently
1398 * charging.
1399 *
1400 * @param curTime The current elepsed realtime in microseconds.
1401 */
1402 public abstract long computeBatteryTimeRemaining(long curTime);
1403
1404 /**
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07001405 * Return the historical number of discharge steps we currently have.
1406 */
1407 public abstract int getNumDischargeStepDurations();
1408
1409 /**
1410 * Return the array of discharge step durations; the number of valid
1411 * items in it is returned by {@link #getNumDischargeStepDurations()}.
1412 * These values are in milliseconds.
1413 */
1414 public abstract long[] getDischargeStepDurationsArray();
1415
1416 /**
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001417 * Compute an approximation for how much time (in microseconds) remains until the battery
1418 * is fully charged. Returns -1 if no time can be computed: either there is not
1419 * enough current data to make a decision, or the battery is currently
1420 * discharging.
1421 *
1422 * @param curTime The current elepsed realtime in microseconds.
1423 */
1424 public abstract long computeChargeTimeRemaining(long curTime);
1425
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07001426 /**
1427 * Return the historical number of charge steps we currently have.
1428 */
1429 public abstract int getNumChargeStepDurations();
1430
1431 /**
1432 * Return the array of charge step durations; the number of valid
1433 * items in it is returned by {@link #getNumChargeStepDurations()}.
1434 * These values are in milliseconds.
1435 */
1436 public abstract long[] getChargeStepDurationsArray();
1437
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001438 public abstract Map<String, ? extends LongCounter> getWakeupReasonStats();
1439
Evan Millarc64edde2009-04-18 12:26:32 -07001440 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001441
Amith Yamasanie43530a2009-08-21 13:11:37 -07001442 /** Returns the number of different speeds that the CPU can run at */
1443 public abstract int getCpuSpeedSteps();
1444
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001445 public abstract void writeToParcelWithoutUids(Parcel out, int flags);
1446
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001447 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 long days = seconds / (60 * 60 * 24);
1449 if (days != 0) {
1450 out.append(days);
1451 out.append("d ");
1452 }
1453 long used = days * 60 * 60 * 24;
1454
1455 long hours = (seconds - used) / (60 * 60);
1456 if (hours != 0 || used != 0) {
1457 out.append(hours);
1458 out.append("h ");
1459 }
1460 used += hours * 60 * 60;
1461
1462 long mins = (seconds-used) / 60;
1463 if (mins != 0 || used != 0) {
1464 out.append(mins);
1465 out.append("m ");
1466 }
1467 used += mins * 60;
1468
1469 if (seconds != 0 || used != 0) {
1470 out.append(seconds-used);
1471 out.append("s ");
1472 }
1473 }
1474
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001475 public final static void formatTime(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 long sec = time / 100;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001477 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 sb.append((time - (sec * 100)) * 10);
1479 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 }
1481
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001482 public final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001484 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 sb.append(time - (sec * 1000));
1486 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001487 }
1488
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001489 public final static void formatTimeMsNoSpace(StringBuilder sb, long time) {
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001490 long sec = time / 1000;
1491 formatTimeRaw(sb, sec);
1492 sb.append(time - (sec * 1000));
1493 sb.append("ms");
1494 }
1495
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001496 public final String formatRatioLocked(long num, long den) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 if (den == 0L) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001498 return "--%";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 }
1500 float perc = ((float)num) / ((float)den) * 100;
1501 mFormatBuilder.setLength(0);
1502 mFormatter.format("%.1f%%", perc);
1503 return mFormatBuilder.toString();
1504 }
1505
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001506 final String formatBytesLocked(long bytes) {
Evan Millar22ac0432009-03-31 11:33:18 -07001507 mFormatBuilder.setLength(0);
1508
1509 if (bytes < BYTES_PER_KB) {
1510 return bytes + "B";
1511 } else if (bytes < BYTES_PER_MB) {
1512 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
1513 return mFormatBuilder.toString();
1514 } else if (bytes < BYTES_PER_GB){
1515 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
1516 return mFormatBuilder.toString();
1517 } else {
1518 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
1519 return mFormatBuilder.toString();
1520 }
1521 }
1522
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001523 private static long computeWakeLock(Timer timer, long elapsedRealtimeUs, int which) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07001524 if (timer != null) {
1525 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001526 long totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07001527 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
1528 return totalTimeMillis;
1529 }
1530 return 0;
1531 }
1532
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 /**
1534 *
1535 * @param sb a StringBuilder object.
1536 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001537 * @param elapsedRealtimeUs the current on-battery time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001539 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 * @param linePrefix a String to be prepended to each line of output.
1541 * @return the line prefix
1542 */
1543 private static final String printWakeLock(StringBuilder sb, Timer timer,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001544 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001545
1546 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001547 long totalTimeMillis = computeWakeLock(timer, elapsedRealtimeUs, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548
Evan Millarc64edde2009-04-18 12:26:32 -07001549 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 if (totalTimeMillis != 0) {
1551 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001552 formatTimeMs(sb, totalTimeMillis);
Dianne Hackborn81038902012-11-26 17:04:09 -08001553 if (name != null) {
1554 sb.append(name);
1555 sb.append(' ');
1556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 sb.append('(');
1558 sb.append(count);
1559 sb.append(" times)");
1560 return ", ";
1561 }
1562 }
1563 return linePrefix;
1564 }
1565
1566 /**
1567 * Checkin version of wakelock printer. Prints simple comma-separated list.
1568 *
1569 * @param sb a StringBuilder object.
1570 * @param timer a Timer object contining the wakelock times.
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001571 * @param elapsedRealtimeUs the current time in microseconds.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001572 * @param name the name of the wakelock.
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001573 * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 * @param linePrefix a String to be prepended to each line of output.
1575 * @return the line prefix
1576 */
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001577 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer,
1578 long elapsedRealtimeUs, String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 long totalTimeMicros = 0;
1580 int count = 0;
1581 if (timer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001582 totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
Evan Millarc64edde2009-04-18 12:26:32 -07001583 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 }
1585 sb.append(linePrefix);
1586 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
1587 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -07001588 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 sb.append(count);
1590 return ",";
1591 }
1592
1593 /**
1594 * Dump a comma-separated line of values for terse checkin mode.
1595 *
1596 * @param pw the PageWriter to dump log to
1597 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
1598 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
1599 * @param args type-dependent data arguments
1600 */
1601 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
1602 Object... args ) {
1603 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
1604 pw.print(uid); pw.print(',');
1605 pw.print(category); pw.print(',');
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001606 pw.print(type);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607
1608 for (Object arg : args) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001609 pw.print(',');
1610 pw.print(arg);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001612 pw.println();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 }
1614
1615 /**
1616 * Checkin server version of dump to produce more compact, computer-readable log.
1617 *
1618 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 */
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001620 public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 final long rawUptime = SystemClock.uptimeMillis() * 1000;
1622 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
1623 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
1625 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001626 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
1627 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
1628 which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 final long totalRealtime = computeRealtime(rawRealtime, which);
1630 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001631 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07001632 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001633 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
1634 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
1635 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
1636 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637
1638 StringBuilder sb = new StringBuilder(128);
1639
Evan Millar22ac0432009-03-31 11:33:18 -07001640 SparseArray<? extends Uid> uidStats = getUidStats();
1641 final int NU = uidStats.size();
1642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 String category = STAT_NAMES[which];
Jeff Sharkey3e013e82013-04-25 14:48:19 -07001644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 // Dump "battery" stat
1646 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001647 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07001648 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08001649 totalRealtime / 1000, totalUptime / 1000,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001650 getStartClockTime(),
1651 whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001653 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07001654 long fullWakeLockTimeTotal = 0;
1655 long partialWakeLockTimeTotal = 0;
1656
1657 for (int iu = 0; iu < NU; iu++) {
1658 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001659
Evan Millar22ac0432009-03-31 11:33:18 -07001660 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1661 if (wakelocks.size() > 0) {
1662 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1663 : wakelocks.entrySet()) {
1664 Uid.Wakelock wl = ent.getValue();
1665
1666 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
1667 if (fullWakeTimer != null) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001668 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime,
1669 which);
Evan Millar22ac0432009-03-31 11:33:18 -07001670 }
1671
1672 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
1673 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001674 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001675 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07001676 }
1677 }
1678 }
1679 }
1680
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001681 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
1682 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
1683 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
1684 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
1685 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
1686 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
1687 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
1688 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
1689
1690 // Dump network stats
1691 dumpLine(pw, 0 /* uid */, category, GLOBAL_NETWORK_DATA,
1692 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
1693 mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets);
1694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 // Dump misc stats
1696 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001697 screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000,
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001698 wifiRunningTime / 1000, bluetoothOnTime / 1000,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001699 mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
Dianne Hackborn617f8772009-03-31 15:04:46 -07001700 fullWakeLockTimeTotal, partialWakeLockTimeTotal,
Jeff Browne95c3cd2014-05-02 16:59:26 -07001701 0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which),
1702 getMobileRadioActiveAdjustedTime(which), interactiveTime / 1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001703
1704 // Dump screen brightness stats
1705 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
1706 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001707 args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
Dianne Hackborn617f8772009-03-31 15:04:46 -07001708 }
1709 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07001710
Dianne Hackborn627bba72009-03-24 22:32:56 -07001711 // Dump signal strength stats
Wink Saville52840902011-02-18 12:40:47 -08001712 args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
1713 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001714 args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001715 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001716 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001717 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001718 getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Wink Saville52840902011-02-18 12:40:47 -08001719 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07001720 args[i] = getPhoneSignalStrengthCount(i, which);
1721 }
1722 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001723
Dianne Hackborn627bba72009-03-24 22:32:56 -07001724 // Dump network type stats
1725 args = new Object[NUM_DATA_CONNECTION_TYPES];
1726 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001727 args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001728 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001729 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
1730 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1731 args[i] = getPhoneDataConnectionCount(i, which);
1732 }
1733 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001734
1735 // Dump wifi state stats
1736 args = new Object[NUM_WIFI_STATES];
1737 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001738 args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001739 }
1740 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_TIME_DATA, args);
1741 for (int i=0; i<NUM_WIFI_STATES; i++) {
1742 args[i] = getWifiStateCount(i, which);
1743 }
1744 dumpLine(pw, 0 /* uid */, category, WIFI_STATE_COUNT_DATA, args);
1745
1746 // Dump bluetooth state stats
1747 args = new Object[NUM_BLUETOOTH_STATES];
1748 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001749 args[i] = getBluetoothStateTime(i, rawRealtime, which) / 1000;
Dianne Hackbornca1bf212014-02-14 14:18:36 -08001750 }
1751 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_TIME_DATA, args);
1752 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
1753 args[i] = getBluetoothStateCount(i, which);
1754 }
1755 dumpLine(pw, 0 /* uid */, category, BLUETOOTH_STATE_COUNT_DATA, args);
1756
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001757 if (which == STATS_SINCE_UNPLUGGED) {
Dianne Hackborne13c4c02014-02-11 17:18:35 -08001758 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07001759 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07001760 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001761
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08001762 if (which == STATS_SINCE_UNPLUGGED) {
1763 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
1764 getDischargeStartLevel()-getDischargeCurrentLevel(),
1765 getDischargeStartLevel()-getDischargeCurrentLevel(),
1766 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
1767 } else {
1768 dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
1769 getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
1770 getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
1771 }
1772
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001773 if (reqUid < 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001774 Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001775 if (kernelWakelocks.size() > 0) {
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001776 for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001777 sb.setLength(0);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001778 printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001779 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001780 sb.toString());
1781 }
Evan Millarc64edde2009-04-18 12:26:32 -07001782 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07001783 Map<String, ? extends LongCounter> wakeupReasons = getWakeupReasonStats();
1784 if (wakeupReasons.size() > 0) {
1785 for (Map.Entry<String, ? extends LongCounter> ent : wakeupReasons.entrySet()) {
1786 dumpLine(pw, 0 /* uid */, category, WAKEUP_REASON_DATA,
1787 "\"" + ent.getKey() + "\"", ent.getValue().getCountLocked(which));
1788 }
1789 }
Evan Millarc64edde2009-04-18 12:26:32 -07001790 }
1791
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07001792 BatteryStatsHelper helper = new BatteryStatsHelper(context, false);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001793 helper.create(this);
1794 helper.refreshStats(which, UserHandle.USER_ALL);
1795 List<BatterySipper> sippers = helper.getUsageList();
1796 if (sippers != null && sippers.size() > 0) {
1797 dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA,
1798 BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()),
Dianne Hackborn099bc622014-01-22 13:39:16 -08001799 BatteryStatsHelper.makemAh(helper.getComputedPower()),
Dianne Hackborna7c837f2014-01-15 16:20:44 -08001800 BatteryStatsHelper.makemAh(helper.getMinDrainedPower()),
1801 BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
1802 for (int i=0; i<sippers.size(); i++) {
1803 BatterySipper bs = sippers.get(i);
1804 int uid = 0;
1805 String label;
1806 switch (bs.drainType) {
1807 case IDLE:
1808 label="idle";
1809 break;
1810 case CELL:
1811 label="cell";
1812 break;
1813 case PHONE:
1814 label="phone";
1815 break;
1816 case WIFI:
1817 label="wifi";
1818 break;
1819 case BLUETOOTH:
1820 label="blue";
1821 break;
1822 case SCREEN:
1823 label="scrn";
1824 break;
1825 case APP:
1826 uid = bs.uidObj.getUid();
1827 label = "uid";
1828 break;
1829 case USER:
1830 uid = UserHandle.getUid(bs.userId, 0);
1831 label = "user";
1832 break;
1833 case UNACCOUNTED:
1834 label = "unacc";
1835 break;
1836 case OVERCOUNTED:
1837 label = "over";
1838 break;
1839 default:
1840 label = "???";
1841 }
1842 dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
1843 BatteryStatsHelper.makemAh(bs.value));
1844 }
1845 }
1846
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001847 for (int iu = 0; iu < NU; iu++) {
1848 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001849 if (reqUid >= 0 && uid != reqUid) {
1850 continue;
1851 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 Uid u = uidStats.valueAt(iu);
1853 // Dump Network stats per uid, if any
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001854 long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
1855 long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
1856 long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
1857 long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
1858 long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
1859 long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001860 long mobileActiveTime = u.getMobileRadioActiveTime(which);
1861 int mobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001862 long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
1863 long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001864 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
1865 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
1866 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001867
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001868 if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0
1869 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001870 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08001871 dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx,
1872 wifiBytesRx, wifiBytesTx,
1873 mobilePacketsRx, mobilePacketsTx,
Dianne Hackbornd45665b2014-02-26 12:35:32 -08001874 wifiPacketsRx, wifiPacketsTx,
1875 mobileActiveTime, mobileActiveCount);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07001876 }
1877
Nick Pelly6ccaa542012-06-15 15:22:47 -07001878 if (fullWifiLockOnTime != 0 || wifiScanTime != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001879 || uidWifiRunningTime != 0) {
Nick Pelly6ccaa542012-06-15 15:22:47 -07001880 dumpLine(pw, uid, category, WIFI_DATA,
1881 fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883
Dianne Hackborn617f8772009-03-31 15:04:46 -07001884 if (u.hasUserActivity()) {
1885 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
1886 boolean hasData = false;
1887 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
1888 int val = u.getUserActivityCount(i, which);
1889 args[i] = val;
1890 if (val != 0) hasData = true;
1891 }
1892 if (hasData) {
1893 dumpLine(pw, 0 /* uid */, category, USER_ACTIVITY_DATA, args);
1894 }
1895 }
1896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1898 if (wakelocks.size() > 0) {
1899 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1900 : wakelocks.entrySet()) {
1901 Uid.Wakelock wl = ent.getValue();
1902 String linePrefix = "";
1903 sb.setLength(0);
Evan Millarc64edde2009-04-18 12:26:32 -07001904 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001905 rawRealtime, "f", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07001906 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001907 rawRealtime, "p", which, linePrefix);
Evan Millarc64edde2009-04-18 12:26:32 -07001908 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001909 rawRealtime, "w", which, linePrefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910
1911 // Only log if we had at lease one wakelock...
1912 if (sb.length() > 0) {
Dianne Hackborn13ac0412013-06-25 19:34:49 -07001913 String name = ent.getKey();
1914 if (name.indexOf(',') >= 0) {
1915 name = name.replace(',', '_');
1916 }
1917 dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001918 }
1919 }
1920 }
1921
1922 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
1923 if (sensors.size() > 0) {
1924 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
1925 : sensors.entrySet()) {
1926 Uid.Sensor se = ent.getValue();
1927 int sensorNumber = ent.getKey();
1928 Timer timer = se.getSensorTime();
1929 if (timer != null) {
1930 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001931 long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Evan Millarc64edde2009-04-18 12:26:32 -07001932 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001933 if (totalTime != 0) {
1934 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
1935 }
1936 }
1937 }
1938 }
1939
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001940 Timer vibTimer = u.getVibratorOnTimer();
1941 if (vibTimer != null) {
1942 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001943 long totalTime = (vibTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001944 int count = vibTimer.getCountLocked(which);
1945 if (totalTime != 0) {
1946 dumpLine(pw, uid, category, VIBRATOR_DATA, totalTime, count);
1947 }
1948 }
1949
Jeff Sharkey3e013e82013-04-25 14:48:19 -07001950 Timer fgTimer = u.getForegroundActivityTimer();
1951 if (fgTimer != null) {
1952 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08001953 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07001954 int count = fgTimer.getCountLocked(which);
1955 if (totalTime != 0) {
1956 dumpLine(pw, uid, category, FOREGROUND_DATA, totalTime, count);
1957 }
1958 }
1959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
1961 if (processStats.size() > 0) {
1962 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
1963 : processStats.entrySet()) {
1964 Uid.Proc ps = ent.getValue();
Jeff Sharkey3e013e82013-04-25 14:48:19 -07001965
1966 final long userMillis = ps.getUserTime(which) * 10;
1967 final long systemMillis = ps.getSystemTime(which) * 10;
1968 final long foregroundMillis = ps.getForegroundTime(which) * 10;
1969 final long starts = ps.getStarts(which);
1970
1971 if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0
1972 || starts != 0) {
1973 dumpLine(pw, uid, category, PROCESS_DATA, ent.getKey(), userMillis,
1974 systemMillis, foregroundMillis, starts);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001975 }
1976 }
1977 }
1978
1979 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
1980 if (packageStats.size() > 0) {
1981 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
1982 : packageStats.entrySet()) {
1983
1984 Uid.Pkg ps = ent.getValue();
1985 int wakeups = ps.getWakeups(which);
1986 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
1987 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
1988 : serviceStats.entrySet()) {
1989 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
1990 long startTime = ss.getStartTime(batteryUptime, which);
1991 int starts = ss.getStarts(which);
1992 int launches = ss.getLaunches(which);
1993 if (startTime != 0 || starts != 0 || launches != 0) {
1994 dumpLine(pw, uid, category, APK_DATA,
1995 wakeups, // wakeup alarms
1996 ent.getKey(), // Apk
1997 sent.getKey(), // service
1998 startTime / 1000, // time spent started, in ms
1999 starts,
2000 launches);
2001 }
2002 }
2003 }
2004 }
2005 }
2006 }
2007
Dianne Hackborn81038902012-11-26 17:04:09 -08002008 static final class TimerEntry {
2009 final String mName;
2010 final int mId;
2011 final BatteryStats.Timer mTimer;
2012 final long mTime;
2013 TimerEntry(String name, int id, BatteryStats.Timer timer, long time) {
2014 mName = name;
2015 mId = id;
2016 mTimer = timer;
2017 mTime = time;
2018 }
2019 }
2020
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002021 private void printmAh(PrintWriter printer, double power) {
2022 printer.print(BatteryStatsHelper.makemAh(power));
2023 }
2024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 @SuppressWarnings("unused")
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002026 public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
2027 int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002028 final long rawUptime = SystemClock.uptimeMillis() * 1000;
2029 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
2030 final long batteryUptime = getBatteryUptime(rawUptime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031
2032 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
2033 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
2034 final long totalRealtime = computeRealtime(rawRealtime, which);
2035 final long totalUptime = computeUptime(rawUptime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002036 final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
2037 final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime,
2038 which);
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002039 final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
2040 final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07002043
2044 SparseArray<? extends Uid> uidStats = getUidStats();
2045 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002046
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002047 sb.setLength(0);
2048 sb.append(prefix);
2049 sb.append(" Time on battery: ");
2050 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
2051 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
2052 sb.append(") realtime, ");
2053 formatTimeMs(sb, whichBatteryUptime / 1000);
2054 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
2055 sb.append(") uptime");
2056 pw.println(sb.toString());
2057 sb.setLength(0);
2058 sb.append(prefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002059 sb.append(" Time on battery screen off: ");
2060 formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
2061 sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
2062 sb.append(") realtime, ");
2063 formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
2064 sb.append("(");
2065 sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
2066 sb.append(") uptime");
2067 pw.println(sb.toString());
2068 sb.setLength(0);
2069 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002070 sb.append(" Total run time: ");
2071 formatTimeMs(sb, totalRealtime / 1000);
2072 sb.append("realtime, ");
2073 formatTimeMs(sb, totalUptime / 1000);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002074 sb.append("uptime");
Jeff Browne95c3cd2014-05-02 16:59:26 -07002075 pw.println(sb.toString());
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002076 if (batteryTimeRemaining >= 0) {
2077 sb.setLength(0);
2078 sb.append(prefix);
2079 sb.append(" Battery time remaining: ");
2080 formatTimeMs(sb, batteryTimeRemaining / 1000);
2081 pw.println(sb.toString());
2082 }
2083 if (chargeTimeRemaining >= 0) {
2084 sb.setLength(0);
2085 sb.append(prefix);
2086 sb.append(" Charge time remaining: ");
2087 formatTimeMs(sb, chargeTimeRemaining / 1000);
2088 pw.println(sb.toString());
2089 }
Dianne Hackborn5f4a5f92014-01-24 16:59:34 -08002090 pw.print(" Start clock time: ");
2091 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
2092
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002093 final long screenOnTime = getScreenOnTime(rawRealtime, which);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002094 final long interactiveTime = getInteractiveTime(rawRealtime, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002095 final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
2096 final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
2097 final long wifiOnTime = getWifiOnTime(rawRealtime, which);
2098 final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002099 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002100 sb.append(prefix);
Jeff Browne95c3cd2014-05-02 16:59:26 -07002101 sb.append(" Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
2102 sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
2103 sb.append(")");
2104 pw.println(sb.toString());
2105 sb.setLength(0);
2106 sb.append(prefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002107 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
2108 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002109 sb.append(") "); sb.append(getScreenOnCount(which));
Jeff Browne95c3cd2014-05-02 16:59:26 -07002110 sb.append("x, Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
2111 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
2112 sb.append(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002113 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002114 if (phoneOnTime != 0) {
2115 sb.setLength(0);
2116 sb.append(prefix);
2117 sb.append(" Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
2118 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
2119 sb.append(") "); sb.append(getPhoneOnCount(which));
2120 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002121 sb.setLength(0);
2122 sb.append(prefix);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002123 sb.append(" Screen brightnesses:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002124 boolean didOne = false;
2125 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002126 final long time = getScreenBrightnessTime(i, rawRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002127 if (time == 0) {
2128 continue;
2129 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002130 sb.append("\n ");
2131 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002132 didOne = true;
2133 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
2134 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002135 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07002136 sb.append("(");
2137 sb.append(formatRatioLocked(time, screenOnTime));
2138 sb.append(")");
2139 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002140 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002141 pw.println(sb.toString());
The Android Open Source Project10592532009-03-18 17:39:46 -07002142
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002143 // Calculate wakelock times across all uids.
Evan Millar22ac0432009-03-31 11:33:18 -07002144 long fullWakeLockTimeTotalMicros = 0;
2145 long partialWakeLockTimeTotalMicros = 0;
Dianne Hackborn81038902012-11-26 17:04:09 -08002146
Dianne Hackborn81038902012-11-26 17:04:09 -08002147 final ArrayList<TimerEntry> timers = new ArrayList<TimerEntry>();
2148
Evan Millar22ac0432009-03-31 11:33:18 -07002149 for (int iu = 0; iu < NU; iu++) {
2150 Uid u = uidStats.valueAt(iu);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002151
Evan Millar22ac0432009-03-31 11:33:18 -07002152 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
2153 if (wakelocks.size() > 0) {
2154 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
2155 : wakelocks.entrySet()) {
2156 Uid.Wakelock wl = ent.getValue();
2157
2158 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
2159 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07002160 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002161 rawRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07002162 }
2163
2164 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
2165 if (partialWakeTimer != null) {
Dianne Hackborn81038902012-11-26 17:04:09 -08002166 long totalTimeMicros = partialWakeTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002167 rawRealtime, which);
Dianne Hackborn81038902012-11-26 17:04:09 -08002168 if (totalTimeMicros > 0) {
2169 if (reqUid < 0) {
2170 // Only show the ordered list of all wake
2171 // locks if the caller is not asking for data
2172 // about a specific uid.
2173 timers.add(new TimerEntry(ent.getKey(), u.getUid(),
2174 partialWakeTimer, totalTimeMicros));
2175 }
2176 partialWakeLockTimeTotalMicros += totalTimeMicros;
2177 }
Evan Millar22ac0432009-03-31 11:33:18 -07002178 }
2179 }
2180 }
2181 }
2182
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002183 long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2184 long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2185 long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2186 long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2187 long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2188 long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
2189 long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2190 long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
2191
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002192 if (fullWakeLockTimeTotalMicros != 0) {
2193 sb.setLength(0);
2194 sb.append(prefix);
2195 sb.append(" Total full wakelock time: "); formatTimeMsNoSpace(sb,
2196 (fullWakeLockTimeTotalMicros + 500) / 1000);
2197 pw.println(sb.toString());
2198 }
2199
2200 if (partialWakeLockTimeTotalMicros != 0) {
2201 sb.setLength(0);
2202 sb.append(prefix);
2203 sb.append(" Total partial wakelock time: "); formatTimeMsNoSpace(sb,
2204 (partialWakeLockTimeTotalMicros + 500) / 1000);
2205 pw.println(sb.toString());
2206 }
2207
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002208 pw.print(prefix);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002209 pw.print(" Mobile total received: "); pw.print(formatBytesLocked(mobileRxTotalBytes));
2210 pw.print(", sent: "); pw.print(formatBytesLocked(mobileTxTotalBytes));
2211 pw.print(" (packets received "); pw.print(mobileRxTotalPackets);
2212 pw.print(", sent "); pw.print(mobileTxTotalPackets); pw.println(")");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002213 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002214 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002215 sb.append(" Signal levels:");
Dianne Hackborn617f8772009-03-31 15:04:46 -07002216 didOne = false;
Wink Saville52840902011-02-18 12:40:47 -08002217 for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002218 final long time = getPhoneSignalStrengthTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002219 if (time == 0) {
2220 continue;
2221 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002222 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002223 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002224 didOne = true;
Wink Saville52840902011-02-18 12:40:47 -08002225 sb.append(SignalStrength.SIGNAL_STRENGTH_NAMES[i]);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002226 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002227 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002228 sb.append("(");
2229 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002230 sb.append(") ");
2231 sb.append(getPhoneSignalStrengthCount(i, which));
2232 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002233 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002234 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002235 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07002236
2237 sb.setLength(0);
2238 sb.append(prefix);
2239 sb.append(" Signal scanning time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002240 formatTimeMsNoSpace(sb, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
Amith Yamasanif37447b2009-10-08 18:28:01 -07002241 pw.println(sb.toString());
2242
Dianne Hackborn627bba72009-03-24 22:32:56 -07002243 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002244 sb.append(prefix);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002245 sb.append(" Radio types:");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002246 didOne = false;
2247 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002248 final long time = getPhoneDataConnectionTime(i, rawRealtime, which);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002249 if (time == 0) {
2250 continue;
2251 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002252 sb.append("\n ");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002253 sb.append(prefix);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002254 didOne = true;
2255 sb.append(DATA_CONNECTION_NAMES[i]);
2256 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002257 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07002258 sb.append("(");
2259 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07002260 sb.append(") ");
2261 sb.append(getPhoneDataConnectionCount(i, which));
2262 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002263 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002264 if (!didOne) sb.append(" (no activity)");
Dianne Hackborn627bba72009-03-24 22:32:56 -07002265 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07002266
2267 sb.setLength(0);
2268 sb.append(prefix);
Dianne Hackborne13c4c02014-02-11 17:18:35 -08002269 sb.append(" Mobile radio active time: ");
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002270 final long mobileActiveTime = getMobileRadioActiveTime(rawRealtime, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002271 formatTimeMs(sb, mobileActiveTime / 1000);
2272 sb.append("("); sb.append(formatRatioLocked(mobileActiveTime, whichBatteryRealtime));
2273 sb.append(") "); sb.append(getMobileRadioActiveCount(which));
2274 sb.append("x");
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07002275 pw.println(sb.toString());
2276
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002277 final long mobileActiveUnknownTime = getMobileRadioActiveUnknownTime(which);
2278 if (mobileActiveUnknownTime != 0) {
2279 sb.setLength(0);
2280 sb.append(prefix);
2281 sb.append(" Mobile radio active unknown time: ");
2282 formatTimeMs(sb, mobileActiveUnknownTime / 1000);
2283 sb.append("(");
2284 sb.append(formatRatioLocked(mobileActiveUnknownTime, whichBatteryRealtime));
2285 sb.append(") "); sb.append(getMobileRadioActiveUnknownCount(which));
2286 sb.append("x");
2287 pw.println(sb.toString());
2288 }
2289
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002290 final long mobileActiveAdjustedTime = getMobileRadioActiveAdjustedTime(which);
2291 if (mobileActiveAdjustedTime != 0) {
2292 sb.setLength(0);
2293 sb.append(prefix);
2294 sb.append(" Mobile radio active adjusted time: ");
2295 formatTimeMs(sb, mobileActiveAdjustedTime / 1000);
2296 sb.append("(");
2297 sb.append(formatRatioLocked(mobileActiveAdjustedTime, whichBatteryRealtime));
2298 sb.append(")");
2299 pw.println(sb.toString());
2300 }
2301
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002302 pw.print(prefix);
2303 pw.print(" Wi-Fi total received: "); pw.print(formatBytesLocked(wifiRxTotalBytes));
2304 pw.print(", sent: "); pw.print(formatBytesLocked(wifiTxTotalBytes));
2305 pw.print(" (packets received "); pw.print(wifiRxTotalPackets);
2306 pw.print(", sent "); pw.print(wifiTxTotalPackets); pw.println(")");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002307 sb.setLength(0);
2308 sb.append(prefix);
2309 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
2310 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
2311 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
2312 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002313 sb.append(")");
2314 pw.println(sb.toString());
2315
2316 sb.setLength(0);
2317 sb.append(prefix);
2318 sb.append(" Wifi states:");
2319 didOne = false;
2320 for (int i=0; i<NUM_WIFI_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002321 final long time = getWifiStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002322 if (time == 0) {
2323 continue;
2324 }
2325 sb.append("\n ");
2326 didOne = true;
2327 sb.append(WIFI_STATE_NAMES[i]);
2328 sb.append(" ");
2329 formatTimeMs(sb, time/1000);
2330 sb.append("(");
2331 sb.append(formatRatioLocked(time, whichBatteryRealtime));
2332 sb.append(") ");
2333 sb.append(getPhoneDataConnectionCount(i, which));
2334 sb.append("x");
2335 }
2336 if (!didOne) sb.append(" (no activity)");
2337 pw.println(sb.toString());
2338
2339 sb.setLength(0);
2340 sb.append(prefix);
2341 sb.append(" Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002342 sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime));
2343 sb.append(")");
2344 pw.println(sb.toString());
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002345
2346 sb.setLength(0);
2347 sb.append(prefix);
2348 sb.append(" Bluetooth states:");
2349 didOne = false;
2350 for (int i=0; i<NUM_BLUETOOTH_STATES; i++) {
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002351 final long time = getBluetoothStateTime(i, rawRealtime, which);
Dianne Hackbornca1bf212014-02-14 14:18:36 -08002352 if (time == 0) {
2353 continue;
2354 }
2355 sb.append("\n ");
2356 didOne = true;
2357 sb.append(BLUETOOTH_STATE_NAMES[i]);
2358 sb.append(" ");
2359 formatTimeMs(sb, time/1000);
2360 sb.append("(");
2361 sb.append(formatRatioLocked(time, whichBatteryRealtime));
2362 sb.append(") ");
2363 sb.append(getPhoneDataConnectionCount(i, which));
2364 sb.append("x");
2365 }
2366 if (!didOne) sb.append(" (no activity)");
2367 pw.println(sb.toString());
2368
2369 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07002370
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002371 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07002372 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002373 pw.print(prefix); pw.println(" Device is currently unplugged");
2374 pw.print(prefix); pw.print(" Discharge cycle start level: ");
2375 pw.println(getDischargeStartLevel());
2376 pw.print(prefix); pw.print(" Discharge cycle current level: ");
2377 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07002378 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002379 pw.print(prefix); pw.println(" Device is currently plugged into power");
2380 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
2381 pw.println(getDischargeStartLevel());
2382 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
2383 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07002384 }
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002385 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
2386 pw.println(getDischargeAmountScreenOn());
2387 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
2388 pw.println(getDischargeAmountScreenOff());
Dianne Hackborn617f8772009-03-31 15:04:46 -07002389 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002390 } else {
2391 pw.print(prefix); pw.println(" Device battery use since last full charge");
2392 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
2393 pw.println(getLowDischargeAmountSinceCharge());
2394 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
2395 pw.println(getHighDischargeAmountSinceCharge());
Dianne Hackbornc1b40e32011-01-05 18:27:40 -08002396 pw.print(prefix); pw.print(" Amount discharged while screen on: ");
2397 pw.println(getDischargeAmountScreenOnSinceCharge());
2398 pw.print(prefix); pw.print(" Amount discharged while screen off: ");
2399 pw.println(getDischargeAmountScreenOffSinceCharge());
Dianne Hackborn81038902012-11-26 17:04:09 -08002400 pw.println();
The Android Open Source Project10592532009-03-18 17:39:46 -07002401 }
Dianne Hackborn81038902012-11-26 17:04:09 -08002402
Dianne Hackborn2ffa11e2014-04-21 15:56:18 -07002403 BatteryStatsHelper helper = new BatteryStatsHelper(context, false);
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002404 helper.create(this);
2405 helper.refreshStats(which, UserHandle.USER_ALL);
2406 List<BatterySipper> sippers = helper.getUsageList();
2407 if (sippers != null && sippers.size() > 0) {
2408 pw.print(prefix); pw.println(" Estimated power use (mAh):");
2409 pw.print(prefix); pw.print(" Capacity: ");
2410 printmAh(pw, helper.getPowerProfile().getBatteryCapacity());
Dianne Hackborn099bc622014-01-22 13:39:16 -08002411 pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower());
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002412 pw.print(", Min drain: "); printmAh(pw, helper.getMinDrainedPower());
2413 pw.print(", Max drain: "); printmAh(pw, helper.getMaxDrainedPower());
2414 pw.println();
2415 for (int i=0; i<sippers.size(); i++) {
2416 BatterySipper bs = sippers.get(i);
2417 switch (bs.drainType) {
2418 case IDLE:
2419 pw.print(prefix); pw.print(" Idle: "); printmAh(pw, bs.value);
2420 pw.println();
2421 break;
2422 case CELL:
2423 pw.print(prefix); pw.print(" Cell standby: "); printmAh(pw, bs.value);
2424 pw.println();
2425 break;
2426 case PHONE:
2427 pw.print(prefix); pw.print(" Phone calls: "); printmAh(pw, bs.value);
2428 pw.println();
2429 break;
2430 case WIFI:
2431 pw.print(prefix); pw.print(" Wifi: "); printmAh(pw, bs.value);
2432 pw.println();
2433 break;
2434 case BLUETOOTH:
2435 pw.print(prefix); pw.print(" Bluetooth: "); printmAh(pw, bs.value);
2436 pw.println();
2437 break;
2438 case SCREEN:
2439 pw.print(prefix); pw.print(" Screen: "); printmAh(pw, bs.value);
2440 pw.println();
2441 break;
2442 case APP:
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002443 pw.print(prefix); pw.print(" Uid ");
2444 UserHandle.formatUid(pw, bs.uidObj.getUid());
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002445 pw.print(": "); printmAh(pw, bs.value); pw.println();
2446 break;
2447 case USER:
2448 pw.print(prefix); pw.print(" User "); pw.print(bs.userId);
2449 pw.print(": "); printmAh(pw, bs.value); pw.println();
2450 break;
2451 case UNACCOUNTED:
2452 pw.print(prefix); pw.print(" Unaccounted: "); printmAh(pw, bs.value);
2453 pw.println();
2454 break;
2455 case OVERCOUNTED:
2456 pw.print(prefix); pw.print(" Over-counted: "); printmAh(pw, bs.value);
2457 pw.println();
2458 break;
2459 }
2460 }
Dianne Hackbornc46809e2014-01-15 16:20:44 -08002461 pw.println();
Dianne Hackborna7c837f2014-01-15 16:20:44 -08002462 }
2463
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002464 sippers = helper.getMobilemsppList();
2465 if (sippers != null && sippers.size() > 0) {
2466 pw.print(prefix); pw.println(" Per-app mobile ms per packet:");
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002467 long totalTime = 0;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002468 for (int i=0; i<sippers.size(); i++) {
2469 BatterySipper bs = sippers.get(i);
2470 sb.setLength(0);
2471 sb.append(prefix); sb.append(" Uid ");
2472 UserHandle.formatUid(sb, bs.uidObj.getUid());
2473 sb.append(": "); sb.append(BatteryStatsHelper.makemAh(bs.mobilemspp));
2474 sb.append(" ("); sb.append(bs.mobileRxPackets+bs.mobileTxPackets);
2475 sb.append(" packets over "); formatTimeMsNoSpace(sb, bs.mobileActive);
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002476 sb.append(") "); sb.append(bs.mobileActiveCount); sb.append("x");
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002477 pw.println(sb.toString());
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002478 totalTime += bs.mobileActive;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002479 }
Dianne Hackborn77b987f2014-02-26 16:20:52 -08002480 sb.setLength(0);
2481 sb.append(prefix);
2482 sb.append(" TOTAL TIME: ");
2483 formatTimeMs(sb, totalTime);
2484 sb.append("("); sb.append(formatRatioLocked(totalTime, whichBatteryRealtime));
2485 sb.append(")");
2486 pw.println(sb.toString());
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002487 pw.println();
2488 }
2489
Dianne Hackbornc51cf032014-03-02 19:08:15 -08002490 final Comparator<TimerEntry> timerComparator = new Comparator<TimerEntry>() {
2491 @Override
2492 public int compare(TimerEntry lhs, TimerEntry rhs) {
2493 long lhsTime = lhs.mTime;
2494 long rhsTime = rhs.mTime;
2495 if (lhsTime < rhsTime) {
2496 return 1;
2497 }
2498 if (lhsTime > rhsTime) {
2499 return -1;
2500 }
2501 return 0;
2502 }
2503 };
2504
2505 if (reqUid < 0) {
2506 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
2507 if (kernelWakelocks.size() > 0) {
2508 final ArrayList<TimerEntry> ktimers = new ArrayList<TimerEntry>();
2509 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
2510 BatteryStats.Timer timer = ent.getValue();
2511 long totalTimeMillis = computeWakeLock(timer, rawRealtime, which);
2512 if (totalTimeMillis > 0) {
2513 ktimers.add(new TimerEntry(ent.getKey(), 0, timer, totalTimeMillis));
2514 }
2515 }
2516 if (ktimers.size() > 0) {
2517 Collections.sort(ktimers, timerComparator);
2518 pw.print(prefix); pw.println(" All kernel wake locks:");
2519 for (int i=0; i<ktimers.size(); i++) {
2520 TimerEntry timer = ktimers.get(i);
2521 String linePrefix = ": ";
2522 sb.setLength(0);
2523 sb.append(prefix);
2524 sb.append(" Kernel Wake lock ");
2525 sb.append(timer.mName);
2526 linePrefix = printWakeLock(sb, timer.mTimer, rawRealtime, null,
2527 which, linePrefix);
2528 if (!linePrefix.equals(": ")) {
2529 sb.append(" realtime");
2530 // Only print out wake locks that were held
2531 pw.println(sb.toString());
2532 }
2533 }
2534 pw.println();
2535 }
2536 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08002537
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002538 if (timers.size() > 0) {
2539 Collections.sort(timers, timerComparator);
2540 pw.print(prefix); pw.println(" All partial wake locks:");
2541 for (int i=0; i<timers.size(); i++) {
2542 TimerEntry timer = timers.get(i);
2543 sb.setLength(0);
2544 sb.append(" Wake lock ");
2545 UserHandle.formatUid(sb, timer.mId);
2546 sb.append(" ");
2547 sb.append(timer.mName);
2548 printWakeLock(sb, timer.mTimer, rawRealtime, null, which, ": ");
2549 sb.append(" realtime");
2550 pw.println(sb.toString());
2551 }
2552 timers.clear();
2553 pw.println();
Dianne Hackborn81038902012-11-26 17:04:09 -08002554 }
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002555
2556 Map<String, ? extends LongCounter> wakeupReasons = getWakeupReasonStats();
2557 if (wakeupReasons.size() > 0) {
2558 pw.print(prefix); pw.println(" All wakeup reasons:");
2559 final ArrayList<TimerEntry> reasons = new ArrayList<TimerEntry>();
2560 for (Map.Entry<String, ? extends LongCounter> ent : wakeupReasons.entrySet()) {
2561 BatteryStats.LongCounter counter = ent.getValue();
2562 reasons.add(new TimerEntry(ent.getKey(), 0, null,
2563 ent.getValue().getCountLocked(which)));
2564 }
2565 Collections.sort(reasons, timerComparator);
2566 for (int i=0; i<reasons.size(); i++) {
2567 TimerEntry timer = reasons.get(i);
2568 String linePrefix = ": ";
2569 sb.setLength(0);
2570 sb.append(prefix);
2571 sb.append(" Wakeup reason ");
2572 sb.append(timer.mName);
2573 sb.append(": ");
2574 formatTimeMs(sb, timer.mTime);
2575 sb.append("realtime");
2576 pw.println(sb.toString());
2577 }
2578 pw.println();
2579 }
Dianne Hackborn81038902012-11-26 17:04:09 -08002580 }
Evan Millar22ac0432009-03-31 11:33:18 -07002581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 for (int iu=0; iu<NU; iu++) {
2583 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08002584 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002585 continue;
2586 }
2587
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 Uid u = uidStats.valueAt(iu);
Dianne Hackborna4cc2052013-07-08 17:31:25 -07002589
2590 pw.print(prefix);
2591 pw.print(" ");
2592 UserHandle.formatUid(pw, uid);
2593 pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 boolean uidActivity = false;
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002595
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002596 long mobileRxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
2597 long mobileTxBytes = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
2598 long wifiRxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
2599 long wifiTxBytes = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
2600 long mobileRxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
2601 long mobileTxPackets = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002602 long uidMobileActiveTime = u.getMobileRadioActiveTime(which);
2603 int uidMobileActiveCount = u.getMobileRadioActiveCount(which);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002604 long wifiRxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
2605 long wifiTxPackets = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002606 long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
2607 long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
2608 long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002609
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002610 if (mobileRxBytes > 0 || mobileTxBytes > 0
2611 || mobileRxPackets > 0 || mobileTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002612 pw.print(prefix); pw.print(" Mobile network: ");
2613 pw.print(formatBytesLocked(mobileRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002614 pw.print(formatBytesLocked(mobileTxBytes));
2615 pw.print(" sent (packets "); pw.print(mobileRxPackets);
2616 pw.print(" received, "); pw.print(mobileTxPackets); pw.println(" sent)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 }
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002618 if (uidMobileActiveTime > 0 || uidMobileActiveCount > 0) {
2619 sb.setLength(0);
2620 sb.append(prefix); sb.append(" Mobile radio active: ");
2621 formatTimeMs(sb, uidMobileActiveTime / 1000);
2622 sb.append("(");
2623 sb.append(formatRatioLocked(uidMobileActiveTime, mobileActiveTime));
2624 sb.append(") "); sb.append(uidMobileActiveCount); sb.append("x");
2625 long packets = mobileRxPackets + mobileTxPackets;
2626 if (packets == 0) {
2627 packets = 1;
2628 }
2629 sb.append(" @ ");
2630 sb.append(BatteryStatsHelper.makemAh(uidMobileActiveTime / 1000 / (double)packets));
2631 sb.append(" mspp");
2632 pw.println(sb.toString());
2633 }
2634
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002635 if (wifiRxBytes > 0 || wifiTxBytes > 0 || wifiRxPackets > 0 || wifiTxPackets > 0) {
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002636 pw.print(prefix); pw.print(" Wi-Fi network: ");
2637 pw.print(formatBytesLocked(wifiRxBytes)); pw.print(" received, ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002638 pw.print(formatBytesLocked(wifiTxBytes));
2639 pw.print(" sent (packets "); pw.print(wifiRxPackets);
2640 pw.print(" received, "); pw.print(wifiTxPackets); pw.println(" sent)");
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -07002641 }
2642
Dianne Hackbornd45665b2014-02-26 12:35:32 -08002643 if (fullWifiLockOnTime != 0 || wifiScanTime != 0
2644 || uidWifiRunningTime != 0) {
2645 sb.setLength(0);
2646 sb.append(prefix); sb.append(" Wifi Running: ");
2647 formatTimeMs(sb, uidWifiRunningTime / 1000);
2648 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
2649 whichBatteryRealtime)); sb.append(")\n");
2650 sb.append(prefix); sb.append(" Full Wifi Lock: ");
2651 formatTimeMs(sb, fullWifiLockOnTime / 1000);
2652 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
2653 whichBatteryRealtime)); sb.append(")\n");
2654 sb.append(prefix); sb.append(" Wifi Scan: ");
2655 formatTimeMs(sb, wifiScanTime / 1000);
2656 sb.append("("); sb.append(formatRatioLocked(wifiScanTime,
2657 whichBatteryRealtime)); sb.append(")");
2658 pw.println(sb.toString());
2659 }
2660
Dianne Hackborn617f8772009-03-31 15:04:46 -07002661 if (u.hasUserActivity()) {
2662 boolean hasData = false;
Raph Levien4c7a4a72012-08-03 14:32:39 -07002663 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
Dianne Hackborn617f8772009-03-31 15:04:46 -07002664 int val = u.getUserActivityCount(i, which);
2665 if (val != 0) {
2666 if (!hasData) {
2667 sb.setLength(0);
2668 sb.append(" User activity: ");
2669 hasData = true;
2670 } else {
2671 sb.append(", ");
2672 }
2673 sb.append(val);
2674 sb.append(" ");
2675 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
2676 }
2677 }
2678 if (hasData) {
2679 pw.println(sb.toString());
2680 }
2681 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002682
2683 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
2684 if (wakelocks.size() > 0) {
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002685 long totalFull = 0, totalPartial = 0, totalWindow = 0;
2686 int count = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
2688 : wakelocks.entrySet()) {
2689 Uid.Wakelock wl = ent.getValue();
2690 String linePrefix = ": ";
2691 sb.setLength(0);
2692 sb.append(prefix);
2693 sb.append(" Wake lock ");
2694 sb.append(ent.getKey());
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002695 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696 "full", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002697 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 "partial", which, linePrefix);
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002699 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 "window", which, linePrefix);
2701 if (!linePrefix.equals(": ")) {
2702 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05002703 // Only print out wake locks that were held
2704 pw.println(sb.toString());
2705 uidActivity = true;
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002706 count++;
2707 }
2708 totalFull += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002709 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002710 totalPartial += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002711 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002712 totalWindow += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002713 rawRealtime, which);
Dianne Hackbornc24ab862011-10-18 15:55:03 -07002714 }
2715 if (count > 1) {
2716 if (totalFull != 0 || totalPartial != 0 || totalWindow != 0) {
2717 sb.setLength(0);
2718 sb.append(prefix);
2719 sb.append(" TOTAL wake: ");
2720 boolean needComma = false;
2721 if (totalFull != 0) {
2722 needComma = true;
2723 formatTimeMs(sb, totalFull);
2724 sb.append("full");
2725 }
2726 if (totalPartial != 0) {
2727 if (needComma) {
2728 sb.append(", ");
2729 }
2730 needComma = true;
2731 formatTimeMs(sb, totalPartial);
2732 sb.append("partial");
2733 }
2734 if (totalWindow != 0) {
2735 if (needComma) {
2736 sb.append(", ");
2737 }
2738 needComma = true;
2739 formatTimeMs(sb, totalWindow);
2740 sb.append("window");
2741 }
2742 sb.append(" realtime");
2743 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002744 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002745 }
2746 }
2747
2748 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
2749 if (sensors.size() > 0) {
2750 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
2751 : sensors.entrySet()) {
2752 Uid.Sensor se = ent.getValue();
2753 int sensorNumber = ent.getKey();
2754 sb.setLength(0);
2755 sb.append(prefix);
2756 sb.append(" Sensor ");
2757 int handle = se.getHandle();
2758 if (handle == Uid.Sensor.GPS) {
2759 sb.append("GPS");
2760 } else {
2761 sb.append(handle);
2762 }
2763 sb.append(": ");
2764
2765 Timer timer = se.getSensorTime();
2766 if (timer != null) {
2767 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -07002768 long totalTime = (timer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002769 rawRealtime, which) + 500) / 1000;
Evan Millarc64edde2009-04-18 12:26:32 -07002770 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 //timer.logState();
2772 if (totalTime != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002773 formatTimeMs(sb, totalTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 sb.append("realtime (");
2775 sb.append(count);
2776 sb.append(" times)");
2777 } else {
2778 sb.append("(not used)");
2779 }
2780 } else {
2781 sb.append("(not used)");
2782 }
2783
2784 pw.println(sb.toString());
2785 uidActivity = true;
2786 }
2787 }
2788
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002789 Timer vibTimer = u.getVibratorOnTimer();
2790 if (vibTimer != null) {
2791 // Convert from microseconds to milliseconds with rounding
2792 long totalTime = (vibTimer.getTotalTimeLocked(
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002793 rawRealtime, which) + 500) / 1000;
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002794 int count = vibTimer.getCountLocked(which);
2795 //timer.logState();
2796 if (totalTime != 0) {
2797 sb.setLength(0);
2798 sb.append(prefix);
2799 sb.append(" Vibrator: ");
2800 formatTimeMs(sb, totalTime);
2801 sb.append("realtime (");
2802 sb.append(count);
2803 sb.append(" times)");
2804 pw.println(sb.toString());
2805 uidActivity = true;
2806 }
2807 }
2808
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002809 Timer fgTimer = u.getForegroundActivityTimer();
2810 if (fgTimer != null) {
2811 // Convert from microseconds to milliseconds with rounding
Dianne Hackborn97ae5382014-03-05 16:43:25 -08002812 long totalTime = (fgTimer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002813 int count = fgTimer.getCountLocked(which);
2814 if (totalTime != 0) {
2815 sb.setLength(0);
2816 sb.append(prefix);
2817 sb.append(" Foreground activities: ");
2818 formatTimeMs(sb, totalTime);
2819 sb.append("realtime (");
2820 sb.append(count);
2821 sb.append(" times)");
2822 pw.println(sb.toString());
2823 uidActivity = true;
2824 }
2825 }
2826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
2828 if (processStats.size() > 0) {
2829 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
2830 : processStats.entrySet()) {
2831 Uid.Proc ps = ent.getValue();
2832 long userTime;
2833 long systemTime;
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002834 long foregroundTime;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 int starts;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002836 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837
2838 userTime = ps.getUserTime(which);
2839 systemTime = ps.getSystemTime(which);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002840 foregroundTime = ps.getForegroundTime(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 starts = ps.getStarts(which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002842 numExcessive = which == STATS_SINCE_CHARGED
Dianne Hackborn287952c2010-09-22 22:34:31 -07002843 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002844
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002845 if (userTime != 0 || systemTime != 0 || foregroundTime != 0 || starts != 0
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002846 || numExcessive != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002847 sb.setLength(0);
2848 sb.append(prefix); sb.append(" Proc ");
2849 sb.append(ent.getKey()); sb.append(":\n");
2850 sb.append(prefix); sb.append(" CPU: ");
2851 formatTime(sb, userTime); sb.append("usr + ");
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002852 formatTime(sb, systemTime); sb.append("krn ; ");
2853 formatTime(sb, foregroundTime); sb.append("fg");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07002854 if (starts != 0) {
Dianne Hackbornb8071d792010-09-09 16:45:15 -07002855 sb.append("\n"); sb.append(prefix); sb.append(" ");
2856 sb.append(starts); sb.append(" proc starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07002857 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002858 pw.println(sb.toString());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002859 for (int e=0; e<numExcessive; e++) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07002860 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002861 if (ew != null) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07002862 pw.print(prefix); pw.print(" * Killed for ");
2863 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
2864 pw.print("wake lock");
2865 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
2866 pw.print("cpu");
2867 } else {
2868 pw.print("unknown");
2869 }
2870 pw.print(" use: ");
Dianne Hackborn1ebccf52010-08-15 13:04:34 -07002871 TimeUtils.formatDuration(ew.usedTime, pw);
2872 pw.print(" over ");
2873 TimeUtils.formatDuration(ew.overTime, pw);
Robert Greenwalta029ea12013-09-25 16:38:12 -07002874 if (ew.overTime != 0) {
2875 pw.print(" (");
2876 pw.print((ew.usedTime*100)/ew.overTime);
2877 pw.println("%)");
2878 }
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07002879 }
2880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002881 uidActivity = true;
2882 }
2883 }
2884 }
2885
2886 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
2887 if (packageStats.size() > 0) {
2888 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
2889 : packageStats.entrySet()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002890 pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 boolean apkActivity = false;
2892 Uid.Pkg ps = ent.getValue();
2893 int wakeups = ps.getWakeups(which);
2894 if (wakeups != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002895 pw.print(prefix); pw.print(" ");
2896 pw.print(wakeups); pw.println(" wakeup alarms");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002897 apkActivity = true;
2898 }
2899 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
2900 if (serviceStats.size() > 0) {
2901 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
2902 : serviceStats.entrySet()) {
2903 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
2904 long startTime = ss.getStartTime(batteryUptime, which);
2905 int starts = ss.getStarts(which);
2906 int launches = ss.getLaunches(which);
2907 if (startTime != 0 || starts != 0 || launches != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002908 sb.setLength(0);
2909 sb.append(prefix); sb.append(" Service ");
2910 sb.append(sent.getKey()); sb.append(":\n");
2911 sb.append(prefix); sb.append(" Created for: ");
2912 formatTimeMs(sb, startTime / 1000);
Jeff Sharkey3e013e82013-04-25 14:48:19 -07002913 sb.append("uptime\n");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002914 sb.append(prefix); sb.append(" Starts: ");
2915 sb.append(starts);
2916 sb.append(", launches: "); sb.append(launches);
2917 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 apkActivity = true;
2919 }
2920 }
2921 }
2922 if (!apkActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002923 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 }
2925 uidActivity = true;
2926 }
2927 }
2928 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07002929 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 }
2931 }
2932 }
2933
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002934 static void printBitDescriptions(PrintWriter pw, int oldval, int newval, HistoryTag wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002935 BitDescription[] descriptions, boolean longNames) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002936 int diff = oldval ^ newval;
2937 if (diff == 0) return;
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002938 boolean didWake = false;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002939 for (int i=0; i<descriptions.length; i++) {
2940 BitDescription bd = descriptions[i];
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002941 if ((diff&bd.mask) != 0) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002942 pw.print(longNames ? " " : ",");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002943 if (bd.shift < 0) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002944 pw.print((newval&bd.mask) != 0 ? "+" : "-");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002945 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002946 if (bd.mask == HistoryItem.STATE_WAKE_LOCK_FLAG && wakelockTag != null) {
2947 didWake = true;
2948 pw.print("=");
2949 if (longNames) {
2950 UserHandle.formatUid(pw, wakelockTag.uid);
2951 pw.print(":\"");
2952 pw.print(wakelockTag.string);
2953 pw.print("\"");
2954 } else {
2955 pw.print(wakelockTag.poolIdx);
2956 }
2957 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002958 } else {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002959 pw.print(longNames ? bd.name : bd.shortName);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002960 pw.print("=");
2961 int val = (newval&bd.mask)>>bd.shift;
2962 if (bd.values != null && val >= 0 && val < bd.values.length) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002963 pw.print(longNames? bd.values[val] : bd.shortValues[val]);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002964 } else {
2965 pw.print(val);
2966 }
2967 }
2968 }
2969 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002970 if (!didWake && wakelockTag != null) {
Ashish Sharma81850c42014-05-05 13:57:07 -07002971 pw.print(longNames ? " wake_lock=" : ",w=");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08002972 if (longNames) {
2973 UserHandle.formatUid(pw, wakelockTag.uid);
2974 pw.print(":\"");
2975 pw.print(wakelockTag.string);
2976 pw.print("\"");
2977 } else {
2978 pw.print(wakelockTag.poolIdx);
2979 }
2980 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07002981 }
2982
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002983 public void prepareForDumpLocked() {
2984 }
2985
2986 public static class HistoryPrinter {
2987 int oldState = 0;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002988 int oldState2 = 0;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002989 int oldLevel = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002990 int oldStatus = -1;
2991 int oldHealth = -1;
2992 int oldPlug = -1;
2993 int oldTemp = -1;
2994 int oldVolt = -1;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08002995 long lastTime = -1;
Dianne Hackborn99009ea2014-04-18 16:23:42 -07002996 long firstTime = -1;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07002997
Dianne Hackborn99009ea2014-04-18 16:23:42 -07002998 public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
Dianne Hackborna1bd7922014-03-21 11:07:11 -07002999 boolean verbose) {
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003000 if (!checkin) {
3001 pw.print(" ");
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003002 TimeUtils.formatDuration(rec.time - baseTime, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003003 pw.print(" (");
3004 pw.print(rec.numReadInts);
3005 pw.print(") ");
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003006 } else {
3007 if (lastTime < 0) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003008 pw.print(rec.time - baseTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003009 } else {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003010 pw.print(rec.time - lastTime);
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003011 }
3012 lastTime = rec.time;
3013 }
3014 if (rec.cmd == HistoryItem.CMD_START) {
3015 if (checkin) {
3016 pw.print(":");
3017 }
3018 pw.println("START");
Dianne Hackborn37de0982014-05-09 09:32:18 -07003019 } else if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
3020 || rec.cmd == HistoryItem.CMD_RESET) {
Dianne Hackborne5167ca2014-03-08 14:39:10 -08003021 if (checkin) {
3022 pw.print(":");
3023 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07003024 if (rec.cmd == HistoryItem.CMD_RESET) {
3025 pw.print("RESET:");
3026 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08003027 pw.print("TIME:");
3028 if (checkin) {
3029 pw.println(rec.currentTime);
3030 } else {
3031 pw.print(" ");
3032 pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss",
3033 rec.currentTime).toString());
3034 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003035 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
3036 if (checkin) {
3037 pw.print(":");
3038 }
3039 pw.println("*OVERFLOW*");
3040 } else {
3041 if (!checkin) {
3042 if (rec.batteryLevel < 10) pw.print("00");
3043 else if (rec.batteryLevel < 100) pw.print("0");
3044 pw.print(rec.batteryLevel);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003045 if (verbose) {
3046 pw.print(" ");
3047 if (rec.states < 0) ;
3048 else if (rec.states < 0x10) pw.print("0000000");
3049 else if (rec.states < 0x100) pw.print("000000");
3050 else if (rec.states < 0x1000) pw.print("00000");
3051 else if (rec.states < 0x10000) pw.print("0000");
3052 else if (rec.states < 0x100000) pw.print("000");
3053 else if (rec.states < 0x1000000) pw.print("00");
3054 else if (rec.states < 0x10000000) pw.print("0");
3055 pw.print(Integer.toHexString(rec.states));
3056 }
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003057 } else {
3058 if (oldLevel != rec.batteryLevel) {
3059 oldLevel = rec.batteryLevel;
3060 pw.print(",Bl="); pw.print(rec.batteryLevel);
3061 }
3062 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003063 if (oldStatus != rec.batteryStatus) {
3064 oldStatus = rec.batteryStatus;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003065 pw.print(checkin ? ",Bs=" : " status=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003066 switch (oldStatus) {
3067 case BatteryManager.BATTERY_STATUS_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003068 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003069 break;
3070 case BatteryManager.BATTERY_STATUS_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003071 pw.print(checkin ? "c" : "charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003072 break;
3073 case BatteryManager.BATTERY_STATUS_DISCHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003074 pw.print(checkin ? "d" : "discharging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003075 break;
3076 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003077 pw.print(checkin ? "n" : "not-charging");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003078 break;
3079 case BatteryManager.BATTERY_STATUS_FULL:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003080 pw.print(checkin ? "f" : "full");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003081 break;
3082 default:
3083 pw.print(oldStatus);
3084 break;
3085 }
3086 }
3087 if (oldHealth != rec.batteryHealth) {
3088 oldHealth = rec.batteryHealth;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003089 pw.print(checkin ? ",Bh=" : " health=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003090 switch (oldHealth) {
3091 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003092 pw.print(checkin ? "?" : "unknown");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003093 break;
3094 case BatteryManager.BATTERY_HEALTH_GOOD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003095 pw.print(checkin ? "g" : "good");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003096 break;
3097 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003098 pw.print(checkin ? "h" : "overheat");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003099 break;
3100 case BatteryManager.BATTERY_HEALTH_DEAD:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003101 pw.print(checkin ? "d" : "dead");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003102 break;
3103 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003104 pw.print(checkin ? "v" : "over-voltage");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003105 break;
3106 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003107 pw.print(checkin ? "f" : "failure");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003108 break;
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08003109 case BatteryManager.BATTERY_HEALTH_COLD:
3110 pw.print(checkin ? "c" : "cold");
3111 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003112 default:
3113 pw.print(oldHealth);
3114 break;
3115 }
3116 }
3117 if (oldPlug != rec.batteryPlugType) {
3118 oldPlug = rec.batteryPlugType;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003119 pw.print(checkin ? ",Bp=" : " plug=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003120 switch (oldPlug) {
3121 case 0:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003122 pw.print(checkin ? "n" : "none");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003123 break;
3124 case BatteryManager.BATTERY_PLUGGED_AC:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003125 pw.print(checkin ? "a" : "ac");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003126 break;
3127 case BatteryManager.BATTERY_PLUGGED_USB:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003128 pw.print(checkin ? "u" : "usb");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003129 break;
Brian Muramatsu37a37f42012-08-14 15:21:02 -07003130 case BatteryManager.BATTERY_PLUGGED_WIRELESS:
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003131 pw.print(checkin ? "w" : "wireless");
Brian Muramatsu37a37f42012-08-14 15:21:02 -07003132 break;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003133 default:
3134 pw.print(oldPlug);
3135 break;
3136 }
3137 }
3138 if (oldTemp != rec.batteryTemperature) {
3139 oldTemp = rec.batteryTemperature;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003140 pw.print(checkin ? ",Bt=" : " temp=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003141 pw.print(oldTemp);
3142 }
3143 if (oldVolt != rec.batteryVoltage) {
3144 oldVolt = rec.batteryVoltage;
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003145 pw.print(checkin ? ",Bv=" : " volt=");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003146 pw.print(oldVolt);
3147 }
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003148 printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
Dianne Hackborn57ed6a62013-12-09 18:15:56 -08003149 HISTORY_STATE_DESCRIPTIONS, !checkin);
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003150 printBitDescriptions(pw, oldState2, rec.states2, null,
3151 HISTORY_STATE2_DESCRIPTIONS, !checkin);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003152 if (rec.wakeReasonTag != null) {
3153 if (checkin) {
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07003154 pw.print(",wr=");
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003155 pw.print(rec.wakeReasonTag.poolIdx);
3156 } else {
3157 pw.print(" wake_reason=");
3158 pw.print(rec.wakeReasonTag.uid);
3159 pw.print(":\"");
3160 pw.print(rec.wakeReasonTag.string);
3161 pw.print("\"");
3162 }
3163 }
Dianne Hackborn099bc622014-01-22 13:39:16 -08003164 if (rec.eventCode != HistoryItem.EVENT_NONE) {
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08003165 pw.print(checkin ? "," : " ");
3166 if ((rec.eventCode&HistoryItem.EVENT_FLAG_START) != 0) {
3167 pw.print("+");
3168 } else if ((rec.eventCode&HistoryItem.EVENT_FLAG_FINISH) != 0) {
3169 pw.print("-");
Dianne Hackborn099bc622014-01-22 13:39:16 -08003170 }
Dianne Hackborneaf2ac42014-02-07 13:01:07 -08003171 String[] eventNames = checkin ? HISTORY_EVENT_CHECKIN_NAMES
3172 : HISTORY_EVENT_NAMES;
3173 int idx = rec.eventCode & ~(HistoryItem.EVENT_FLAG_START
3174 | HistoryItem.EVENT_FLAG_FINISH);
3175 if (idx >= 0 && idx < eventNames.length) {
3176 pw.print(eventNames[idx]);
3177 } else {
3178 pw.print(checkin ? "Ev" : "event");
3179 pw.print(idx);
3180 }
3181 pw.print("=");
Dianne Hackborn099bc622014-01-22 13:39:16 -08003182 if (checkin) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003183 pw.print(rec.eventTag.poolIdx);
Dianne Hackborn099bc622014-01-22 13:39:16 -08003184 } else {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003185 UserHandle.formatUid(pw, rec.eventTag.uid);
3186 pw.print(":\"");
3187 pw.print(rec.eventTag.string);
3188 pw.print("\"");
Dianne Hackborn099bc622014-01-22 13:39:16 -08003189 }
3190 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003191 pw.println();
Dianne Hackborne5167ca2014-03-08 14:39:10 -08003192 oldState = rec.states;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003193 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003194 }
3195 }
3196
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003197 private void printSizeValue(PrintWriter pw, long size) {
3198 float result = size;
3199 String suffix = "";
3200 if (result >= 10*1024) {
3201 suffix = "KB";
3202 result = result / 1024;
3203 }
3204 if (result >= 10*1024) {
3205 suffix = "MB";
3206 result = result / 1024;
3207 }
3208 if (result >= 10*1024) {
3209 suffix = "GB";
3210 result = result / 1024;
3211 }
3212 if (result >= 10*1024) {
3213 suffix = "TB";
3214 result = result / 1024;
3215 }
3216 if (result >= 10*1024) {
3217 suffix = "PB";
3218 result = result / 1024;
3219 }
3220 pw.print((int)result);
3221 pw.print(suffix);
3222 }
3223
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07003224 private static boolean dumpDurationSteps(PrintWriter pw, String header, long[] steps,
3225 int count, boolean checkin) {
3226 if (count <= 0) {
3227 return false;
3228 }
3229 if (!checkin) {
3230 pw.println(header);
3231 }
3232 String[] lineArgs = new String[1];
3233 for (int i=0; i<count; i++) {
3234 if (checkin) {
3235 lineArgs[0] = Long.toString(steps[i]);
3236 dumpLine(pw, 0 /* uid */, "i" /* category */, header, (Object[])lineArgs);
3237 } else {
3238 pw.print(" #"); pw.print(i); pw.print(": ");
3239 TimeUtils.formatDuration(steps[i], pw);
3240 pw.println();
3241 }
3242 }
3243 return true;
3244 }
3245
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003246 public static final int DUMP_UNPLUGGED_ONLY = 1<<0;
3247 public static final int DUMP_CHARGED_ONLY = 1<<1;
3248 public static final int DUMP_HISTORY_ONLY = 1<<2;
3249 public static final int DUMP_INCLUDE_HISTORY = 1<<3;
Dianne Hackborna1bd7922014-03-21 11:07:11 -07003250 public static final int DUMP_VERBOSE = 1<<4;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003251
Dianne Hackborn37de0982014-05-09 09:32:18 -07003252 private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) {
3253 final HistoryPrinter hprinter = new HistoryPrinter();
3254 final HistoryItem rec = new HistoryItem();
3255 long lastTime = -1;
3256 long baseTime = -1;
3257 boolean printed = false;
3258 HistoryEventTracker tracker = null;
3259 while (getNextHistoryLocked(rec)) {
3260 lastTime = rec.time;
3261 if (baseTime < 0) {
3262 baseTime = lastTime;
3263 }
3264 if (rec.time >= histStart) {
3265 if (histStart >= 0 && !printed) {
3266 if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
3267 || rec.cmd == HistoryItem.CMD_RESET) {
3268 printed = true;
3269 } else if (rec.currentTime != 0) {
3270 printed = true;
3271 byte cmd = rec.cmd;
3272 rec.cmd = HistoryItem.CMD_CURRENT_TIME;
3273 if (checkin) {
3274 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
3275 pw.print(HISTORY_DATA); pw.print(',');
3276 }
3277 hprinter.printNextItem(pw, rec, baseTime, checkin,
3278 (flags&DUMP_VERBOSE) != 0);
3279 rec.cmd = cmd;
3280 }
3281 if (tracker != null) {
3282 int oldCode = rec.eventCode;
3283 HistoryTag oldTag = rec.eventTag;
3284 rec.eventTag = new HistoryTag();
3285 for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
3286 HashMap<String, SparseIntArray> active
3287 = tracker.getStateForEvent(i);
3288 if (active == null) {
3289 continue;
3290 }
3291 for (HashMap.Entry<String, SparseIntArray> ent
3292 : active.entrySet()) {
3293 SparseIntArray uids = ent.getValue();
3294 for (int j=0; j<uids.size(); j++) {
3295 rec.eventCode = i;
3296 rec.eventTag.string = ent.getKey();
3297 rec.eventTag.uid = uids.keyAt(j);
3298 rec.eventTag.poolIdx = uids.valueAt(j);
3299 if (checkin) {
3300 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
3301 pw.print(HISTORY_DATA); pw.print(',');
3302 }
3303 hprinter.printNextItem(pw, rec, baseTime, checkin,
3304 (flags&DUMP_VERBOSE) != 0);
3305 }
3306 }
3307 }
3308 rec.eventCode = oldCode;
3309 rec.eventTag = oldTag;
3310 tracker = null;
3311 }
3312 }
3313 if (checkin) {
3314 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
3315 pw.print(HISTORY_DATA); pw.print(',');
3316 }
3317 hprinter.printNextItem(pw, rec, baseTime, checkin,
3318 (flags&DUMP_VERBOSE) != 0);
3319 } else if (rec.eventCode != HistoryItem.EVENT_NONE) {
3320 if (tracker == null) {
3321 tracker = new HistoryEventTracker();
3322 }
3323 tracker.updateState(rec.eventCode, rec.eventTag.string,
3324 rec.eventTag.uid, rec.eventTag.poolIdx);
3325 }
3326 }
3327 if (histStart >= 0) {
3328 pw.print(checkin ? "NEXT: " : " NEXT: "); pw.println(lastTime+1);
3329 }
3330 }
3331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 /**
3333 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
3334 *
3335 * @param pw a Printer to receive the dump output.
3336 */
3337 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003338 public void dumpLocked(Context context, PrintWriter pw, int flags, int reqUid, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003339 prepareForDumpLocked();
3340
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003341 final boolean filtering =
3342 (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003343
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003344 if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003345 final long historyTotalSize = getHistoryTotalSize();
3346 final long historyUsedSize = getHistoryUsedSize();
3347 if (startIteratingHistoryLocked()) {
3348 try {
3349 pw.print("Battery History (");
3350 pw.print((100*historyUsedSize)/historyTotalSize);
3351 pw.print("% used, ");
3352 printSizeValue(pw, historyUsedSize);
3353 pw.print(" used of ");
3354 printSizeValue(pw, historyTotalSize);
3355 pw.print(", ");
3356 pw.print(getHistoryStringPoolSize());
3357 pw.print(" strings using ");
3358 printSizeValue(pw, getHistoryStringPoolBytes());
3359 pw.println("):");
Dianne Hackborn37de0982014-05-09 09:32:18 -07003360 dumpHistoryLocked(pw, flags, histStart, false);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003361 pw.println();
3362 } finally {
3363 finishIteratingHistoryLocked();
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003364 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003365 }
3366
3367 if (startIteratingOldHistoryLocked()) {
3368 try {
Dianne Hackborn37de0982014-05-09 09:32:18 -07003369 final HistoryItem rec = new HistoryItem();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003370 pw.println("Old battery History:");
3371 HistoryPrinter hprinter = new HistoryPrinter();
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003372 long baseTime = -1;
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003373 while (getNextOldHistoryLocked(rec)) {
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003374 if (baseTime < 0) {
3375 baseTime = rec.time;
3376 }
3377 hprinter.printNextItem(pw, rec, baseTime, false, (flags&DUMP_VERBOSE) != 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003378 }
3379 pw.println();
3380 } finally {
3381 finishIteratingOldHistoryLocked();
3382 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003383 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003384 }
3385
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003386 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08003387 return;
3388 }
3389
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003390 if (!filtering) {
3391 SparseArray<? extends Uid> uidStats = getUidStats();
3392 final int NU = uidStats.size();
3393 boolean didPid = false;
3394 long nowRealtime = SystemClock.elapsedRealtime();
3395 for (int i=0; i<NU; i++) {
3396 Uid uid = uidStats.valueAt(i);
3397 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
3398 if (pids != null) {
3399 for (int j=0; j<pids.size(); j++) {
3400 Uid.Pid pid = pids.valueAt(j);
3401 if (!didPid) {
3402 pw.println("Per-PID Stats:");
3403 didPid = true;
3404 }
Dianne Hackborne5167ca2014-03-08 14:39:10 -08003405 long time = pid.mWakeSumMs + (pid.mWakeNesting > 0
3406 ? (nowRealtime - pid.mWakeStartMs) : 0);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003407 pw.print(" PID "); pw.print(pids.keyAt(j));
3408 pw.print(" wake time: ");
3409 TimeUtils.formatDuration(time, pw);
3410 pw.println("");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07003411 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07003412 }
3413 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003414 if (didPid) {
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07003415 pw.println();
3416 }
3417 if (dumpDurationSteps(pw, "Discharge step durations:", getDischargeStepDurationsArray(),
3418 getNumDischargeStepDurations(), false)) {
3419 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
3420 if (timeRemaining >= 0) {
3421 pw.print(" Estimated discharge time remaining: ");
3422 TimeUtils.formatDuration(timeRemaining / 1000, pw);
3423 pw.println();
3424 }
3425 pw.println();
3426 }
3427 if (dumpDurationSteps(pw, "Charge step durations:", getChargeStepDurationsArray(),
3428 getNumChargeStepDurations(), false)) {
3429 long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
3430 if (timeRemaining >= 0) {
3431 pw.print(" Estimated charge time remaining: ");
3432 TimeUtils.formatDuration(timeRemaining / 1000, pw);
3433 pw.println();
3434 }
3435 pw.println();
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003436 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -07003437 }
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07003438
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003439 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07003440 pw.println("Statistics since last charge:");
3441 pw.println(" System starts: " + getStartCount()
3442 + ", currently on battery: " + getIsOnBattery());
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003443 dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid);
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07003444 pw.println();
Jeff Sharkeyec43a6b2013-04-30 13:33:18 -07003445 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003446 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
3447 pw.println("Statistics since last unplugged:");
3448 dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid);
3449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450 }
3451
3452 @SuppressWarnings("unused")
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003453 public void dumpCheckinLocked(Context context, PrintWriter pw,
3454 List<ApplicationInfo> apps, int flags, long histStart) {
Dianne Hackborn0ffc9882011-04-13 18:15:56 -07003455 prepareForDumpLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003457 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
3458
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003459 final boolean filtering =
3460 (flags&(DUMP_HISTORY_ONLY|DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) != 0;
3461
3462 if ((flags&DUMP_INCLUDE_HISTORY) != 0 || (flags&DUMP_HISTORY_ONLY) != 0) {
Dianne Hackborn49021f52013-09-04 18:03:40 -07003463 if (startIteratingHistoryLocked()) {
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003464 try {
3465 for (int i=0; i<getHistoryStringPoolSize(); i++) {
3466 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
3467 pw.print(HISTORY_STRING_POOL); pw.print(',');
3468 pw.print(i);
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003469 pw.print(",");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003470 pw.print(getHistoryTagPoolUid(i));
Dianne Hackborn99009ea2014-04-18 16:23:42 -07003471 pw.print(",\"");
3472 String str = getHistoryTagPoolString(i);
3473 str = str.replace("\\", "\\\\");
3474 str = str.replace("\"", "\\\"");
3475 pw.print(str);
3476 pw.print("\"");
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003477 pw.println();
3478 }
Dianne Hackborn37de0982014-05-09 09:32:18 -07003479 dumpHistoryLocked(pw, flags, histStart, true);
Dianne Hackborn71fc13e2014-02-03 10:50:53 -08003480 } finally {
3481 finishIteratingHistoryLocked();
Dianne Hackborn099bc622014-01-22 13:39:16 -08003482 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003483 }
Dianne Hackborn13ac0412013-06-25 19:34:49 -07003484 }
3485
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003486 if (filtering && (flags&(DUMP_UNPLUGGED_ONLY|DUMP_CHARGED_ONLY)) == 0) {
Dianne Hackborn099bc622014-01-22 13:39:16 -08003487 return;
3488 }
3489
Dianne Hackborne4a59512010-12-07 11:08:07 -08003490 if (apps != null) {
3491 SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
3492 for (int i=0; i<apps.size(); i++) {
3493 ApplicationInfo ai = apps.get(i);
3494 ArrayList<String> pkgs = uids.get(ai.uid);
3495 if (pkgs == null) {
3496 pkgs = new ArrayList<String>();
3497 uids.put(ai.uid, pkgs);
3498 }
3499 pkgs.add(ai.packageName);
3500 }
3501 SparseArray<? extends Uid> uidStats = getUidStats();
3502 final int NU = uidStats.size();
3503 String[] lineArgs = new String[2];
3504 for (int i=0; i<NU; i++) {
3505 int uid = uidStats.keyAt(i);
3506 ArrayList<String> pkgs = uids.get(uid);
3507 if (pkgs != null) {
3508 for (int j=0; j<pkgs.size(); j++) {
3509 lineArgs[0] = Integer.toString(uid);
3510 lineArgs[1] = pkgs.get(j);
3511 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
3512 (Object[])lineArgs);
3513 }
3514 }
3515 }
3516 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07003517 if (!filtering) {
3518 dumpDurationSteps(pw, DISCHARGE_STEP_DATA, getDischargeStepDurationsArray(),
3519 getNumDischargeStepDurations(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07003520 String[] lineArgs = new String[1];
3521 long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
3522 if (timeRemaining >= 0) {
3523 lineArgs[0] = Long.toString(timeRemaining);
3524 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
3525 (Object[])lineArgs);
3526 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07003527 dumpDurationSteps(pw, CHARGE_STEP_DATA, getChargeStepDurationsArray(),
3528 getNumChargeStepDurations(), true);
Dianne Hackbornd06dcfd2014-05-02 13:49:30 -07003529 timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
3530 if (timeRemaining >= 0) {
3531 lineArgs[0] = Long.toString(timeRemaining);
3532 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
3533 (Object[])lineArgs);
3534 }
Dianne Hackbornab5c0ea2014-04-29 14:53:32 -07003535 }
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003536 if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003537 dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1);
Dianne Hackbornc51cf032014-03-02 19:08:15 -08003538 }
3539 if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) {
Dianne Hackborna7c837f2014-01-15 16:20:44 -08003540 dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003541 }
3542 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003543}