blob: e4485d1fb68e8574edc24bdea90e150ca791ec2a [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import java.util.Formatter;
Dianne Hackborne4a59512010-12-07 11:08:07 -080022import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import java.util.Map;
24
Dianne Hackborne4a59512010-12-07 11:08:07 -080025import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.util.Log;
27import android.util.Printer;
28import android.util.SparseArray;
Dianne Hackborn1ebccf52010-08-15 13:04:34 -070029import android.util.TimeUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
31/**
32 * A class providing access to battery usage statistics, including information on
33 * wakelocks, processes, packages, and services. All times are represented in microseconds
34 * except where indicated otherwise.
35 * @hide
36 */
37public abstract class BatteryStats implements Parcelable {
38
39 private static final boolean LOCAL_LOGV = false;
40
41 /**
42 * A constant indicating a partial wake lock timer.
43 */
44 public static final int WAKE_TYPE_PARTIAL = 0;
45
46 /**
47 * A constant indicating a full wake lock timer.
48 */
49 public static final int WAKE_TYPE_FULL = 1;
50
51 /**
52 * A constant indicating a window wake lock timer.
53 */
54 public static final int WAKE_TYPE_WINDOW = 2;
55
56 /**
57 * A constant indicating a sensor timer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 */
59 public static final int SENSOR = 3;
The Android Open Source Project10592532009-03-18 17:39:46 -070060
61 /**
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070062 * A constant indicating a a wifi running timer
Dianne Hackborn617f8772009-03-31 15:04:46 -070063 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -070064 public static final int WIFI_RUNNING = 4;
Dianne Hackborn617f8772009-03-31 15:04:46 -070065
66 /**
The Android Open Source Project10592532009-03-18 17:39:46 -070067 * A constant indicating a full wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070068 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070069 public static final int FULL_WIFI_LOCK = 5;
The Android Open Source Project10592532009-03-18 17:39:46 -070070
71 /**
72 * A constant indicating a scan wifi lock timer
The Android Open Source Project10592532009-03-18 17:39:46 -070073 */
Dianne Hackborn617f8772009-03-31 15:04:46 -070074 public static final int SCAN_WIFI_LOCK = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075
Robert Greenwalt5347bd42009-05-13 15:10:16 -070076 /**
77 * A constant indicating a wifi multicast timer
Robert Greenwalt5347bd42009-05-13 15:10:16 -070078 */
79 public static final int WIFI_MULTICAST_ENABLED = 7;
80
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 /**
Amith Yamasani244fa5c2009-05-22 14:36:07 -070082 * A constant indicating an audio turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070083 */
84 public static final int AUDIO_TURNED_ON = 7;
85
86 /**
87 * A constant indicating a video turn on timer
Amith Yamasani244fa5c2009-05-22 14:36:07 -070088 */
89 public static final int VIDEO_TURNED_ON = 8;
90
91 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 * Include all of the data in the stats, including previously saved data.
93 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -070094 public static final int STATS_SINCE_CHARGED = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095
96 /**
97 * Include only the last run in the stats.
98 */
99 public static final int STATS_LAST = 1;
100
101 /**
102 * Include only the current run in the stats.
103 */
104 public static final int STATS_CURRENT = 2;
105
106 /**
107 * Include only the run since the last time the device was unplugged in the stats.
108 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700109 public static final int STATS_SINCE_UNPLUGGED = 3;
Evan Millare84de8d2009-04-02 22:16:12 -0700110
111 // NOTE: Update this list if you add/change any stats above.
112 // These characters are supposed to represent "total", "last", "current",
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700113 // and "unplugged". They were shortened for efficiency sake.
Evan Millare84de8d2009-04-02 22:16:12 -0700114 private static final String[] STAT_NAMES = { "t", "l", "c", "u" };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115
116 /**
117 * Bump the version on this if the checkin format changes.
118 */
Evan Millarc64edde2009-04-18 12:26:32 -0700119 private static final int BATTERY_STATS_CHECKIN_VERSION = 5;
Evan Millar22ac0432009-03-31 11:33:18 -0700120
121 private static final long BYTES_PER_KB = 1024;
122 private static final long BYTES_PER_MB = 1048576; // 1024^2
123 private static final long BYTES_PER_GB = 1073741824; //1024^3
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125
Dianne Hackborne4a59512010-12-07 11:08:07 -0800126 private static final String UID_DATA = "uid";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 private static final String APK_DATA = "apk";
Evan Millare84de8d2009-04-02 22:16:12 -0700128 private static final String PROCESS_DATA = "pr";
129 private static final String SENSOR_DATA = "sr";
130 private static final String WAKELOCK_DATA = "wl";
Evan Millarc64edde2009-04-18 12:26:32 -0700131 private static final String KERNEL_WAKELOCK_DATA = "kwl";
Evan Millare84de8d2009-04-02 22:16:12 -0700132 private static final String NETWORK_DATA = "nt";
133 private static final String USER_ACTIVITY_DATA = "ua";
134 private static final String BATTERY_DATA = "bt";
135 private static final String BATTERY_LEVEL_DATA = "lv";
136 private static final String WIFI_LOCK_DATA = "wfl";
137 private static final String MISC_DATA = "m";
138 private static final String SCREEN_BRIGHTNESS_DATA = "br";
139 private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt";
Amith Yamasanif37447b2009-10-08 18:28:01 -0700140 private static final String SIGNAL_SCANNING_TIME_DATA = "sst";
Evan Millare84de8d2009-04-02 22:16:12 -0700141 private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc";
142 private static final String DATA_CONNECTION_TIME_DATA = "dct";
143 private static final String DATA_CONNECTION_COUNT_DATA = "dcc";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700145 private final StringBuilder mFormatBuilder = new StringBuilder(32);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 private final Formatter mFormatter = new Formatter(mFormatBuilder);
147
148 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700149 * State for keeping track of counting information.
150 */
151 public static abstract class Counter {
152
153 /**
154 * Returns the count associated with this Counter for the
155 * selected type of statistics.
156 *
157 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
158 */
Evan Millarc64edde2009-04-18 12:26:32 -0700159 public abstract int getCountLocked(int which);
Dianne Hackborn617f8772009-03-31 15:04:46 -0700160
161 /**
162 * Temporary for debugging.
163 */
164 public abstract void logState(Printer pw, String prefix);
165 }
166
167 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 * State for keeping track of timing information.
169 */
170 public static abstract class Timer {
171
172 /**
173 * Returns the count associated with this Timer for the
174 * selected type of statistics.
175 *
176 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
177 */
Evan Millarc64edde2009-04-18 12:26:32 -0700178 public abstract int getCountLocked(int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179
180 /**
181 * Returns the total time in microseconds associated with this Timer for the
182 * selected type of statistics.
183 *
184 * @param batteryRealtime system realtime on battery in microseconds
185 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT
186 * @return a time in microseconds
187 */
Evan Millarc64edde2009-04-18 12:26:32 -0700188 public abstract long getTotalTimeLocked(long batteryRealtime, int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 /**
191 * Temporary for debugging.
192 */
Dianne Hackborn627bba72009-03-24 22:32:56 -0700193 public abstract void logState(Printer pw, String prefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 }
195
196 /**
197 * The statistics associated with a particular uid.
198 */
199 public static abstract class Uid {
200
201 /**
202 * Returns a mapping containing wakelock statistics.
203 *
204 * @return a Map from Strings to Uid.Wakelock objects.
205 */
206 public abstract Map<String, ? extends Wakelock> getWakelockStats();
207
208 /**
209 * The statistics associated with a particular wake lock.
210 */
211 public static abstract class Wakelock {
212 public abstract Timer getWakeTime(int type);
213 }
214
215 /**
216 * Returns a mapping containing sensor statistics.
217 *
218 * @return a Map from Integer sensor ids to Uid.Sensor objects.
219 */
220 public abstract Map<Integer, ? extends Sensor> getSensorStats();
221
222 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700223 * Returns a mapping containing active process data.
224 */
225 public abstract SparseArray<? extends Pid> getPidStats();
226
227 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 * Returns a mapping containing process statistics.
229 *
230 * @return a Map from Strings to Uid.Proc objects.
231 */
232 public abstract Map<String, ? extends Proc> getProcessStats();
233
234 /**
235 * Returns a mapping containing package statistics.
236 *
237 * @return a Map from Strings to Uid.Pkg objects.
238 */
239 public abstract Map<String, ? extends Pkg> getPackageStats();
240
241 /**
242 * {@hide}
243 */
244 public abstract int getUid();
245
246 /**
247 * {@hide}
248 */
249 public abstract long getTcpBytesReceived(int which);
250
251 /**
252 * {@hide}
253 */
254 public abstract long getTcpBytesSent(int which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700255
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700256 public abstract void noteWifiRunningLocked();
257 public abstract void noteWifiStoppedLocked();
The Android Open Source Project10592532009-03-18 17:39:46 -0700258 public abstract void noteFullWifiLockAcquiredLocked();
259 public abstract void noteFullWifiLockReleasedLocked();
260 public abstract void noteScanWifiLockAcquiredLocked();
261 public abstract void noteScanWifiLockReleasedLocked();
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700262 public abstract void noteWifiMulticastEnabledLocked();
263 public abstract void noteWifiMulticastDisabledLocked();
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700264 public abstract void noteAudioTurnedOnLocked();
265 public abstract void noteAudioTurnedOffLocked();
266 public abstract void noteVideoTurnedOnLocked();
267 public abstract void noteVideoTurnedOffLocked();
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700268 public abstract long getWifiRunningTime(long batteryRealtime, int which);
The Android Open Source Project10592532009-03-18 17:39:46 -0700269 public abstract long getFullWifiLockTime(long batteryRealtime, int which);
270 public abstract long getScanWifiLockTime(long batteryRealtime, int which);
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700271 public abstract long getWifiMulticastTime(long batteryRealtime,
272 int which);
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700273 public abstract long getAudioTurnedOnTime(long batteryRealtime, int which);
274 public abstract long getVideoTurnedOnTime(long batteryRealtime, int which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275
Dianne Hackborn617f8772009-03-31 15:04:46 -0700276 /**
277 * Note that these must match the constants in android.os.LocalPowerManager.
278 */
279 static final String[] USER_ACTIVITY_TYPES = {
280 "other", "cheek", "touch", "long_touch", "touch_up", "button", "unknown"
281 };
282
283 public static final int NUM_USER_ACTIVITY_TYPES = 7;
284
285 public abstract void noteUserActivityLocked(int type);
286 public abstract boolean hasUserActivity();
287 public abstract int getUserActivityCount(int type, int which);
288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 public static abstract class Sensor {
290 // Magic sensor number for the GPS.
291 public static final int GPS = -10000;
292
293 public abstract int getHandle();
294
295 public abstract Timer getSensorTime();
296 }
297
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700298 public class Pid {
299 public long mWakeSum;
300 public long mWakeStart;
301 }
302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 /**
304 * The statistics associated with a particular process.
305 */
306 public static abstract class Proc {
307
Dianne Hackborn287952c2010-09-22 22:34:31 -0700308 public static class ExcessivePower {
309 public static final int TYPE_WAKE = 1;
310 public static final int TYPE_CPU = 2;
311
312 public int type;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700313 public long overTime;
314 public long usedTime;
315 }
316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 /**
318 * Returns the total time (in 1/100 sec) spent executing in user code.
319 *
320 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
321 */
322 public abstract long getUserTime(int which);
323
324 /**
325 * Returns the total time (in 1/100 sec) spent executing in system code.
326 *
327 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
328 */
329 public abstract long getSystemTime(int which);
330
331 /**
332 * Returns the number of times the process has been started.
333 *
334 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
335 */
336 public abstract int getStarts(int which);
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700337
338 /**
339 * Returns the cpu time spent in microseconds while the process was in the foreground.
340 * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
341 * @return foreground cpu time in microseconds
342 */
343 public abstract long getForegroundTime(int which);
Amith Yamasanie43530a2009-08-21 13:11:37 -0700344
345 /**
346 * Returns the approximate cpu time spent in microseconds, at a certain CPU speed.
347 * @param speedStep the index of the CPU speed. This is not the actual speed of the
348 * CPU.
349 * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED
350 * @see BatteryStats#getCpuSpeedSteps()
351 */
352 public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700353
Dianne Hackborn287952c2010-09-22 22:34:31 -0700354 public abstract int countExcessivePowers();
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700355
Dianne Hackborn287952c2010-09-22 22:34:31 -0700356 public abstract ExcessivePower getExcessivePower(int i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 }
358
359 /**
360 * The statistics associated with a particular package.
361 */
362 public static abstract class Pkg {
363
364 /**
365 * Returns the number of times this package has done something that could wake up the
366 * device from sleep.
367 *
368 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
369 */
370 public abstract int getWakeups(int which);
371
372 /**
373 * Returns a mapping containing service statistics.
374 */
375 public abstract Map<String, ? extends Serv> getServiceStats();
376
377 /**
378 * The statistics associated with a particular service.
379 */
380 public abstract class Serv {
381
382 /**
383 * Returns the amount of time spent started.
384 *
385 * @param batteryUptime elapsed uptime on battery in microseconds.
386 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
387 * @return
388 */
389 public abstract long getStartTime(long batteryUptime, int which);
390
391 /**
392 * Returns the total number of times startService() has been called.
393 *
394 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
395 */
396 public abstract int getStarts(int which);
397
398 /**
399 * Returns the total number times the service has been launched.
400 *
401 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
402 */
403 public abstract int getLaunches(int which);
404 }
405 }
406 }
407
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700408 public final static class HistoryItem implements Parcelable {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700409 public HistoryItem next;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700410
411 public long time;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700412
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700413 public static final byte CMD_UPDATE = 0;
414 public static final byte CMD_START = 1;
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700415 public static final byte CMD_OVERFLOW = 2;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700416
417 public byte cmd;
418
419 public byte batteryLevel;
420 public byte batteryStatus;
421 public byte batteryHealth;
422 public byte batteryPlugType;
423
424 public char batteryTemperature;
425 public char batteryVoltage;
426
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700427 // Constants from SCREEN_BRIGHTNESS_*
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700428 public static final int STATE_BRIGHTNESS_MASK = 0x000000f;
429 public static final int STATE_BRIGHTNESS_SHIFT = 0;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700430 // Constants from SIGNAL_STRENGTH_*
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700431 public static final int STATE_SIGNAL_STRENGTH_MASK = 0x00000f0;
432 public static final int STATE_SIGNAL_STRENGTH_SHIFT = 4;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700433 // Constants from ServiceState.STATE_*
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700434 public static final int STATE_PHONE_STATE_MASK = 0x0000f00;
435 public static final int STATE_PHONE_STATE_SHIFT = 8;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700436 // Constants from DATA_CONNECTION_*
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700437 public static final int STATE_DATA_CONNECTION_MASK = 0x000f000;
438 public static final int STATE_DATA_CONNECTION_SHIFT = 12;
439
440 public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<30;
441 public static final int STATE_SCREEN_ON_FLAG = 1<<29;
442 public static final int STATE_GPS_ON_FLAG = 1<<28;
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700443 public static final int STATE_PHONE_IN_CALL_FLAG = 1<<27;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700444 public static final int STATE_PHONE_SCANNING_FLAG = 1<<26;
445 public static final int STATE_WIFI_ON_FLAG = 1<<25;
446 public static final int STATE_WIFI_RUNNING_FLAG = 1<<24;
447 public static final int STATE_WIFI_FULL_LOCK_FLAG = 1<<23;
448 public static final int STATE_WIFI_SCAN_LOCK_FLAG = 1<<22;
449 public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<21;
450 public static final int STATE_BLUETOOTH_ON_FLAG = 1<<20;
451 public static final int STATE_AUDIO_ON_FLAG = 1<<19;
452 public static final int STATE_VIDEO_ON_FLAG = 1<<18;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700453 public static final int STATE_WAKE_LOCK_FLAG = 1<<17;
454 public static final int STATE_SENSOR_ON_FLAG = 1<<16;
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700455
Dianne Hackbornf47d8f22010-10-08 10:46:55 -0700456 public static final int MOST_INTERESTING_STATES =
457 STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG
458 | STATE_GPS_ON_FLAG | STATE_PHONE_IN_CALL_FLAG;
459
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700460 public int states;
461
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700462 public HistoryItem() {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700463 }
464
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700465 public HistoryItem(long time, Parcel src) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700466 this.time = time;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700467 int bat = src.readInt();
468 cmd = (byte)(bat&0xff);
469 batteryLevel = (byte)((bat>>8)&0xff);
470 batteryStatus = (byte)((bat>>16)&0xf);
471 batteryHealth = (byte)((bat>>20)&0xf);
472 batteryPlugType = (byte)((bat>>24)&0xf);
473 bat = src.readInt();
474 batteryTemperature = (char)(bat&0xffff);
475 batteryVoltage = (char)((bat>>16)&0xffff);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700476 states = src.readInt();
477 }
478
479 public int describeContents() {
480 return 0;
481 }
482
483 public void writeToParcel(Parcel dest, int flags) {
484 dest.writeLong(time);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700485 int bat = (((int)cmd)&0xff)
486 | ((((int)batteryLevel)<<8)&0xff00)
487 | ((((int)batteryStatus)<<16)&0xf0000)
488 | ((((int)batteryHealth)<<20)&0xf00000)
489 | ((((int)batteryPlugType)<<24)&0xf000000);
490 dest.writeInt(bat);
491 bat = (((int)batteryTemperature)&0xffff)
492 | ((((int)batteryVoltage)<<16)&0xffff0000);
493 dest.writeInt(bat);
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700494 dest.writeInt(states);
495 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700496
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700497 public void setTo(HistoryItem o) {
498 time = o.time;
499 cmd = o.cmd;
500 batteryLevel = o.batteryLevel;
501 batteryStatus = o.batteryStatus;
502 batteryHealth = o.batteryHealth;
503 batteryPlugType = o.batteryPlugType;
504 batteryTemperature = o.batteryTemperature;
505 batteryVoltage = o.batteryVoltage;
506 states = o.states;
507 }
508
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700509 public void setTo(long time, byte cmd, HistoryItem o) {
510 this.time = time;
511 this.cmd = cmd;
512 batteryLevel = o.batteryLevel;
513 batteryStatus = o.batteryStatus;
514 batteryHealth = o.batteryHealth;
515 batteryPlugType = o.batteryPlugType;
516 batteryTemperature = o.batteryTemperature;
517 batteryVoltage = o.batteryVoltage;
518 states = o.states;
519 }
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700520
521 public boolean same(HistoryItem o) {
522 return batteryLevel == o.batteryLevel
523 && batteryStatus == o.batteryStatus
524 && batteryHealth == o.batteryHealth
525 && batteryPlugType == o.batteryPlugType
526 && batteryTemperature == o.batteryTemperature
527 && batteryVoltage == o.batteryVoltage
528 && states == o.states;
529 }
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700530 }
531
532 public static final class BitDescription {
533 public final int mask;
534 public final int shift;
535 public final String name;
536 public final String[] values;
537
538 public BitDescription(int mask, String name) {
539 this.mask = mask;
540 this.shift = -1;
541 this.name = name;
542 this.values = null;
543 }
544
545 public BitDescription(int mask, int shift, String name, String[] values) {
546 this.mask = mask;
547 this.shift = shift;
548 this.name = name;
549 this.values = values;
550 }
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700551 }
552
Dianne Hackbornce2ef762010-09-20 11:39:14 -0700553 public abstract boolean startIteratingHistoryLocked();
554
555 public abstract boolean getNextHistoryLocked(HistoryItem out);
556
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700557 /**
558 * Return the current history of battery state changes.
559 */
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700560 public abstract HistoryItem getHistory();
Dianne Hackborn32907cf2010-06-10 17:50:20 -0700561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 /**
Dianne Hackbornb5e31652010-09-07 12:13:55 -0700563 * Return the base time offset for the battery history.
564 */
565 public abstract long getHistoryBaseTime();
566
567 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 * Returns the number of times the device has been started.
569 */
570 public abstract int getStartCount();
571
572 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700573 * 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 -0800574 * running on battery.
575 *
576 * {@hide}
577 */
578 public abstract long getScreenOnTime(long batteryRealtime, int which);
579
Dianne Hackborn617f8772009-03-31 15:04:46 -0700580 public static final int SCREEN_BRIGHTNESS_DARK = 0;
581 public static final int SCREEN_BRIGHTNESS_DIM = 1;
582 public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
583 public static final int SCREEN_BRIGHTNESS_LIGHT = 3;
584 public static final int SCREEN_BRIGHTNESS_BRIGHT = 4;
585
586 static final String[] SCREEN_BRIGHTNESS_NAMES = {
587 "dark", "dim", "medium", "light", "bright"
588 };
589
590 public static final int NUM_SCREEN_BRIGHTNESS_BINS = 5;
591
592 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700593 * Returns the time in microseconds that the screen has been on with
Dianne Hackborn617f8772009-03-31 15:04:46 -0700594 * the given brightness
595 *
596 * {@hide}
597 */
598 public abstract long getScreenBrightnessTime(int brightnessBin,
599 long batteryRealtime, int which);
600
601 public abstract int getInputEventCount(int which);
602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700604 * 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 -0800605 * running on battery.
606 *
607 * {@hide}
608 */
609 public abstract long getPhoneOnTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700610
Dianne Hackborn627bba72009-03-24 22:32:56 -0700611 public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
612 public static final int SIGNAL_STRENGTH_POOR = 1;
613 public static final int SIGNAL_STRENGTH_MODERATE = 2;
614 public static final int SIGNAL_STRENGTH_GOOD = 3;
615 public static final int SIGNAL_STRENGTH_GREAT = 4;
616
617 static final String[] SIGNAL_STRENGTH_NAMES = {
618 "none", "poor", "moderate", "good", "great"
619 };
620
621 public static final int NUM_SIGNAL_STRENGTH_BINS = 5;
622
623 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700624 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -0700625 * the given signal strength.
626 *
627 * {@hide}
628 */
629 public abstract long getPhoneSignalStrengthTime(int strengthBin,
630 long batteryRealtime, int which);
631
Dianne Hackborn617f8772009-03-31 15:04:46 -0700632 /**
Amith Yamasanif37447b2009-10-08 18:28:01 -0700633 * Returns the time in microseconds that the phone has been trying to
634 * acquire a signal.
635 *
636 * {@hide}
637 */
638 public abstract long getPhoneSignalScanningTime(
639 long batteryRealtime, int which);
640
641 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700642 * Returns the number of times the phone has entered the given signal strength.
643 *
644 * {@hide}
645 */
646 public abstract int getPhoneSignalStrengthCount(int strengthBin, int which);
647
Dianne Hackborn627bba72009-03-24 22:32:56 -0700648 public static final int DATA_CONNECTION_NONE = 0;
649 public static final int DATA_CONNECTION_GPRS = 1;
650 public static final int DATA_CONNECTION_EDGE = 2;
651 public static final int DATA_CONNECTION_UMTS = 3;
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700652 public static final int DATA_CONNECTION_CDMA = 4;
653 public static final int DATA_CONNECTION_EVDO_0 = 5;
654 public static final int DATA_CONNECTION_EVDO_A = 6;
655 public static final int DATA_CONNECTION_1xRTT = 7;
656 public static final int DATA_CONNECTION_HSDPA = 8;
657 public static final int DATA_CONNECTION_HSUPA = 9;
658 public static final int DATA_CONNECTION_HSPA = 10;
659 public static final int DATA_CONNECTION_IDEN = 11;
660 public static final int DATA_CONNECTION_EVDO_B = 12;
661 public static final int DATA_CONNECTION_OTHER = 13;
Dianne Hackborn627bba72009-03-24 22:32:56 -0700662
663 static final String[] DATA_CONNECTION_NAMES = {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700664 "none", "gprs", "edge", "umts", "cdma", "evdo_0", "evdo_A",
665 "1xrtt", "hsdpa", "hsupa", "hspa", "iden", "evdo_b", "other"
Dianne Hackborn627bba72009-03-24 22:32:56 -0700666 };
667
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700668 public static final int NUM_DATA_CONNECTION_TYPES = DATA_CONNECTION_OTHER+1;
Dianne Hackborn627bba72009-03-24 22:32:56 -0700669
670 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700671 * Returns the time in microseconds that the phone has been running with
Dianne Hackborn627bba72009-03-24 22:32:56 -0700672 * the given data connection.
673 *
674 * {@hide}
675 */
676 public abstract long getPhoneDataConnectionTime(int dataType,
677 long batteryRealtime, int which);
678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 /**
Dianne Hackborn617f8772009-03-31 15:04:46 -0700680 * Returns the number of times the phone has entered the given data
681 * connection type.
682 *
683 * {@hide}
684 */
685 public abstract int getPhoneDataConnectionCount(int dataType, int which);
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700686
687 public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
688 = new BitDescription[] {
689 new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged"),
690 new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen"),
691 new BitDescription(HistoryItem.STATE_GPS_ON_FLAG, "gps"),
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700692 new BitDescription(HistoryItem.STATE_PHONE_IN_CALL_FLAG, "phone_in_call"),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700693 new BitDescription(HistoryItem.STATE_PHONE_SCANNING_FLAG, "phone_scanning"),
694 new BitDescription(HistoryItem.STATE_WIFI_ON_FLAG, "wifi"),
695 new BitDescription(HistoryItem.STATE_WIFI_RUNNING_FLAG, "wifi_running"),
696 new BitDescription(HistoryItem.STATE_WIFI_FULL_LOCK_FLAG, "wifi_full_lock"),
697 new BitDescription(HistoryItem.STATE_WIFI_SCAN_LOCK_FLAG, "wifi_scan_lock"),
698 new BitDescription(HistoryItem.STATE_WIFI_MULTICAST_ON_FLAG, "wifi_multicast"),
699 new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth"),
700 new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio"),
701 new BitDescription(HistoryItem.STATE_VIDEO_ON_FLAG, "video"),
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700702 new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock"),
703 new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor"),
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700704 new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
705 HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness",
706 SCREEN_BRIGHTNESS_NAMES),
707 new BitDescription(HistoryItem.STATE_SIGNAL_STRENGTH_MASK,
708 HistoryItem.STATE_SIGNAL_STRENGTH_SHIFT, "signal_strength",
709 SIGNAL_STRENGTH_NAMES),
710 new BitDescription(HistoryItem.STATE_PHONE_STATE_MASK,
711 HistoryItem.STATE_PHONE_STATE_SHIFT, "phone_state",
712 new String[] {"in", "out", "emergency", "off"}),
713 new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
714 HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn",
715 DATA_CONNECTION_NAMES),
716 };
Dianne Hackborn617f8772009-03-31 15:04:46 -0700717
718 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700719 * Returns the time in microseconds that wifi has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -0700720 * running on battery.
721 *
722 * {@hide}
723 */
724 public abstract long getWifiOnTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700725
726 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700727 * Returns the time in microseconds that wifi has been on and the driver has
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700728 * been in the running state while the device was running on battery.
729 *
730 * {@hide}
731 */
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700732 public abstract long getGlobalWifiRunningTime(long batteryRealtime, int which);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700733
The Android Open Source Project10592532009-03-18 17:39:46 -0700734 /**
Amith Yamasanieaeb6632009-06-03 15:16:10 -0700735 * Returns the time in microseconds that bluetooth has been on while the device was
The Android Open Source Project10592532009-03-18 17:39:46 -0700736 * running on battery.
737 *
738 * {@hide}
739 */
740 public abstract long getBluetoothOnTime(long batteryRealtime, int which);
741
742 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 * Return whether we are currently running on battery.
744 */
745 public abstract boolean getIsOnBattery();
746
747 /**
748 * Returns a SparseArray containing the statistics for each uid.
749 */
750 public abstract SparseArray<? extends Uid> getUidStats();
751
752 /**
753 * Returns the current battery uptime in microseconds.
754 *
755 * @param curTime the amount of elapsed realtime in microseconds.
756 */
757 public abstract long getBatteryUptime(long curTime);
758
759 /**
Amith Yamasani3f7e35c2009-07-13 16:02:45 -0700760 * @deprecated use getRadioDataUptime
761 */
762 public long getRadioDataUptimeMs() {
763 return getRadioDataUptime() / 1000;
764 }
765
766 /**
767 * Returns the time that the radio was on for data transfers.
768 * @return the uptime in microseconds while unplugged
769 */
770 public abstract long getRadioDataUptime();
771
772 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 * Returns the current battery realtime in microseconds.
774 *
775 * @param curTime the amount of elapsed realtime in microseconds.
776 */
777 public abstract long getBatteryRealtime(long curTime);
The Android Open Source Project10592532009-03-18 17:39:46 -0700778
779 /**
Evan Millar633a1742009-04-02 16:36:33 -0700780 * Returns the battery percentage level at the last time the device was unplugged from power, or
781 * the last time it booted on battery power.
The Android Open Source Project10592532009-03-18 17:39:46 -0700782 */
Evan Millar633a1742009-04-02 16:36:33 -0700783 public abstract int getDischargeStartLevel();
The Android Open Source Project10592532009-03-18 17:39:46 -0700784
785 /**
Evan Millar633a1742009-04-02 16:36:33 -0700786 * Returns the current battery percentage level if we are in a discharge cycle, otherwise
787 * returns the level at the last plug event.
The Android Open Source Project10592532009-03-18 17:39:46 -0700788 */
Evan Millar633a1742009-04-02 16:36:33 -0700789 public abstract int getDischargeCurrentLevel();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790
791 /**
Dianne Hackborn3bee5af82010-07-23 00:22:04 -0700792 * Get the amount the battery has discharged since the stats were
793 * last reset after charging, as a lower-end approximation.
794 */
795 public abstract int getLowDischargeAmountSinceCharge();
796
797 /**
798 * Get the amount the battery has discharged since the stats were
799 * last reset after charging, as an upper-end approximation.
800 */
801 public abstract int getHighDischargeAmountSinceCharge();
802
803 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 * Returns the total, last, or current battery uptime in microseconds.
805 *
806 * @param curTime the elapsed realtime in microseconds.
807 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
808 */
809 public abstract long computeBatteryUptime(long curTime, int which);
810
811 /**
812 * Returns the total, last, or current battery realtime in microseconds.
813 *
814 * @param curTime the current elapsed realtime in microseconds.
815 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
816 */
817 public abstract long computeBatteryRealtime(long curTime, int which);
818
819 /**
820 * Returns the total, last, or current uptime in microseconds.
821 *
822 * @param curTime the current elapsed realtime in microseconds.
823 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
824 */
825 public abstract long computeUptime(long curTime, int which);
826
827 /**
828 * Returns the total, last, or current realtime in microseconds.
829 * *
830 * @param curTime the current elapsed realtime in microseconds.
831 * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
832 */
833 public abstract long computeRealtime(long curTime, int which);
Evan Millarc64edde2009-04-18 12:26:32 -0700834
835 public abstract Map<String, ? extends Timer> getKernelWakelockStats();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836
Amith Yamasanie43530a2009-08-21 13:11:37 -0700837 /** Returns the number of different speeds that the CPU can run at */
838 public abstract int getCpuSpeedSteps();
839
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700840 private final static void formatTimeRaw(StringBuilder out, long seconds) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 long days = seconds / (60 * 60 * 24);
842 if (days != 0) {
843 out.append(days);
844 out.append("d ");
845 }
846 long used = days * 60 * 60 * 24;
847
848 long hours = (seconds - used) / (60 * 60);
849 if (hours != 0 || used != 0) {
850 out.append(hours);
851 out.append("h ");
852 }
853 used += hours * 60 * 60;
854
855 long mins = (seconds-used) / 60;
856 if (mins != 0 || used != 0) {
857 out.append(mins);
858 out.append("m ");
859 }
860 used += mins * 60;
861
862 if (seconds != 0 || used != 0) {
863 out.append(seconds-used);
864 out.append("s ");
865 }
866 }
867
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700868 private final static void formatTime(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 long sec = time / 100;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700870 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871 sb.append((time - (sec * 100)) * 10);
872 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 }
874
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700875 private final static void formatTimeMs(StringBuilder sb, long time) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 long sec = time / 1000;
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700877 formatTimeRaw(sb, sec);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 sb.append(time - (sec * 1000));
879 sb.append("ms ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 }
881
882 private final String formatRatioLocked(long num, long den) {
883 if (den == 0L) {
884 return "---%";
885 }
886 float perc = ((float)num) / ((float)den) * 100;
887 mFormatBuilder.setLength(0);
888 mFormatter.format("%.1f%%", perc);
889 return mFormatBuilder.toString();
890 }
891
Evan Millar22ac0432009-03-31 11:33:18 -0700892 private final String formatBytesLocked(long bytes) {
893 mFormatBuilder.setLength(0);
894
895 if (bytes < BYTES_PER_KB) {
896 return bytes + "B";
897 } else if (bytes < BYTES_PER_MB) {
898 mFormatter.format("%.2fKB", bytes / (double) BYTES_PER_KB);
899 return mFormatBuilder.toString();
900 } else if (bytes < BYTES_PER_GB){
901 mFormatter.format("%.2fMB", bytes / (double) BYTES_PER_MB);
902 return mFormatBuilder.toString();
903 } else {
904 mFormatter.format("%.2fGB", bytes / (double) BYTES_PER_GB);
905 return mFormatBuilder.toString();
906 }
907 }
908
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 /**
910 *
911 * @param sb a StringBuilder object.
912 * @param timer a Timer object contining the wakelock times.
913 * @param batteryRealtime the current on-battery time in microseconds.
914 * @param name the name of the wakelock.
915 * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
916 * @param linePrefix a String to be prepended to each line of output.
917 * @return the line prefix
918 */
919 private static final String printWakeLock(StringBuilder sb, Timer timer,
920 long batteryRealtime, String name, int which, String linePrefix) {
921
922 if (timer != null) {
923 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -0700924 long totalTimeMicros = timer.getTotalTimeLocked(batteryRealtime, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 long totalTimeMillis = (totalTimeMicros + 500) / 1000;
926
Evan Millarc64edde2009-04-18 12:26:32 -0700927 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 if (totalTimeMillis != 0) {
929 sb.append(linePrefix);
Dianne Hackborn1d442e02009-04-20 18:14:05 -0700930 formatTimeMs(sb, totalTimeMillis);
931 if (name != null) sb.append(name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 sb.append(' ');
933 sb.append('(');
934 sb.append(count);
935 sb.append(" times)");
936 return ", ";
937 }
938 }
939 return linePrefix;
940 }
941
942 /**
943 * Checkin version of wakelock printer. Prints simple comma-separated list.
944 *
945 * @param sb a StringBuilder object.
946 * @param timer a Timer object contining the wakelock times.
947 * @param now the current time in microseconds.
948 * @param name the name of the wakelock.
949 * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT.
950 * @param linePrefix a String to be prepended to each line of output.
951 * @return the line prefix
952 */
953 private static final String printWakeLockCheckin(StringBuilder sb, Timer timer, long now,
Evan Millarc64edde2009-04-18 12:26:32 -0700954 String name, int which, String linePrefix) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 long totalTimeMicros = 0;
956 int count = 0;
957 if (timer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -0700958 totalTimeMicros = timer.getTotalTimeLocked(now, which);
959 count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 }
961 sb.append(linePrefix);
962 sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
963 sb.append(',');
Evan Millarc64edde2009-04-18 12:26:32 -0700964 sb.append(name != null ? name + "," : "");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 sb.append(count);
966 return ",";
967 }
968
969 /**
970 * Dump a comma-separated line of values for terse checkin mode.
971 *
972 * @param pw the PageWriter to dump log to
973 * @param category category of data (e.g. "total", "last", "unplugged", "current" )
974 * @param type type of data (e.g. "wakelock", "sensor", "process", "apk" , "process", "network")
975 * @param args type-dependent data arguments
976 */
977 private static final void dumpLine(PrintWriter pw, int uid, String category, String type,
978 Object... args ) {
979 pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
980 pw.print(uid); pw.print(',');
981 pw.print(category); pw.print(',');
982 pw.print(type);
983
984 for (Object arg : args) {
985 pw.print(',');
986 pw.print(arg);
987 }
988 pw.print('\n');
989 }
990
991 /**
992 * Checkin server version of dump to produce more compact, computer-readable log.
993 *
994 * NOTE: all times are expressed in 'ms'.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 */
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800996 public final void dumpCheckinLocked(PrintWriter pw, int which, int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 final long rawUptime = SystemClock.uptimeMillis() * 1000;
998 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
999 final long batteryUptime = getBatteryUptime(rawUptime);
1000 final long batteryRealtime = getBatteryRealtime(rawRealtime);
1001 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
1002 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
1003 final long totalRealtime = computeRealtime(rawRealtime, which);
1004 final long totalUptime = computeUptime(rawUptime, which);
1005 final long screenOnTime = getScreenOnTime(batteryRealtime, which);
1006 final long phoneOnTime = getPhoneOnTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001007 final long wifiOnTime = getWifiOnTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001008 final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001009 final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010
1011 StringBuilder sb = new StringBuilder(128);
1012
Evan Millar22ac0432009-03-31 11:33:18 -07001013 SparseArray<? extends Uid> uidStats = getUidStats();
1014 final int NU = uidStats.size();
1015
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 String category = STAT_NAMES[which];
1017
1018 // Dump "battery" stat
1019 dumpLine(pw, 0 /* uid */, category, BATTERY_DATA,
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001020 which == STATS_SINCE_CHARGED ? getStartCount() : "N/A",
Dianne Hackborn617f8772009-03-31 15:04:46 -07001021 whichBatteryRealtime / 1000, whichBatteryUptime / 1000,
1022 totalRealtime / 1000, totalUptime / 1000);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023
Evan Millar22ac0432009-03-31 11:33:18 -07001024 // Calculate total network and wakelock times across all uids.
1025 long rxTotal = 0;
1026 long txTotal = 0;
1027 long fullWakeLockTimeTotal = 0;
1028 long partialWakeLockTimeTotal = 0;
1029
1030 for (int iu = 0; iu < NU; iu++) {
1031 Uid u = uidStats.valueAt(iu);
1032 rxTotal += u.getTcpBytesReceived(which);
1033 txTotal += u.getTcpBytesSent(which);
1034
1035 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1036 if (wakelocks.size() > 0) {
1037 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1038 : wakelocks.entrySet()) {
1039 Uid.Wakelock wl = ent.getValue();
1040
1041 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
1042 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001043 fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(batteryRealtime, which);
Evan Millar22ac0432009-03-31 11:33:18 -07001044 }
1045
1046 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
1047 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001048 partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001049 batteryRealtime, which);
1050 }
1051 }
1052 }
1053 }
1054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 // Dump misc stats
1056 dumpLine(pw, 0 /* uid */, category, MISC_DATA,
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001057 screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000,
Evan Millar22ac0432009-03-31 11:33:18 -07001058 wifiRunningTime / 1000, bluetoothOnTime / 1000, rxTotal, txTotal,
Dianne Hackborn617f8772009-03-31 15:04:46 -07001059 fullWakeLockTimeTotal, partialWakeLockTimeTotal,
1060 getInputEventCount(which));
1061
1062 // Dump screen brightness stats
1063 Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
1064 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1065 args[i] = getScreenBrightnessTime(i, batteryRealtime, which) / 1000;
1066 }
1067 dumpLine(pw, 0 /* uid */, category, SCREEN_BRIGHTNESS_DATA, args);
The Android Open Source Project10592532009-03-18 17:39:46 -07001068
Dianne Hackborn627bba72009-03-24 22:32:56 -07001069 // Dump signal strength stats
Dianne Hackborn617f8772009-03-31 15:04:46 -07001070 args = new Object[NUM_SIGNAL_STRENGTH_BINS];
Dianne Hackborn627bba72009-03-24 22:32:56 -07001071 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
1072 args[i] = getPhoneSignalStrengthTime(i, batteryRealtime, which) / 1000;
1073 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001074 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args);
Amith Yamasanif37447b2009-10-08 18:28:01 -07001075 dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA,
1076 getPhoneSignalScanningTime(batteryRealtime, which) / 1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001077 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
1078 args[i] = getPhoneSignalStrengthCount(i, which);
1079 }
1080 dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_COUNT_DATA, args);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001081
1082 // Dump network type stats
1083 args = new Object[NUM_DATA_CONNECTION_TYPES];
1084 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1085 args[i] = getPhoneDataConnectionTime(i, batteryRealtime, which) / 1000;
1086 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001087 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_TIME_DATA, args);
1088 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1089 args[i] = getPhoneDataConnectionCount(i, which);
1090 }
1091 dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001092
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001093 if (which == STATS_SINCE_UNPLUGGED) {
Evan Millare84de8d2009-04-02 22:16:12 -07001094 dumpLine(pw, 0 /* uid */, category, BATTERY_LEVEL_DATA, getDischargeStartLevel(),
Evan Millar633a1742009-04-02 16:36:33 -07001095 getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07001096 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001098 if (reqUid < 0) {
1099 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
1100 if (kernelWakelocks.size() > 0) {
1101 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
1102 sb.setLength(0);
1103 printWakeLockCheckin(sb, ent.getValue(), batteryRealtime, null, which, "");
1104
1105 dumpLine(pw, 0 /* uid */, category, KERNEL_WAKELOCK_DATA, ent.getKey(),
1106 sb.toString());
1107 }
Evan Millarc64edde2009-04-18 12:26:32 -07001108 }
1109 }
1110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 for (int iu = 0; iu < NU; iu++) {
1112 final int uid = uidStats.keyAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001113 if (reqUid >= 0 && uid != reqUid) {
1114 continue;
1115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 Uid u = uidStats.valueAt(iu);
1117 // Dump Network stats per uid, if any
1118 long rx = u.getTcpBytesReceived(which);
1119 long tx = u.getTcpBytesSent(which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001120 long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which);
1121 long scanWifiLockOnTime = u.getScanWifiLockTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001122 long uidWifiRunningTime = u.getWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 if (rx > 0 || tx > 0) dumpLine(pw, uid, category, NETWORK_DATA, rx, tx);
The Android Open Source Project10592532009-03-18 17:39:46 -07001125
Dianne Hackborn617f8772009-03-31 15:04:46 -07001126 if (fullWifiLockOnTime != 0 || scanWifiLockOnTime != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001127 || uidWifiRunningTime != 0) {
The Android Open Source Project10592532009-03-18 17:39:46 -07001128 dumpLine(pw, uid, category, WIFI_LOCK_DATA,
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001129 fullWifiLockOnTime, scanWifiLockOnTime, uidWifiRunningTime);
The Android Open Source Project10592532009-03-18 17:39:46 -07001130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131
Dianne Hackborn617f8772009-03-31 15:04:46 -07001132 if (u.hasUserActivity()) {
1133 args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
1134 boolean hasData = false;
1135 for (int i=0; i<Uid.NUM_USER_ACTIVITY_TYPES; i++) {
1136 int val = u.getUserActivityCount(i, which);
1137 args[i] = val;
1138 if (val != 0) hasData = true;
1139 }
1140 if (hasData) {
1141 dumpLine(pw, 0 /* uid */, category, USER_ACTIVITY_DATA, args);
1142 }
1143 }
1144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1146 if (wakelocks.size() > 0) {
1147 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1148 : wakelocks.entrySet()) {
1149 Uid.Wakelock wl = ent.getValue();
1150 String linePrefix = "";
1151 sb.setLength(0);
Evan Millarc64edde2009-04-18 12:26:32 -07001152 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL),
1153 batteryRealtime, "f", which, linePrefix);
1154 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL),
1155 batteryRealtime, "p", which, linePrefix);
1156 linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW),
1157 batteryRealtime, "w", which, linePrefix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001158
1159 // Only log if we had at lease one wakelock...
1160 if (sb.length() > 0) {
1161 dumpLine(pw, uid, category, WAKELOCK_DATA, ent.getKey(), sb.toString());
1162 }
1163 }
1164 }
1165
1166 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
1167 if (sensors.size() > 0) {
1168 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
1169 : sensors.entrySet()) {
1170 Uid.Sensor se = ent.getValue();
1171 int sensorNumber = ent.getKey();
1172 Timer timer = se.getSensorTime();
1173 if (timer != null) {
1174 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -07001175 long totalTime = (timer.getTotalTimeLocked(batteryRealtime, which) + 500) / 1000;
1176 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 if (totalTime != 0) {
1178 dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
1179 }
1180 }
1181 }
1182 }
1183
1184 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
1185 if (processStats.size() > 0) {
1186 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
1187 : processStats.entrySet()) {
1188 Uid.Proc ps = ent.getValue();
1189
1190 long userTime = ps.getUserTime(which);
1191 long systemTime = ps.getSystemTime(which);
1192 int starts = ps.getStarts(which);
1193
1194 if (userTime != 0 || systemTime != 0 || starts != 0) {
1195 dumpLine(pw, uid, category, PROCESS_DATA,
1196 ent.getKey(), // proc
1197 userTime * 10, // cpu time in ms
1198 systemTime * 10, // user time in ms
1199 starts); // process starts
1200 }
1201 }
1202 }
1203
1204 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
1205 if (packageStats.size() > 0) {
1206 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
1207 : packageStats.entrySet()) {
1208
1209 Uid.Pkg ps = ent.getValue();
1210 int wakeups = ps.getWakeups(which);
1211 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
1212 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
1213 : serviceStats.entrySet()) {
1214 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
1215 long startTime = ss.getStartTime(batteryUptime, which);
1216 int starts = ss.getStarts(which);
1217 int launches = ss.getLaunches(which);
1218 if (startTime != 0 || starts != 0 || launches != 0) {
1219 dumpLine(pw, uid, category, APK_DATA,
1220 wakeups, // wakeup alarms
1221 ent.getKey(), // Apk
1222 sent.getKey(), // service
1223 startTime / 1000, // time spent started, in ms
1224 starts,
1225 launches);
1226 }
1227 }
1228 }
1229 }
1230 }
1231 }
1232
1233 @SuppressWarnings("unused")
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001234 public final void dumpLocked(PrintWriter pw, String prefix, int which, int reqUid) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 final long rawUptime = SystemClock.uptimeMillis() * 1000;
1236 final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
1237 final long batteryUptime = getBatteryUptime(rawUptime);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -07001238 final long batteryRealtime = getBatteryRealtime(rawRealtime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239
1240 final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
1241 final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
1242 final long totalRealtime = computeRealtime(rawRealtime, which);
1243 final long totalUptime = computeUptime(rawUptime, which);
1244
1245 StringBuilder sb = new StringBuilder(128);
Evan Millar22ac0432009-03-31 11:33:18 -07001246
1247 SparseArray<? extends Uid> uidStats = getUidStats();
1248 final int NU = uidStats.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001250 sb.setLength(0);
1251 sb.append(prefix);
1252 sb.append(" Time on battery: ");
1253 formatTimeMs(sb, whichBatteryRealtime / 1000); sb.append("(");
1254 sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
1255 sb.append(") realtime, ");
1256 formatTimeMs(sb, whichBatteryUptime / 1000);
1257 sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
1258 sb.append(") uptime");
1259 pw.println(sb.toString());
1260 sb.setLength(0);
1261 sb.append(prefix);
1262 sb.append(" Total run time: ");
1263 formatTimeMs(sb, totalRealtime / 1000);
1264 sb.append("realtime, ");
1265 formatTimeMs(sb, totalUptime / 1000);
1266 sb.append("uptime, ");
1267 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268
The Android Open Source Project10592532009-03-18 17:39:46 -07001269 final long screenOnTime = getScreenOnTime(batteryRealtime, which);
1270 final long phoneOnTime = getPhoneOnTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001271 final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001272 final long wifiOnTime = getWifiOnTime(batteryRealtime, which);
1273 final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001274 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001275 sb.append(prefix);
1276 sb.append(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
1277 sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
1278 sb.append("), Input events: "); sb.append(getInputEventCount(which));
1279 sb.append(", Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
1280 sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
1281 sb.append(")");
1282 pw.println(sb.toString());
1283 sb.setLength(0);
1284 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001285 sb.append(" Screen brightnesses: ");
1286 boolean didOne = false;
1287 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1288 final long time = getScreenBrightnessTime(i, batteryRealtime, which);
1289 if (time == 0) {
1290 continue;
1291 }
1292 if (didOne) sb.append(", ");
1293 didOne = true;
1294 sb.append(SCREEN_BRIGHTNESS_NAMES[i]);
1295 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001296 formatTimeMs(sb, time/1000);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001297 sb.append("(");
1298 sb.append(formatRatioLocked(time, screenOnTime));
1299 sb.append(")");
1300 }
1301 if (!didOne) sb.append("No activity");
1302 pw.println(sb.toString());
The Android Open Source Project10592532009-03-18 17:39:46 -07001303
Evan Millar22ac0432009-03-31 11:33:18 -07001304 // Calculate total network and wakelock times across all uids.
1305 long rxTotal = 0;
1306 long txTotal = 0;
1307 long fullWakeLockTimeTotalMicros = 0;
1308 long partialWakeLockTimeTotalMicros = 0;
1309
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001310 if (reqUid < 0) {
1311 Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
1312 if (kernelWakelocks.size() > 0) {
1313 for (Map.Entry<String, ? extends BatteryStats.Timer> ent : kernelWakelocks.entrySet()) {
1314
1315 String linePrefix = ": ";
1316 sb.setLength(0);
1317 sb.append(prefix);
1318 sb.append(" Kernel Wake lock ");
1319 sb.append(ent.getKey());
1320 linePrefix = printWakeLock(sb, ent.getValue(), batteryRealtime, null, which,
1321 linePrefix);
1322 if (!linePrefix.equals(": ")) {
1323 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05001324 // Only print out wake locks that were held
1325 pw.println(sb.toString());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001326 }
Evan Millarc64edde2009-04-18 12:26:32 -07001327 }
Evan Millarc64edde2009-04-18 12:26:32 -07001328 }
1329 }
1330
Evan Millar22ac0432009-03-31 11:33:18 -07001331 for (int iu = 0; iu < NU; iu++) {
1332 Uid u = uidStats.valueAt(iu);
1333 rxTotal += u.getTcpBytesReceived(which);
1334 txTotal += u.getTcpBytesSent(which);
1335
1336 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1337 if (wakelocks.size() > 0) {
1338 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1339 : wakelocks.entrySet()) {
1340 Uid.Wakelock wl = ent.getValue();
1341
1342 Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
1343 if (fullWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001344 fullWakeLockTimeTotalMicros += fullWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001345 batteryRealtime, which);
1346 }
1347
1348 Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
1349 if (partialWakeTimer != null) {
Evan Millarc64edde2009-04-18 12:26:32 -07001350 partialWakeLockTimeTotalMicros += partialWakeTimer.getTotalTimeLocked(
Evan Millar22ac0432009-03-31 11:33:18 -07001351 batteryRealtime, which);
1352 }
1353 }
1354 }
1355 }
1356
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001357 pw.print(prefix);
1358 pw.print(" Total received: "); pw.print(formatBytesLocked(rxTotal));
1359 pw.print(", Total sent: "); pw.println(formatBytesLocked(txTotal));
1360 sb.setLength(0);
1361 sb.append(prefix);
1362 sb.append(" Total full wakelock time: "); formatTimeMs(sb,
1363 (fullWakeLockTimeTotalMicros + 500) / 1000);
1364 sb.append(", Total partial waklock time: "); formatTimeMs(sb,
1365 (partialWakeLockTimeTotalMicros + 500) / 1000);
1366 pw.println(sb.toString());
Evan Millar22ac0432009-03-31 11:33:18 -07001367
Dianne Hackborn627bba72009-03-24 22:32:56 -07001368 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001369 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001370 sb.append(" Signal levels: ");
1371 didOne = false;
Dianne Hackborn627bba72009-03-24 22:32:56 -07001372 for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) {
1373 final long time = getPhoneSignalStrengthTime(i, batteryRealtime, which);
1374 if (time == 0) {
1375 continue;
1376 }
1377 if (didOne) sb.append(", ");
1378 didOne = true;
1379 sb.append(SIGNAL_STRENGTH_NAMES[i]);
1380 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001381 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001382 sb.append("(");
1383 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07001384 sb.append(") ");
1385 sb.append(getPhoneSignalStrengthCount(i, which));
1386 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001387 }
1388 if (!didOne) sb.append("No activity");
1389 pw.println(sb.toString());
Amith Yamasanif37447b2009-10-08 18:28:01 -07001390
1391 sb.setLength(0);
1392 sb.append(prefix);
1393 sb.append(" Signal scanning time: ");
1394 formatTimeMs(sb, getPhoneSignalScanningTime(batteryRealtime, which) / 1000);
1395 pw.println(sb.toString());
1396
Dianne Hackborn627bba72009-03-24 22:32:56 -07001397 sb.setLength(0);
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001398 sb.append(prefix);
Dianne Hackborn617f8772009-03-31 15:04:46 -07001399 sb.append(" Radio types: ");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001400 didOne = false;
1401 for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) {
1402 final long time = getPhoneDataConnectionTime(i, batteryRealtime, which);
1403 if (time == 0) {
1404 continue;
1405 }
1406 if (didOne) sb.append(", ");
1407 didOne = true;
1408 sb.append(DATA_CONNECTION_NAMES[i]);
1409 sb.append(" ");
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001410 formatTimeMs(sb, time/1000);
Dianne Hackborn627bba72009-03-24 22:32:56 -07001411 sb.append("(");
1412 sb.append(formatRatioLocked(time, whichBatteryRealtime));
Dianne Hackborn617f8772009-03-31 15:04:46 -07001413 sb.append(") ");
1414 sb.append(getPhoneDataConnectionCount(i, which));
1415 sb.append("x");
Dianne Hackborn627bba72009-03-24 22:32:56 -07001416 }
1417 if (!didOne) sb.append("No activity");
1418 pw.println(sb.toString());
Amith Yamasani3f7e35c2009-07-13 16:02:45 -07001419
1420 sb.setLength(0);
1421 sb.append(prefix);
1422 sb.append(" Radio data uptime when unplugged: ");
1423 sb.append(getRadioDataUptime() / 1000);
1424 sb.append(" ms");
1425 pw.println(sb.toString());
1426
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001427 sb.setLength(0);
1428 sb.append(prefix);
1429 sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);
1430 sb.append("("); sb.append(formatRatioLocked(wifiOnTime, whichBatteryRealtime));
1431 sb.append("), Wifi running: "); formatTimeMs(sb, wifiRunningTime / 1000);
1432 sb.append("("); sb.append(formatRatioLocked(wifiRunningTime, whichBatteryRealtime));
1433 sb.append("), Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
1434 sb.append("("); sb.append(formatRatioLocked(bluetoothOnTime, whichBatteryRealtime));
1435 sb.append(")");
1436 pw.println(sb.toString());
Dianne Hackborn617f8772009-03-31 15:04:46 -07001437
The Android Open Source Project10592532009-03-18 17:39:46 -07001438 pw.println(" ");
1439
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001440 if (which == STATS_SINCE_UNPLUGGED) {
The Android Open Source Project10592532009-03-18 17:39:46 -07001441 if (getIsOnBattery()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001442 pw.print(prefix); pw.println(" Device is currently unplugged");
1443 pw.print(prefix); pw.print(" Discharge cycle start level: ");
1444 pw.println(getDischargeStartLevel());
1445 pw.print(prefix); pw.print(" Discharge cycle current level: ");
1446 pw.println(getDischargeCurrentLevel());
Dianne Hackborn99d04522010-08-20 13:43:00 -07001447 } else {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001448 pw.print(prefix); pw.println(" Device is currently plugged into power");
1449 pw.print(prefix); pw.print(" Last discharge cycle start level: ");
1450 pw.println(getDischargeStartLevel());
1451 pw.print(prefix); pw.print(" Last discharge cycle end level: ");
1452 pw.println(getDischargeCurrentLevel());
The Android Open Source Project10592532009-03-18 17:39:46 -07001453 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001454 pw.println(" ");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001455 } else {
1456 pw.print(prefix); pw.println(" Device battery use since last full charge");
1457 pw.print(prefix); pw.print(" Amount discharged (lower bound): ");
1458 pw.println(getLowDischargeAmountSinceCharge());
1459 pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
1460 pw.println(getHighDischargeAmountSinceCharge());
1461 pw.println(" ");
The Android Open Source Project10592532009-03-18 17:39:46 -07001462 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001463
Evan Millar22ac0432009-03-31 11:33:18 -07001464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 for (int iu=0; iu<NU; iu++) {
1466 final int uid = uidStats.keyAt(iu);
Dianne Hackborne4a59512010-12-07 11:08:07 -08001467 if (reqUid >= 0 && uid != reqUid && uid != Process.SYSTEM_UID) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001468 continue;
1469 }
1470
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 Uid u = uidStats.valueAt(iu);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 pw.println(prefix + " #" + uid + ":");
1474 boolean uidActivity = false;
1475
1476 long tcpReceived = u.getTcpBytesReceived(which);
1477 long tcpSent = u.getTcpBytesSent(which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001478 long fullWifiLockOnTime = u.getFullWifiLockTime(batteryRealtime, which);
1479 long scanWifiLockOnTime = u.getScanWifiLockTime(batteryRealtime, which);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001480 long uidWifiRunningTime = u.getWifiRunningTime(batteryRealtime, which);
The Android Open Source Project10592532009-03-18 17:39:46 -07001481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001482 if (tcpReceived != 0 || tcpSent != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001483 pw.print(prefix); pw.print(" Network: ");
1484 pw.print(formatBytesLocked(tcpReceived)); pw.print(" received, ");
1485 pw.print(formatBytesLocked(tcpSent)); pw.println(" sent");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 }
Dianne Hackborn617f8772009-03-31 15:04:46 -07001487
1488 if (u.hasUserActivity()) {
1489 boolean hasData = false;
1490 for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
1491 int val = u.getUserActivityCount(i, which);
1492 if (val != 0) {
1493 if (!hasData) {
1494 sb.setLength(0);
1495 sb.append(" User activity: ");
1496 hasData = true;
1497 } else {
1498 sb.append(", ");
1499 }
1500 sb.append(val);
1501 sb.append(" ");
1502 sb.append(Uid.USER_ACTIVITY_TYPES[i]);
1503 }
1504 }
1505 if (hasData) {
1506 pw.println(sb.toString());
1507 }
1508 }
1509
1510 if (fullWifiLockOnTime != 0 || scanWifiLockOnTime != 0
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001511 || uidWifiRunningTime != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001512 sb.setLength(0);
Dianne Hackborn58e0eef2010-09-16 01:22:10 -07001513 sb.append(prefix); sb.append(" Wifi Running: ");
1514 formatTimeMs(sb, uidWifiRunningTime / 1000);
1515 sb.append("("); sb.append(formatRatioLocked(uidWifiRunningTime,
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001516 whichBatteryRealtime)); sb.append(")\n");
1517 sb.append(prefix); sb.append(" Full Wifi Lock: ");
1518 formatTimeMs(sb, fullWifiLockOnTime / 1000);
1519 sb.append("("); sb.append(formatRatioLocked(fullWifiLockOnTime,
1520 whichBatteryRealtime)); sb.append(")\n");
1521 sb.append(prefix); sb.append(" Scan Wifi Lock: ");
1522 formatTimeMs(sb, scanWifiLockOnTime / 1000);
1523 sb.append("("); sb.append(formatRatioLocked(scanWifiLockOnTime,
1524 whichBatteryRealtime)); sb.append(")");
1525 pw.println(sb.toString());
The Android Open Source Project10592532009-03-18 17:39:46 -07001526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527
1528 Map<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
1529 if (wakelocks.size() > 0) {
1530 for (Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> ent
1531 : wakelocks.entrySet()) {
1532 Uid.Wakelock wl = ent.getValue();
1533 String linePrefix = ": ";
1534 sb.setLength(0);
1535 sb.append(prefix);
1536 sb.append(" Wake lock ");
1537 sb.append(ent.getKey());
1538 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_FULL), batteryRealtime,
1539 "full", which, linePrefix);
1540 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), batteryRealtime,
1541 "partial", which, linePrefix);
1542 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), batteryRealtime,
1543 "window", which, linePrefix);
1544 if (!linePrefix.equals(": ")) {
1545 sb.append(" realtime");
Jason Parks94b916d2010-07-20 12:39:07 -05001546 // Only print out wake locks that were held
1547 pw.println(sb.toString());
1548 uidActivity = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550 }
1551 }
1552
1553 Map<Integer, ? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
1554 if (sensors.size() > 0) {
1555 for (Map.Entry<Integer, ? extends BatteryStats.Uid.Sensor> ent
1556 : sensors.entrySet()) {
1557 Uid.Sensor se = ent.getValue();
1558 int sensorNumber = ent.getKey();
1559 sb.setLength(0);
1560 sb.append(prefix);
1561 sb.append(" Sensor ");
1562 int handle = se.getHandle();
1563 if (handle == Uid.Sensor.GPS) {
1564 sb.append("GPS");
1565 } else {
1566 sb.append(handle);
1567 }
1568 sb.append(": ");
1569
1570 Timer timer = se.getSensorTime();
1571 if (timer != null) {
1572 // Convert from microseconds to milliseconds with rounding
Evan Millarc64edde2009-04-18 12:26:32 -07001573 long totalTime = (timer.getTotalTimeLocked(
1574 batteryRealtime, which) + 500) / 1000;
1575 int count = timer.getCountLocked(which);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001576 //timer.logState();
1577 if (totalTime != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001578 formatTimeMs(sb, totalTime);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 sb.append("realtime (");
1580 sb.append(count);
1581 sb.append(" times)");
1582 } else {
1583 sb.append("(not used)");
1584 }
1585 } else {
1586 sb.append("(not used)");
1587 }
1588
1589 pw.println(sb.toString());
1590 uidActivity = true;
1591 }
1592 }
1593
1594 Map<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
1595 if (processStats.size() > 0) {
1596 for (Map.Entry<String, ? extends BatteryStats.Uid.Proc> ent
1597 : processStats.entrySet()) {
1598 Uid.Proc ps = ent.getValue();
1599 long userTime;
1600 long systemTime;
1601 int starts;
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001602 int numExcessive;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603
1604 userTime = ps.getUserTime(which);
1605 systemTime = ps.getSystemTime(which);
1606 starts = ps.getStarts(which);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001607 numExcessive = which == STATS_SINCE_CHARGED
Dianne Hackborn287952c2010-09-22 22:34:31 -07001608 ? ps.countExcessivePowers() : 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001610 if (userTime != 0 || systemTime != 0 || starts != 0
1611 || numExcessive != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001612 sb.setLength(0);
1613 sb.append(prefix); sb.append(" Proc ");
1614 sb.append(ent.getKey()); sb.append(":\n");
1615 sb.append(prefix); sb.append(" CPU: ");
1616 formatTime(sb, userTime); sb.append("usr + ");
Dianne Hackbornb8071d792010-09-09 16:45:15 -07001617 formatTime(sb, systemTime); sb.append("krn");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07001618 if (starts != 0) {
Dianne Hackbornb8071d792010-09-09 16:45:15 -07001619 sb.append("\n"); sb.append(prefix); sb.append(" ");
1620 sb.append(starts); sb.append(" proc starts");
Dianne Hackborn0d903a82010-09-07 23:51:03 -07001621 }
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001622 pw.println(sb.toString());
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001623 for (int e=0; e<numExcessive; e++) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07001624 Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001625 if (ew != null) {
Dianne Hackborn287952c2010-09-22 22:34:31 -07001626 pw.print(prefix); pw.print(" * Killed for ");
1627 if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
1628 pw.print("wake lock");
1629 } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
1630 pw.print("cpu");
1631 } else {
1632 pw.print("unknown");
1633 }
1634 pw.print(" use: ");
Dianne Hackborn1ebccf52010-08-15 13:04:34 -07001635 TimeUtils.formatDuration(ew.usedTime, pw);
1636 pw.print(" over ");
1637 TimeUtils.formatDuration(ew.overTime, pw);
1638 pw.print(" (");
Dianne Hackborn9adb9c32010-08-13 14:09:56 -07001639 pw.print((ew.usedTime*100)/ew.overTime);
1640 pw.println("%)");
1641 }
1642 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 uidActivity = true;
1644 }
1645 }
1646 }
1647
1648 Map<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
1649 if (packageStats.size() > 0) {
1650 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg> ent
1651 : packageStats.entrySet()) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001652 pw.print(prefix); pw.print(" Apk "); pw.print(ent.getKey()); pw.println(":");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001653 boolean apkActivity = false;
1654 Uid.Pkg ps = ent.getValue();
1655 int wakeups = ps.getWakeups(which);
1656 if (wakeups != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001657 pw.print(prefix); pw.print(" ");
1658 pw.print(wakeups); pw.println(" wakeup alarms");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 apkActivity = true;
1660 }
1661 Map<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
1662 if (serviceStats.size() > 0) {
1663 for (Map.Entry<String, ? extends BatteryStats.Uid.Pkg.Serv> sent
1664 : serviceStats.entrySet()) {
1665 BatteryStats.Uid.Pkg.Serv ss = sent.getValue();
1666 long startTime = ss.getStartTime(batteryUptime, which);
1667 int starts = ss.getStarts(which);
1668 int launches = ss.getLaunches(which);
1669 if (startTime != 0 || starts != 0 || launches != 0) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001670 sb.setLength(0);
1671 sb.append(prefix); sb.append(" Service ");
1672 sb.append(sent.getKey()); sb.append(":\n");
1673 sb.append(prefix); sb.append(" Created for: ");
1674 formatTimeMs(sb, startTime / 1000);
1675 sb.append(" uptime\n");
1676 sb.append(prefix); sb.append(" Starts: ");
1677 sb.append(starts);
1678 sb.append(", launches: "); sb.append(launches);
1679 pw.println(sb.toString());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001680 apkActivity = true;
1681 }
1682 }
1683 }
1684 if (!apkActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001685 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001686 }
1687 uidActivity = true;
1688 }
1689 }
1690 if (!uidActivity) {
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001691 pw.print(prefix); pw.println(" (nothing executed)");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 }
1693 }
1694 }
1695
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001696 void printBitDescriptions(PrintWriter pw, int oldval, int newval, BitDescription[] descriptions) {
1697 int diff = oldval ^ newval;
1698 if (diff == 0) return;
1699 for (int i=0; i<descriptions.length; i++) {
1700 BitDescription bd = descriptions[i];
1701 if ((diff&bd.mask) != 0) {
1702 if (bd.shift < 0) {
1703 pw.print((newval&bd.mask) != 0 ? " +" : " -");
1704 pw.print(bd.name);
1705 } else {
1706 pw.print(" ");
1707 pw.print(bd.name);
1708 pw.print("=");
1709 int val = (newval&bd.mask)>>bd.shift;
1710 if (bd.values != null && val >= 0 && val < bd.values.length) {
1711 pw.print(bd.values[val]);
1712 } else {
1713 pw.print(val);
1714 }
1715 }
1716 }
1717 }
1718 }
1719
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 /**
1721 * Dumps a human-readable summary of the battery statistics to the given PrintWriter.
1722 *
1723 * @param pw a Printer to receive the dump output.
1724 */
1725 @SuppressWarnings("unused")
Dianne Hackborn1d442e02009-04-20 18:14:05 -07001726 public void dumpLocked(PrintWriter pw) {
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001727 final HistoryItem rec = new HistoryItem();
1728 if (startIteratingHistoryLocked()) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001729 pw.println("Battery History:");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001730 long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001731 int oldState = 0;
1732 int oldStatus = -1;
1733 int oldHealth = -1;
1734 int oldPlug = -1;
1735 int oldTemp = -1;
1736 int oldVolt = -1;
Dianne Hackbornce2ef762010-09-20 11:39:14 -07001737 while (getNextHistoryLocked(rec)) {
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001738 pw.print(" ");
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001739 TimeUtils.formatDuration(rec.time-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001740 pw.print(" ");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001741 if (rec.cmd == HistoryItem.CMD_START) {
1742 pw.println(" START");
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -07001743 } else if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
1744 pw.println(" *OVERFLOW*");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001745 } else {
1746 if (rec.batteryLevel < 10) pw.print("00");
1747 else if (rec.batteryLevel < 100) pw.print("0");
1748 pw.print(rec.batteryLevel);
1749 pw.print(" ");
1750 if (rec.states < 0x10) pw.print("0000000");
1751 else if (rec.states < 0x100) pw.print("000000");
1752 else if (rec.states < 0x1000) pw.print("00000");
1753 else if (rec.states < 0x10000) pw.print("0000");
1754 else if (rec.states < 0x100000) pw.print("000");
1755 else if (rec.states < 0x1000000) pw.print("00");
1756 else if (rec.states < 0x10000000) pw.print("0");
1757 pw.print(Integer.toHexString(rec.states));
1758 if (oldStatus != rec.batteryStatus) {
1759 oldStatus = rec.batteryStatus;
1760 pw.print(" status=");
1761 switch (oldStatus) {
1762 case BatteryManager.BATTERY_STATUS_UNKNOWN:
1763 pw.print("unknown");
1764 break;
1765 case BatteryManager.BATTERY_STATUS_CHARGING:
1766 pw.print("charging");
1767 break;
1768 case BatteryManager.BATTERY_STATUS_DISCHARGING:
1769 pw.print("discharging");
1770 break;
1771 case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
1772 pw.print("not-charging");
1773 break;
1774 case BatteryManager.BATTERY_STATUS_FULL:
1775 pw.print("full");
1776 break;
1777 default:
1778 pw.print(oldStatus);
1779 break;
1780 }
1781 }
1782 if (oldHealth != rec.batteryHealth) {
1783 oldHealth = rec.batteryHealth;
1784 pw.print(" health=");
1785 switch (oldHealth) {
1786 case BatteryManager.BATTERY_HEALTH_UNKNOWN:
1787 pw.print("unknown");
1788 break;
1789 case BatteryManager.BATTERY_HEALTH_GOOD:
1790 pw.print("good");
1791 break;
1792 case BatteryManager.BATTERY_HEALTH_OVERHEAT:
1793 pw.print("overheat");
1794 break;
1795 case BatteryManager.BATTERY_HEALTH_DEAD:
1796 pw.print("dead");
1797 break;
1798 case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
1799 pw.print("over-voltage");
1800 break;
1801 case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
1802 pw.print("failure");
1803 break;
1804 default:
1805 pw.print(oldHealth);
1806 break;
1807 }
1808 }
1809 if (oldPlug != rec.batteryPlugType) {
1810 oldPlug = rec.batteryPlugType;
1811 pw.print(" plug=");
1812 switch (oldPlug) {
1813 case 0:
1814 pw.print("none");
1815 break;
1816 case BatteryManager.BATTERY_PLUGGED_AC:
1817 pw.print("ac");
1818 break;
1819 case BatteryManager.BATTERY_PLUGGED_USB:
1820 pw.print("usb");
1821 break;
1822 default:
1823 pw.print(oldPlug);
1824 break;
1825 }
1826 }
1827 if (oldTemp != rec.batteryTemperature) {
1828 oldTemp = rec.batteryTemperature;
1829 pw.print(" temp=");
1830 pw.print(oldTemp);
1831 }
1832 if (oldVolt != rec.batteryVoltage) {
1833 oldVolt = rec.batteryVoltage;
1834 pw.print(" volt=");
1835 pw.print(oldVolt);
1836 }
1837 printBitDescriptions(pw, oldState, rec.states,
1838 HISTORY_STATE_DESCRIPTIONS);
1839 pw.println();
1840 }
1841 oldState = rec.states;
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001842 }
Dianne Hackbornb5e31652010-09-07 12:13:55 -07001843 pw.println("");
1844 }
1845
1846 SparseArray<? extends Uid> uidStats = getUidStats();
1847 final int NU = uidStats.size();
1848 boolean didPid = false;
1849 long nowRealtime = SystemClock.elapsedRealtime();
1850 StringBuilder sb = new StringBuilder(64);
1851 for (int i=0; i<NU; i++) {
1852 Uid uid = uidStats.valueAt(i);
1853 SparseArray<? extends Uid.Pid> pids = uid.getPidStats();
1854 if (pids != null) {
1855 for (int j=0; j<pids.size(); j++) {
1856 Uid.Pid pid = pids.valueAt(j);
1857 if (!didPid) {
1858 pw.println("Per-PID Stats:");
1859 didPid = true;
1860 }
1861 long time = pid.mWakeSum + (pid.mWakeStart != 0
1862 ? (nowRealtime - pid.mWakeStart) : 0);
1863 pw.print(" PID "); pw.print(pids.keyAt(j));
1864 pw.print(" wake time: ");
1865 TimeUtils.formatDuration(time, pw);
1866 pw.println("");
1867 }
1868 }
1869 }
1870 if (didPid) {
1871 pw.println("");
Dianne Hackborn32907cf2010-06-10 17:50:20 -07001872 }
1873
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001874 pw.println("Statistics since last charge:");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 pw.println(" System starts: " + getStartCount()
1876 + ", currently on battery: " + getIsOnBattery());
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001877 dumpLocked(pw, "", STATS_SINCE_CHARGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001878 pw.println("");
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001879 pw.println("Statistics since last unplugged:");
1880 dumpLocked(pw, "", STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001881 }
1882
1883 @SuppressWarnings("unused")
Dianne Hackborne4a59512010-12-07 11:08:07 -08001884 public void dumpCheckinLocked(PrintWriter pw, String[] args, List<ApplicationInfo> apps) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 boolean isUnpluggedOnly = false;
1886
1887 for (String arg : args) {
1888 if ("-u".equals(arg)) {
1889 if (LOCAL_LOGV) Log.v("BatteryStats", "Dumping unplugged data");
1890 isUnpluggedOnly = true;
1891 }
1892 }
1893
Dianne Hackborne4a59512010-12-07 11:08:07 -08001894 if (apps != null) {
1895 SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
1896 for (int i=0; i<apps.size(); i++) {
1897 ApplicationInfo ai = apps.get(i);
1898 ArrayList<String> pkgs = uids.get(ai.uid);
1899 if (pkgs == null) {
1900 pkgs = new ArrayList<String>();
1901 uids.put(ai.uid, pkgs);
1902 }
1903 pkgs.add(ai.packageName);
1904 }
1905 SparseArray<? extends Uid> uidStats = getUidStats();
1906 final int NU = uidStats.size();
1907 String[] lineArgs = new String[2];
1908 for (int i=0; i<NU; i++) {
1909 int uid = uidStats.keyAt(i);
1910 ArrayList<String> pkgs = uids.get(uid);
1911 if (pkgs != null) {
1912 for (int j=0; j<pkgs.size(); j++) {
1913 lineArgs[0] = Integer.toString(uid);
1914 lineArgs[1] = pkgs.get(j);
1915 dumpLine(pw, 0 /* uid */, "i" /* category */, UID_DATA,
1916 (Object[])lineArgs);
1917 }
1918 }
1919 }
1920 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 if (isUnpluggedOnly) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001922 dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001923 }
1924 else {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -07001925 dumpCheckinLocked(pw, STATS_SINCE_CHARGED, -1);
1926 dumpCheckinLocked(pw, STATS_SINCE_UNPLUGGED, -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 }
1928 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929}